Jump to content

Guigetmsg(1) error.


Recommended Posts

This always worked and it still works in older scripts I have but if I try to type a new one it doesn't work right.

Here's the code:

Global $gui2, $button2
$gui = GUICreate("Gui 1",200,200,-1,-1)
$button1 = GUICtrlCreateButton("Gui 1 Button",0,0,100,25)
GUISetState()
while 1
   $msg = GUIGetMsg(1)
   Switch $msg[1]
   Case $gui
      Switch $msg[0]
      ;Case -3
         ;Exit
      Case $button1
         gui2()
      EndSwitch
   Case $gui2
      Switch $msg[0]
      ;Case -3
         ;Exit
      Case $button2
         MsgBox(0,"Gui2","From Gui2")
      EndSwitch
   EndSwitch
WEnd

Func gui2()
   $gui2 = GUICreate("Gui 2",200,200,-1,-1)
   $button2 = GUICtrlCreateButton("Gui 2 Button",0,0,100,25)
   GUISetState()
   EndFunc

Thanks.

Link to comment
Share on other sites

If no message is returned, then the $msg[1] is 0...which matches the switch case for gui2, which is empty/null when not created.

You can add fake variable values like this to get around that.

Global $gui2=99, $button2=99
$gui = GUICreate("Gui 1",200,200,-1,-1)
$button1 = GUICtrlCreateButton("Gui 1 Button",0,0,100,25)
GUISetState()
while 1
   $msg = GUIGetMsg(1)
   Switch $msg[1]

   Case $gui
      Switch $msg[0]
      ;Case -3
         ;Exit
      Case $button1
         gui2()
      EndSwitch
   Case $gui2
      Switch $msg[0]
      ;Case -3
         ;Exit
      Case $button2
         MsgBox(0,"Gui2","From Gui2")
      EndSwitch
   EndSwitch
WEnd

Func gui2()
   $gui2 = GUICreate("Gui 2",200,200,-1,-1)
   $button2 = GUICtrlCreateButton("Gui 2 Button",0,0,100,25)
   GUISetState()
EndFunc

That will fix the messagebox from popping up repeately.  Other than that, there are still many issues with your code.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Well, if you logically check that the array value for the GUI is a hande (IsHwnd), then you can skip the switch block, and not have to worry about the 'dumb' data.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...