jnmayer Posted March 9, 2008 Share Posted March 9, 2008 Hi! I have the following problem. I have a main window which has a "Start" button to begin with the calculations. I'm using GUICtrlSetOnEvent($startbutton,"Main") to receive an event, when the button is clicked. GUIOnEventMode is set to "1" so I can receive the events automatically. Now, inside the function "Main()", a small window with just a progress bar ist displayed. I'm trying to get an event for the clicking of the close-button of that window to stop the calculations: $progwindow=GUICreate("Fortschritt",200,80) GUISetOnEvent($GUI_EVENT_CLOSE,"CLOSEClicked",$progwindow) The event ist generated, but the event handling function "CLOSEClicked" is only called, when Main() reaches the end of the calculations and returns. But I want to receive the event at once to stop the calculation. How can this be done? Do I have to use event polling instead? BTW, I'm using HotKeySet("^c","CLOSEClicked") so I can stop the calculations with CTRL+C. This works just fine, I'm getting this event immideately. Thanks in advance, J. Mayer Link to comment Share on other sites More sharing options...
martin Posted March 9, 2008 Share Posted March 9, 2008 Hi!I have the following problem. I have a main window which has a "Start" button to begin with the calculations. I'm usingGUICtrlSetOnEvent($startbutton,"Main")to receive an event, when the button is clicked. GUIOnEventMode is set to "1" so I can receive the events automatically.Now, inside the function "Main()", a small window with just a progress bar ist displayed. I'm trying to get an event for the clicking of the close-button of that window to stop the calculations:$progwindow=GUICreate("Fortschritt",200,80)GUISetOnEvent($GUI_EVENT_CLOSE,"CLOSEClicked",$progwindow)The event ist generated, but the event handling function "CLOSEClicked" is only called, when Main() reaches the end of the calculations and returns. But I want to receive the event at once to stop the calculation.How can this be done? Do I have to use event polling instead?BTW, I'm using HotKeySet("^c","CLOSEClicked") so I can stop the calculations with CTRL+C. This works just fine, I'm getting this event immideately.Thanks in advance, J. MayerYou can do it by registering WM_COMMAND and detecting the button click notification $BN_CLICKED. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jnmayer Posted March 10, 2008 Author Share Posted March 10, 2008 You can do it by registering WM_COMMAND and detecting the button click notification $BN_CLICKED.Sorry, I could not get that to work. This probably has something to do with the fact, that ist startet programming with AutoIt olny just three days ago... Anyway, I changed the program from OnEventMode to event polling. And now it works!!! But there is drawback to this. As I need to check for incoming messages with GUIGetMsg() all the time, I'm facing a major slowdown of the calculations. I've come arround this by not checking in every single loop of the main calculations but only in every 100th loop. This seems to me like a bit of a hack... is there any better way to do this?Greetings, J. Mayer Link to comment Share on other sites More sharing options...
martin Posted March 10, 2008 Share Posted March 10, 2008 (edited) Sorry, I could not get that to work. This probably has something to do with the fact, that ist startet programming with AutoIt olny just three days ago... Anyway, I changed the program from OnEventMode to event polling. And now it works!!! But there is drawback to this. As I need to check for incoming messages with GUIGetMsg() all the time, I'm facing a major slowdown of the calculations. I've come arround this by not checking in every single loop of the main calculations but only in every 100th loop. This seems to me like a bit of a hack... is there any better way to do this? Greetings, J. Mayer Here's a quick example of what I meant. expandcollapse popup[ #include <GuiConstants.au3> Opt("GUIOnEventMode", 1) ;Global Const $WM_COMMAND = 0x0111 Global Const $BN_DOUBLECLICKED = 5 Global Const $BN_CLICKED = 0 Global $c = 0 $Form1 = GUICreate("Test Form", 681, 480, -1, -1) $Tab1 = GUICtrlCreateTab(0, 0, 681, 481) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $TabSheet1 = GUICtrlCreateTabItem("Test Tab") $apps = GUICtrlCreateCombo("", 520, 40, 140, 150) GUICtrlSetData(-1, "Entry 1|Entry 2|Entry 3", "Entry 1") GUISetState() $Add = GUICtrlCreateButton("Add", 520, 80, 60, 30) $Test = GUICtrlCreateButton("Test Button", 20, 40, 120, 20) GUICtrlSetOnEvent($Test, "TestButton") ;GUICtrlSetOnEvent($Add,"AddButton");because we need to action this immediately use WM_COMMAND GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") GUISetOnEvent($GUI_EVENT_CLOSE,"DoExit") While 1 Sleep(100) WEnd Func DoExit() Exit EndFunc Func TestButton() $c = 0 ConsoleWrite("start test" & @CRLF) For $n = 0 To 80 If $c <> 0 Then ConsoleWrite($c & 'changed' & @CRLF) $c = 0 EndIf Sleep(50) Next ConsoleWrite("end test" & @CRLF) EndFunc ;==>TestButton Func AddButton() $c = 9;any change so we see the effect in TestButton EndFunc Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) $nNotifyCode = _HiWord($wParam) $nID = _LoWord($wParam) $hCtrl = $lParam If $nID = $Add Then Switch $nNotifyCode Case $BN_CLICKED AddButton() EndSwitch Return 0 Else Return $GUI_RUNDEFMSG EndIf EndFunc ;==>MY_WM_COMMAND Func _HiWord($x) Return BitShift($x, 16) EndFunc ;==>_HiWord Func _LoWord($x) Return BitAND($x, 0xFFFF) EndFunc ;==>_LoWord Edited March 10, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now