wisem2540 Posted July 6, 2015 Share Posted July 6, 2015 I have a GUI app that I am working on. I looked at GUIRegisterMsg and its just not making sense. As I understand it, I am supposed to use GUIRegisterMsg to capture the GUI_Event_Close message that calls a function to set a flag. Does anyone have a simple example that they use? Link to comment Share on other sites More sharing options...
LarsJ Posted July 6, 2015 Share Posted July 6, 2015 GUIRegisterMsg is used to capture Windows messages that are not captured by the AutoIt message loop. There is rarely a need to capture messages that have already been captured by the AutoIt message loop. Please explain what it is you want to do. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
TheDcoder Posted July 6, 2015 Share Posted July 6, 2015 @wisem2540 Use GUISetOnEvent not GUIRegisterMsg, TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
JohnOne Posted July 6, 2015 Share Posted July 6, 2015 Here are two ways.HotKeySet("+{Esc}", "_Exit") GUICreate("GUI") GUISetState() While 3 Switch GUIGetMsg() Case -3 Exit EndSwitch _CodeLoop() WEnd Func _CodeLoop() While 3 Sleep(50) If GUIGetMsg() = -3 Then Exit WEnd EndFunc Func _Exit() Exit EndFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
TheDcoder Posted July 6, 2015 Share Posted July 6, 2015 @JohnOne Why use magic numbers? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
mikell Posted July 6, 2015 Share Posted July 6, 2015 (edited) There are 2 other ways Both can be used, GuiOnEventMode is simpler to use but GUIRegisterMsg has a higher priority as shown in the tests below (can be useful in some rare cases)expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "_Terminate2") Opt("GuiOnEventMode", 1) GUICreate("My GUI") GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate") $btn = GUICtrlCreateButton("stop", 10, 50, 50, 20) GUICtrlSetOnEvent(-1, "_btn") $label = GUICtrlCreateLabel("0", 100, 50, 20, 20) GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") Local $aAccelKeys[1][2] = [["{SPACE}", $btn]] GUISetAccelerators($aAccelKeys) For $i = 1 to 10000 Sleep(300) GuiCtrlSetData($label, GuiCtrlRead($label)+1) Next ;While 1 ; Sleep(10) ;Wend Func _btn() Msgbox(0,"", "on event") EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $lParam Switch BitAND($wParam, 0xFFFF) Case $btn Msgbox(0,"", "wm_command") EndSwitch Return 'GUI_RUNDEFMSG' EndFunc Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) ; 0xF060 = $SC_CLOSE If BitAND($wParam, 0xFFF0) = 0xF060 Then Exit Msgbox(0,"", "wm_syscommand") EndFunc Func _Terminate() Exit Msgbox(0,"", "on event") EndFunc Func _Terminate2() Exit Msgbox(0,"", "hotkey") EndFuncShould read this https://www.autoitscript.com/wiki/Interrupting_a_running_function Edited July 6, 2015 by mikell Link to comment Share on other sites More sharing options...
JohnOne Posted July 6, 2015 Share Posted July 6, 2015 @JohnOne Why use magic numbers? I like them bud, and it's a simple example where I can't be bothered with #includes. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
mikell Posted July 6, 2015 Share Posted July 6, 2015 GUICreate("GUI") GUISetState() Do If GUIGetMsg() = -3 Then Exit Until not "JohnOne" TheDcoder 1 Link to comment Share on other sites More sharing options...
wisem2540 Posted July 6, 2015 Author Share Posted July 6, 2015 I suspect my issue has something to do with being inside of a function. Because I do not believe I saw this issue until I made it a function. My script is using OneventMode. When I am inside the function, and inside the FOR loop, my GUI does not respond to a CLOSE until the loop finishes Heres my functionexpandcollapse popupFunc Query() GUICtrlSetData($hList, "") $Pserver = GUICtrlRead ($hcombo) $objWMIService = ObjGet("winmgmts:\\" & $pserver & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Printer") For $objItem In $colItems _ArrayAdd ($PrinterInfo,$objitem.Name,0) GUICtrlSetData ($hList,$objitem.Name & ",") If StringLeft ($objItem.PortName, 3) = "IP_" Then $PrinterInfo[$x][1]=StringTrimLeft ($objItem.PortName, 3) Else $PrinterInfo[$x][1]=$objItem.PortName EndIf $State = $objItem.PrinterState if $State = 0 Then $State = "Ready" if $State = 1024 Then $State = "Ready"; 1024 is "Printing" if $State = 16384 Then $State = "Ready"; 16284 is "Processing" if $State = 1 Then $State = "Paused" if $State = 129 Then $State = "Paused - Offline" if $State = 1027 Then $State = "Paused - Error" If $State = 131073 Then $State = "Paused - Toner/Ink Low" if $State = 128 Then $State = "Offline" if $State = 1154 Then $State = "Error - Offline" if $State = 8 Then $State = "Paper Jam" if $State = 1034 Then $State = "Error - Paper Jam" if $State = 131072 Then $State = "Toner/Ink Low" If $State = 262144 Then $State = "No Toner/Ink" if $State = 2 Then $State = "Error" if $State = 132 Then $State = "Deleting - Error" if $State = 1158 Then $State = "Error - Deleting - Offline" if $State = 1042 Then $State = "Error - Out of Paper" if $State = 16 Then $State = "Out of Paper" If $State = 4194304 Then $State = "Door Open" $PrinterInfo[$x][2]=$state $PrinterInfo[$x][3]=$objItem.Drivername $PrinterInfo[$x][4]=$objItem.Location $PrinterInfo[$x][5]=$objItem.comment ;_ArrayDisplay($Printerinfo) $x = $x + 1 Next _ArrayDisplay($Printerinfo) EndFunc 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