Jump to content

GUICtrlSetOnEvent Not correctly linking to functions..


orange
 Share

Recommended Posts

I create this GUI at the beginning of my script, for use later. When I need the GUI, I set it visible. So, why won't the OnEvent settings work?

Here is what I know:

OPT is not changed in the rest of the script.

The $GUI_CLOSE function works perfectly in the actual script, so I know that the Opt("...") is not getting changed

I have another GUI that works perfectly fine.

If I set the GUI to show, the everything works fine.

EDIT:

Adding the line:

GUISetState(@sw_show)

winsetstate("Limit Sort","",@SW_HIDE)

to the end of the GUI declaration works, but the GUI still flashes. Is there a better way to do what I am trying to do?

#include<GUIconstants.au3>
#include<GUICOMBO.au3>

Opt("GUIOnEventMode", 1)
GUICreate("Limit Sort", 224, 171, 193, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose")
GUICtrlCreateLabel("Sort By:", 6, 16, 41, 17)
$SortByCombo = GUICtrlCreateCombo("", 54, 12, 161, 25)
guictrlsetdata($SortByCombo,"CN Number|AR Number|CFM Number")
GUICtrlSetOnEvent($SortByCombo,"SortByComboChange")
_GUICtrlComboSelectString($SortByCombo, 0, "CN Number")
GUICtrlCreateLabel("From:", 6, 52, 30, 17)
$StartLimitCombo = GUICtrlCreateCombo("", 54, 48, 161, 25)
GUICtrlCreateLabel("To:", 6, 86, 20, 17)
$EndLimitCombo = GUICtrlCreateCombo("", 54, 82, 161, 25)
$SortButton = GUICtrlCreateButton("SortButton", 24, 118, 177, 41)
GUICtrlSetOnEvent($SortButton, "SortButtonclick")
GUISetState(@sw_show)
winsetstate("Limit Sort","",@SW_HIDE)


ShowGUI()

while 1 
 sleep(100)
WEnd

func ShowGUI()
     WinSetState("Limit Sort","",@SW_SHOW)
endfunc

func SortButtonclick()
     msgbox(0,0,"The Sort button was clicked")
endfunc

func SortByComboChange()
     msgbox(0,0,"The Sort combo was changed")
endfunc

func GUIClose()
     msgbox(0,0,"Exit was clicked")
     exit
endfunc
Edited by orange
Link to comment
Share on other sites

For some reason, this is the line causing troubles:

;_GUICtrlComboSelectString($SortByCombo, 0, "CN Number")

Comment it out as in the above example, and everything will work well.

thanks for the quick reply, but I cannot duplicate your results. When I comment out that line, it still does not work for me.

I have the latest beta, the latest SciTE; everything is update.

Link to comment
Share on other sites

If you comment out the above line and click on the combo so as to change its value, the correct msgbox will appear. Do not try to type something in, it won't work this way.

Tested using latest stable and latest beta.

Link to comment
Share on other sites

If you comment out the above line and click on the combo so as to change its value, the correct msgbox will appear. Do not try to type something in, it won't work this way.

Tested using latest stable and latest beta.

Well I am not sure what to say- I did change the selection of the combo, and still there was no MSGBOX that appeared. I think that fundamentally the root of the problem has something to do with the fact that it "won't work" when something is typed in. Franky, it is a GUI Event problem, which typing is clearly a GUI event.

Edited by orange
Link to comment
Share on other sites

dident understan this all the way

func ShowGUI()
     WinSetState("Limit Sort","",@SW_SHOW)
endfunc

i think it shud b

func ShowGUI()
     GUISetState(@sw_show)
endfunc

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Hi orange,

There's a few things you should get sorted ..

To me it looks like your a bit confused with hiding or showing your GUI.

Your actually double handling the hide and show state with 2 functions wich serves no purpose apart from to baffle yourself :)

Since you are only hiding/showing your created AutoIt GUI window, put your GUI into a variable just use GuiSetState() to set the state of the GUI when needed. Also puting your GUI into a variable will latter help when your working with multiple GUI's in your script.

Drop the WinSetState completely ftm.

Another thing I notice is your using _GUICtrlComboSelectString($SortByCombo, 0, "CN Number")

To me this seems unneeded at that point in your script.

Since you could just as easily use GUICtrlSetData($SortByCombo,"CN Number|AR Number|CFM Number", "CN Number") to do the same thing. This way your script is not dependant upon another udf making it smaller in code in the long run.

Here's your script with the mentioned changes:

#include<GUIconstants.au3>

