pixelsearch Posted December 27, 2019 Share Posted December 27, 2019 Hi everybody Concerning GUIRegisterMsg, we read this in the Wiki tutorial : There are 2 ways we can still run something long and complicated but still leave the handler quickly: either set a flag or action a dummy control. If we set a flag inside the handler, we can then look for it within our idle loop and run our blocking code from here without affecting the handler at all. If we action a dummy control then we do not even have to look for the flag! Reading this, we might think that the dummy control is a better solution than the flag. But look at the given example : expandcollapse popup#include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; Whichever method we use, we need to declare the dummy control or the flag as a Global variable Global $hLeftClick, $fRightClick = False GUICreate("Click me!") ; Create a dummy control for the handler to action $hLeftClick = GUICtrlCreateDummy() GUISetState() ; Register our messages GUIRegisterMsg($WM_LBUTTONUP, "_WM_LBUTTONUP") GUIRegisterMsg($WM_RBUTTONUP, "_WM_RBUTTONUP") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hLeftClick ; Our dummy control was actioned so run the required code MsgBox($MB_TOPMOST, "Click", "LEFT CLICK!") EndSwitch ; Look for the flag If $fRightClick = True Then ; Run the code MsgBox($MB_TOPMOST, "Click", "RIGHT CLICK!") ; Do not forget to reset the flag! $fRightClick = False EndIf WEnd Func _WM_LBUTTONUP($hWnd, $iMsg, $wParam, $lParam) ; Action the dummy control GUICtrlSendToDummy($hLeftClick) EndFunc Func _WM_RBUTTONUP($hWnd, $iMsg, $wParam, $lParam) ; Set the flag $fRightClick = True EndFunc * 1st test : left click once in the Gui (dummy control) => MsgBox appears on top Do not close the Msgbox, but left click another couple of times in the Gui, outside the Msgbox. Now only close the Msgbox, what happens ? All the pending left clicks you made will now action the dummy control again & again, with several Msgbox appearing. * 2nd test : right click once in the Gui (flag) => MsgBox appears on top. Do same as 1st test (with right clicks this time) while the Msgbox is on top What happens after you close Msgbox ? Nothing happens (and that's very good), no pending right clicks, no new Msgbox, nothing. That's the reason why I always preferred the flag option Xandy 1 Link to comment Share on other sites More sharing options...
pixelsearch Posted January 3, 2020 Author Share Posted January 3, 2020 (edited) @Xandy : glad you liked the tests In fact, there are (at least) 2 ways to solve situations similar to the 1st test above (a dummy control being triggered again & again, due to pending left clicks on the gui while Msgbox isn't closed) 1) 1st way is to disable the Gui until MsgBox is closed, like this : $hGUI = GUICreate("Click me!") ... GUISetState(@SW_DISABLE, $hGUI) MsgBox($MB_TOPMOST, "Click", "LEFT CLICK!") GUISetState(@SW_ENABLE, $hGUI) This works fine and left clicks on the gui won't trigger the dummy control after the Gui is enabled. 2) A very interesting 2nd way that I discovered a few weeks ago and now I use it everywhere, for example in all 5 dialogs of my CSV file editor script. These 5 dialogs are : _ChooseColor() FileOpenDialog() FileSaveDialog() Inputbox() Msgbox() All these dialogs have in common their last parameter which is : hwnd ; a window handle to use as the parent for this dialog. As soon as you indicate the handle of the GUI in this last parameter, then all clicks on the GUI are "lost" while the dialog box is opened. And that's fantastic because you won't mess the environment mistakenly (for example by clicking another control or another listview row etc...) I'm not sure many AutoIt scripters use this important functionality, because when you look at AutoIt scripts, this is what you see very often, for example : MsgBox($MB_TOPMOST, "Click", "LEFT CLICK!") While in fact, the following syntax is much more interesting in any script... and now we know why MsgBox($MB_TOPMOST, "Click", "LEFT CLICK!", 0, $hGUI) Edited January 3, 2020 by pixelsearch Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 3, 2020 Moderators Share Posted January 3, 2020 pixelsearch, Take a look at the Modal MsgBox Styles tutorial in the Wiki - you are not the first to discover this! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
pixelsearch Posted January 3, 2020 Author Share Posted January 3, 2020 (edited) 1 hour ago, Melba23 said: you are not the first to discover this! And certainly not the last... Thanks Melba23 for this interesting link. I truly wish there was a link in the help file (MsgBox topic) leading us immediately to the Wiki page you indicated, where by the way we read this : "Although the values needed to set these styles are given in the Helpfile, it does not actually explain the difference between them." This sentence by itself means a lot ! So $MB_TASKMODAL would have done it for me... but well, as I use now this last parameter $hGUI in all others dialogue boxes (list in my precedent post), I guess I'll stick to it (though I'll try not to forget that $MB_TASKMODAL can do it too). Also there is something else I never understood : Why does everybody use $MB_SYSTEMMODAL, which truncates the Msgbox title (as written in the help file and it's true, you can verify it anytime) : [...]However, the title could get truncated if the SYSTEMMODAL flag (4096) is used. (help file) That's the only reason why I preferred $MB_TOPMOST since day #1, it displays much more longer titles than $MB_SYSTEMMODAL, and stays also on top (like $MB_SYSTEMMODAL does) That's another mystery to me... why should anyone have his titles truncated when it can be so easily avoidable ? Also, concerning $MB_APPLMODAL (0) that continuously plays hide & seek with you as soon as you click anywhere, thanks, but no thanks... Edited January 3, 2020 by pixelsearch 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