Jump to content

Recommended Posts

Posted

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

 

Posted

@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:

  Reveal hidden contents


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

 

Posted
  On 5/26/2021 at 6:18 PM, Lion66 said:

message about the return of the window status

Expand  
#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

 

Posted (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 by Lion66
Posted

@Lion66 Just add a flag to track when the window is in a minimized state --

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

Posted
  On 5/27/2021 at 6:34 PM, Lion66 said:

but will be triggered at any change of size, and not specifically at the restore

Expand  
#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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...