Opt("GUIOnEventMode", 1)

$Gui = GUICreate("Limit Sort", 224, 171, 193, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose", $Gui)
GUICtrlCreateLabel("Sort By:", 6, 16, 41, 17)
$SortByCombo = GUICtrlCreateCombo("", 54, 12, 161, 25)
GUICtrlSetData(-1,"CN Number|AR Number|CFM Number", "CN Number")
GUICtrlSetOnEvent(-1,"SortByComboChange")
GUICtrlCreateLabel("From:", 6, 52, 30, 17)
$StartLimitCombo = GUICtrlCreateCombo("", 54, 48, 161, 25)
GUICtrlCreateLabel("To:", 6, 86, 20, 17)
$EndLimitCombo = GUICtrlCreateCombo("", 54, 82, 161, 25)
$SortButton = GUICtrlCreateButton("SortButton", 24, 118, 177, 41)
GUICtrlSetOnEvent(-1, "SortButtonclick")
GUISetState(@SW_HIDE, $Gui)

ShowGUI()

While 1
    Sleep(100)
WEnd

Func ShowGUI()
    GUISetState(@SW_SHOW, $Gui)
EndFunc

Func SortButtonclick()
    MsgBox(0,0,"The Sort button was clicked")
EndFunc

Func SortByComboChange()
    MsgBox(0,0,"The Sort combo was changed")
EndFunc

Func GUIClose()
    MsgBox(0,0,"Exit was clicked")
    Exit
EndFunc

Cheers

Edit: Saw the post below.. that should of been GUISetState(@SW_HIDE, $Gui) when I posted, doh .. changed it to reflect what I mean...

Edited by smashly
Link to comment
Share on other sites

Hi orange,

There's a few things you should get sorted ..

To me it looks like your a bit confused in with hiding or showing your GUI.

Your actually double handling the hide and show state with 2 functions wich serves no purpose apart from to baffle yourself :)

Since you are only hiding/showing your created AutoIt GUI window, put your GUI into a variable just use GuiSetState() to set the state of the GUI when needed. Also puting your GUI into a variable will latter help when your working with multiple GUI's in your script.

Drop the WinSetState completely ftm.

Another thing I notice is your using _GUICtrlComboSelectString($SortByCombo, 0, "CN Number")

To me these seems unneeded at that point in your script.

Since you could just as easily use GUICtrlSetData($SortByCombo,"CN Number|AR Number|CFM Number", "CN Number") to do the same thing. This way your script is not dependant upon another udf making it smaller in code in the long run.

Here's your script with the mentioned changes:

#include<GUIconstants.au3>

Opt("GUIOnEventMode", 1)

$Gui = GUICreate("Limit Sort", 224, 171, 193, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose", $Gui)
GUICtrlCreateLabel("Sort By:", 6, 16, 41, 17)
$SortByCombo = GUICtrlCreateCombo("", 54, 12, 161, 25)
GUICtrlSetData(-1,"CN Number|AR Number|CFM Number", "CN Number")
GUICtrlSetOnEvent(-1,"SortByComboChange")
GUICtrlCreateLabel("From:", 6, 52, 30, 17)
$StartLimitCombo = GUICtrlCreateCombo("", 54, 48, 161, 25)
GUICtrlCreateLabel("To:", 6, 86, 20, 17)
$EndLimitCombo = GUICtrlCreateCombo("", 54, 82, 161, 25)
$SortButton = GUICtrlCreateButton("SortButton", 24, 118, 177, 41)
GUICtrlSetOnEvent(-1, "SortButtonclick")
GUISetState(@SW_SHOW, $Gui)

ShowGUI()

While 1
    Sleep(100)
WEnd

Func ShowGUI()
    GUISetState(@SW_SHOW, $Gui)
EndFunc

Func SortButtonclick()
    MsgBox(0,0,"The Sort button was clicked")
EndFunc

Func SortByComboChange()
    MsgBox(0,0,"The Sort combo was changed")
EndFunc

Func GUIClose()
    MsgBox(0,0,"Exit was clicked")
    Exit
EndFunc

Cheers

thanks for the reply -

I do know that I do not need the WinSetState to hide and show the GUI. This was an example script as a part of a much larger script.

The larger script does need to hide and show the GUI, with the GUI hidden upon initialization, so that is why I have a function that hides and shows. Also, I can't make the GUI handle global because of some other issues, therefore WinSetState was my only option to hide and show the GUI within functions.

As for the _GUICombo thing, yeah, that was just stupid of me. Thanks!

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...