Jump to content

Button Creation Loop Triggers GUIGetMsg


Recommended Posts

I'm working on a small practice project that allows a user to 1. Choose between moving multiple files to a single target location or 2. Moving multiple files to Multiple locations. The problem I am having is creating all the buttons I wish to use. I have created them with a loop and it seems to cause a problem with the GUIGetMsg() Function. If I create each button seperatly I have no problems except the load of lines used to create them seperatly. I was wondering if there is a work around for this or not.

Here is my code (Please bare with me if it looks a mess...)

#include
#include
#include

HotKeySet("{ESC}", "Destroy")

$Version = "1.0"
$WindowW = 100
$WindowH = 100
$CenterW = (@DesktopWidth / 2) - ($WindowW / 2)
$CenterH = (@DesktopHeight / 2) - ($WindowH / 2)

Startup_Window()

Func Main_Window($Win_Style)
If $Win_Style = 1 Then
$WindowW = 500
$WindowH = 500
$CenterW = (@DesktopWidth / 2) - ($WindowW / 2)
$CenterH = (@DesktopHeight / 2) - ($WindowH / 2)
$SD_Window = GUICreate("Installation Manager " & $Version, $WindowW, $WindowH, $CenterW, $CenterH)

$File_Menu = GUICtrlCreateMenu("&File")
$Prefrences_Sub_Menu = GUICtrlCreateMenuItem("Prefrences", $File_Menu)
$Exit_Sub_Menu = GUICtrlCreateMenuItem("Exit", $File_Menu)

Local $Button_Array[15]
$ButtonW = 60
$ButtonH = 20
$ButtonColumn = $WindowW - ($ButtonW + 5)
$ButtonRow = 5

$i = 1
While $i <= 15
GUICtrlCreateButton("Browse", $ButtonColumn, $ButtonRow, $ButtonW, $ButtonH)
$ButtonRow = $ButtonRow + 25
$i = $i + 1
WEnd

GUISetIcon(@ScriptDir & "\PPzIcon.ico")
GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg()
Select
Case $msg = $Button_Array[1]
MsgBox(0, "", "Button 1")
Case $msg = $GUI_EVENT_CLOSE
;MsgBox(0, "Goodbye", "Thanks for using Pickpocketz Installation Manager!")
Exit
Case $msg = $Exit_Sub_menu
Exit
EndSelect
WEnd

ElseIf $Win_Style = 2 Then
$WindowW = 500
$WindowH = 500
$CenterW = (@DesktopWidth / 2) - ($WindowW / 2)
$CenterH = (@DesktopHeight / 2) - ($WindowH / 2)
$MD_Window = GUICreate("Installation Manager " & $Version, $WindowW, $WindowH, $CenterW, $CenterH)
GUISetIcon(@ScriptDir & "\PPzIcon.ico")
GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
;MsgBox(0, "Goodbye", "Thanks for using Pickpocketz Installation Manager!")
Exit
EndSelect
WEnd
Else
MsgBox(0, "Error", "Window Style Not Recognized!")
Exit
EndIf
EndFunc

Func Destroy()
Exit
EndFunc

Func Startup_Window()
$S_Win = GUICreate("", $WindowW, $WindowH, $CenterW, $CenterH)
GUISetBkColor(0x000000)
$SD_Button = GUICtrlCreateButton("Single Dir Install", 0, $WindowH - 40, 100, 20)
$MD_Button = GUICtrlCreateButton("Multi Dir Install", 0, $WindowH - 20, 100, 20)
GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg()
Select
Case $msg = $SD_Button
$Win_Style = 1
GUIDelete($S_Win)
Main_Window($Win_Style)
Case $msg = $MD_Button
$Win_Style = 2
GUIDelete($S_Win)
Main_Window($Win_Style)
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
EndFunc
Link to comment
Share on other sites

Hint #1: try this message ... MsgBox(0, $msg, "Button 1")

Hint #2: have a look at where $Button_Array[1] is set to a value

Thank you for the Hints! I'm not sure why GUIGetMsg is coming up with 0 and $Button_Array[0], $Button_Array[1] etc... aren't showing anything being stored as far as I can tell. My guess now is that it's not possible to use an array to store controls.
Link to comment
Share on other sites

Wow that was a complete derp moment. I apologize for not realizing that I wasn't actually assigning the controls to the array. It's funny because it almost hit me in a dream. I was just lying my head down starting to nod off and *BAM*! the solution hits me like a ton of bricks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...