Lion66 Posted May 26, 2021 Share Posted May 26, 2021 Hello everyone. There is an example when we get messages about change the status of the window through the buttons pressing. How to catch an event after restoring the window through the WinSetState($hGUI, "", @SW_RESTORE) Interested in not pressing the button, but a message about the return of the window status after a pause by GUIRegisterMsg. Thank you. #Include <WindowsConstants.au3> #Include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 640, 480, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX)) $Button1 = GUICtrlCreateButton("Maximize", 80, 56, 113, 33) GUISetState() GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 WinSetState($hGUI, "", @SW_MAXIMIZE) Sleep(1000) WinSetState($hGUI, "", @SW_RESTORE) EndSwitch WEnd Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) Switch BitAND($wParam, 0x0000FFFF) Case 0xF020 ConsoleWrite("Window was minimized" & @LF) Case 0xF120 ConsoleWrite("Window was restored" & @LF) Case 0xF030 ConsoleWrite("Window was maximized" & @LF) EndSwitch Return "GUI_RUNDEFMSG" EndFunc Link to comment Share on other sites More sharing options...
Danp2 Posted May 26, 2021 Share Posted May 26, 2021 Have you checked out GUIRegisterMsg20? It may help you with implementing this. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Lion66 Posted May 27, 2021 Author Share Posted May 27, 2021 @Danp2 Thanks for link. I don't know what you wanted to tell me, but I used Windows Message Monitor and got the following list: Spoiler [ 0] hGui WM_SHOWWINDOW [ 1] hGui WM_WINDOWPOSCHANGING [ 2] hGui WM_WINDOWPOSCHANGING [ 3] hGui WM_ACTIVATEAPP [ 4] hGui WM_NCACTIVATE [ 5] hGui WM_GETICON [ 6] hGui WM_GETICON [ 7] hGui WM_GETICON [ 8] hGui WM_ACTIVATE [ 9] hGui WM_IME_SETCONTEXT [ 10] hGui WM_IME_NOTIFY [ 11] hGui WM_SETFOCUS [ 12] hGui WM_GETDLGCODE [ 13] hGui WM_NCPAINT [ 14] hGui WM_ERASEBKGND [ 15] hGui WM_CTLCOLORDLG [ 16] hGui WM_WINDOWPOSCHANGED [ 17] hGui WM_GETICON [ 18] hGui WM_0xC0F0 [ 19] hGui WM_GETICON [ 20] hGui WM_GETMINMAXINFO [ 21] hGui WM_GETICON [ 22] hGui WM_PAINT [ 23] hGui WM_KILLFOCUS [ 24] hGui WM_IME_SETCONTEXT [ 25] hGui WM_IME_NOTIFY [ 26] hGui WM_WINDOWPOSCHANGING [ 27] hGui WM_NCCALCSIZE [ 28] hGui WM_WINDOWPOSCHANGED [ 29] hGui WM_MOVE [ 30] hGui WM_SIZE [ 31] hGui WM_NCACTIVATE [ 32] hGui WM_ACTIVATE [ 33] hGui WM_ACTIVATEAPP [ 34] hGui WM_QUERYOPEN [ 35] hGui WM_WINDOWPOSCHANGING [ 36] hGui WM_NCCALCSIZE [ 37] hGui WM_WINDOWPOSCHANGING [ 38] hGui WM_ACTIVATEAPP [ 39] hGui WM_NCACTIVATE [ 40] hGui WM_ACTIVATE [ 41] hGui WM_IME_SETCONTEXT [ 42] hGui WM_IME_NOTIFY [ 43] hGui WM_SETFOCUS [ 44] hGui WM_GETDLGCODE [ 45] hGui WM_NCPAINT [ 46] hGui WM_ERASEBKGND [ 47] hGui WM_CTLCOLORDLG [ 48] hGui WM_WINDOWPOSCHANGED [ 49] hGui WM_MOVE [ 50] hGui WM_SIZE [ 51] hGui WM_ACTIVATE [ 52] hGui WM_PAINT [ 53] hGui WM_ERASEBKGND [ 54] hGui WM_CTLCOLORDLG [ 55] hGui WM_UAHDESTROYWINDOW [ 56] hGui WM_WINDOWPOSCHANGING [ 57] hGui WM_WINDOWPOSCHANGED [ 58] hGui WM_NCACTIVATE [ 59] hGui WM_ACTIVATE [ 60] hGui WM_ACTIVATEAPP [ 61] hGui WM_KILLFOCUS [ 62] hGui WM_IME_SETCONTEXT [ 63] hGui WM_IME_NOTIFY [ 64] hGui WM_DESTROY [ 65] hGui WM_NCDESTROY As I understand it, I need to use $WM_QUERYOPEN and then wait to $WM_PAINT. Perhaps this is not at all correct, but here is what i did. Now how can I wait for $WM_PAINT after receiving $WM_QUERYOPEN? #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include "..\..\Includes\GUIRegisterMsg20.au3" #include "..\..\WMMincl\WinMsgMon_ListView.au3" WinMsgMon_InitMsgs("..\..\WMMincl") Example() Func Example() Global $hGUI = GUICreate("Test", 640, 480, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX)) WinMsgMon_GetMsgs($hGUI, "$hGui") Global $hHandle = GUICtrlGetHandle($hGUI) GUIRegisterMsg($WM_QUERYOPEN, "_RestoreEvent") ;GUIRegisterMsg($WM_PAINT, "_RestoreEvent") GUISetState(@SW_SHOW) Sleep(2000) WinSetState($hGUI, "", @SW_MINIMIZE) Sleep(2000) WinSetState($hGUI, "", @SW_RESTORE) ;WinMsgMon_ViewMsgs(Example) GUIDelete($hGUI) EndFunc ;==>Example Func _RestoreEvent() ConsoleWrite("Restored" & @CRLF) EndFunc ;==>WM_NOTIFY Link to comment Share on other sites More sharing options...
Danp2 Posted May 27, 2021 Share Posted May 27, 2021 @Lion66 No idea to be honest. I know that you need to subclass the window, so that's why I pointed you to @LarsJ's thread. Hopefully someone else will jump in and give you a hand. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
InnI Posted May 27, 2021 Share Posted May 27, 2021 20 hours ago, Lion66 said: message about the return of the window status expandcollapse popup#Include <WindowsConstants.au3> #Include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 640, 480, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX)) $Button1 = GUICtrlCreateButton("Maximize", 80, 56, 113, 33) GUISetState() GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 WinSetState($hGUI, "", @SW_MAXIMIZE) Sleep(1000) WinSetState($hGUI, "", @SW_RESTORE) EndSwitch WEnd ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-size Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) Switch BitAND($wParam, 0xFFFF) Case 0 ; SIZE_RESTORED ConsoleWrite("Window was restored" & @LF) Case 1 ; SIZE_MINIMIZED ConsoleWrite("Window was minimized" & @LF) Case 2 ; SIZE_MAXIMIZED ConsoleWrite("Window was maximized" & @LF) Case 3 ; SIZE_MAXSHOW ConsoleWrite("SIZE_MAXSHOW" & @LF) Case 4 ; SIZE_MAXHIDE ConsoleWrite("SIZE_MAXHIDE" & @LF) EndSwitch Return "GUI_RUNDEFMSG" EndFunc Danp2 1 Link to comment Share on other sites More sharing options...
Lion66 Posted May 27, 2021 Author Share Posted May 27, 2021 (edited) @InnI Thanks for the example. Formally, it works and it can be used, but will be triggered at any change of size, and not specifically at the restore. I wonder if there are other solutions? Edited May 27, 2021 by Lion66 Link to comment Share on other sites More sharing options...
Danp2 Posted May 27, 2021 Share Posted May 27, 2021 @Lion66 Just add a flag to track when the window is in a minimized state -- expandcollapse popup#Include <WindowsConstants.au3> #Include <GUIConstantsEx.au3> Global $bMinimized = False $hGUI = GUICreate("Test", 640, 480, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_OVERLAPPEDWINDOW)) $Button1 = GUICtrlCreateButton("Maximize", 80, 56, 113, 33) GUISetState() GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 WinSetState($hGUI, "", @SW_MAXIMIZE) Sleep(1000) WinSetState($hGUI, "", @SW_RESTORE) EndSwitch WEnd ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-size Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) Switch BitAND($wParam, 0xFFFF) Case 0 ; SIZE_RESTORED If $bMinimized Then $bMinimized = False ConsoleWrite("Window was restored" & @LF) EndIf Case 1 ; SIZE_MINIMIZED ConsoleWrite("Window was minimized" & @LF) $bMinimized = True Case 2 ; SIZE_MAXIMIZED ConsoleWrite("Window was maximized" & @LF) Case 3 ; SIZE_MAXSHOW ConsoleWrite("SIZE_MAXSHOW" & @LF) Case 4 ; SIZE_MAXHIDE ConsoleWrite("SIZE_MAXHIDE" & @LF) EndSwitch Return "GUI_RUNDEFMSG" EndFunc Note that this doesn't handle the situation where a maximized window is minimized then restored. Lion66 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
InnI Posted May 27, 2021 Share Posted May 27, 2021 40 minutes ago, Lion66 said: but will be triggered at any change of size, and not specifically at the restore expandcollapse popup#Include <WindowsConstants.au3> #Include <GUIConstantsEx.au3> $Restored = True $hGUI = GUICreate("Test", 640, 480, -1, -1, $WS_OVERLAPPEDWINDOW) $Button1 = GUICtrlCreateButton("Maximize", 80, 56, 113, 33) GUISetState() GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 WinSetState($hGUI, "", @SW_MAXIMIZE) Sleep(1000) WinSetState($hGUI, "", @SW_RESTORE) EndSwitch WEnd ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-size Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) Switch BitAND($wParam, 0xFFFF) Case 0 ; SIZE_RESTORED If Not $Restored Then ConsoleWrite("Window was restored" & @LF) $Restored = True Case 1 ; SIZE_MINIMIZED ConsoleWrite("Window was minimized" & @LF) $Restored = False Case 2 ; SIZE_MAXIMIZED ConsoleWrite("Window was maximized" & @LF) $Restored = False EndSwitch Return "GUI_RUNDEFMSG" EndFunc Lion66 1 Link to comment Share on other sites More sharing options...
Lion66 Posted May 28, 2021 Author Share Posted May 28, 2021 The last two responses are identical and already more specific to question. Thanks for answers. 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