Sign in to follow this  
Followers 0
supersonic

Strange: Can't min./max/restore window by button!?

4 posts in this topic

#1 ·  Posted (edited)

Hello,

I notice a strange behavior in my script if I try to min./max./restore a window by (window title) button.

It is possible to min. the window ONCE - any further try will result in lost window focus.

To reproduce the behavior I stripped the script down:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


Global $___WINDOW_HEIGHT = @DesktopHeight / 2
If $___WINDOW_HEIGHT < 400 Then
    $___WINDOW_HEIGHT = 400
EndIf
Global $___WINDOW_HEIGHT_MIN = $___WINDOW_HEIGHT


Global $___WINDOW_WIDTH = @DesktopWidth / 2
If $___WINDOW_WIDTH < 666 Then
    $___WINDOW_WIDTH = 666
EndIf
Global $___WINDOW_WIDTH_MIN = $___WINDOW_WIDTH


Global $hGUI1 = GUICreate("TEST1", $___WINDOW_WIDTH, $___WINDOW_HEIGHT, -1, -1, BitOR($WS_CAPTION, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_POPUP, $WS_SIZEBOX, $WS_SYSMENU), $WS_EX_TOPMOST, 0)
Global $hGUI1_B4 = GUICtrlCreateButton("MIN", 1, 1, 100, 36)
Global $hGUI1_B5 = GUICtrlCreateButton("MAX. / RESTORE", 102, 1, 100, 36)
Global $hGUI1_B7 = GUICtrlCreateButton("EXIT", 202, 1, 100, 36)


GUICtrlSetTip($hGUI1_B5, "Maximize main window to full screen.", "MAXIMIZE window.", 0, 0)
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO")
GUISetState(@SW_SHOW, $hGUI1)


Local $aTmp1[1] = [0]
Local $hMsg = 0
; ----------------------------------------------------------------------------------------------------
$aTmp1 = WinGetPos($hGUI1, "")
If Not @error Then
    $___WINDOW_HEIGHT_MIN = $aTmp1[3]
    $___WINDOW_WIDTH_MIN = $aTmp1[2]
EndIf
; ----------------------------------------------------------------------------------------------------
While 1
    $hMsg = GUIGetMsg(1)
    Switch $hMsg[1]
        Case $hGUI1
            Switch $hMsg[0]
                Case $GUI_EVENT_CLOSE, $hGUI1_B7
                    ExitLoop
                Case $hGUI1_B4
                    GUISetState(@SW_MINIMIZE, $hMsg[1])
;~                  _SendMessage($hMsg[1], 0x0112, 0xF020, 0) ; $WM_SYSCOMMAND, $SC_MINIMIZE. ; [http://msdn.microsoft.com/en-us/library/ms646360.aspx].
                Case $hGUI1_B5
                    If BitAND(WinGetState($hMsg[1], ""), 32) = 32 Then
                        GUISetState(@SW_RESTORE, $hMsg[1])
                    Else ; Non-error.
                        GUISetState(@SW_MAXIMIZE, $hMsg[1])
                    EndIf
            EndSwitch
    EndSwitch
WEnd


GUIDelete($hGUI1)


Func _WM_GETMINMAXINFO($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Switch $hWnd
        Case $hGUI1
            Local $tagMINMAXINFO = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $ilParam)
            DllStructSetData($tagMINMAXINFO, 7, $___WINDOW_WIDTH_MIN) ; Min. X.
            DllStructSetData($tagMINMAXINFO, 8, $___WINDOW_HEIGHT_MIN) ; Min. Y.
            DllStructSetData($tagMINMAXINFO, 9, @DesktopWidth) ; Max. X.
            DllStructSetData($tagMINMAXINFO, 10, @DesktopHeight) ; Max. Y.
            ; ----------------------------------------------------------------------------------------------------
            If BitAND(WinGetState($hWnd, ""), 32) = 32 Then
                GUICtrlSetTip($hGUI1_B5, "Restore main window to original position / size.", "RESTORE DOWN.")
            Else ; Non-error.
                GUICtrlSetTip($hGUI1_B5, "Maximize main window to full screen.", "MAXIMIZE window.")
            EndIf
    EndSwitch
    Return 0
EndFunc   ;==>_WM_GETMINMAXINFO

Somebody any idea?

Greets,

-supersonic.

Edited by supersonic

Share this post


Link to post
Share on other sites



supersonic,

It seems to be a problem with the WM_GETMINMAXINFO message handler interfering with the MINIMIZE command - if you disable the message handler before you minimize and re-enable it when you restore, everything seems to work (well it does for me): ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $___WINDOW_HEIGHT = @DesktopHeight / 2
If $___WINDOW_HEIGHT < 400 Then
    $___WINDOW_HEIGHT = 400
EndIf
Global $___WINDOW_HEIGHT_MIN = $___WINDOW_HEIGHT
Global $___WINDOW_WIDTH = @DesktopWidth / 2
If $___WINDOW_WIDTH < 666 Then
    $___WINDOW_WIDTH = 666
EndIf
Global $___WINDOW_WIDTH_MIN = $___WINDOW_WIDTH

Global $hGUI1 = GUICreate("TEST1", $___WINDOW_WIDTH, $___WINDOW_HEIGHT, -1, -1, BitOR($WS_CAPTION, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_POPUP, $WS_SIZEBOX, $WS_SYSMENU), $WS_EX_TOPMOST, 0)
Global $hGUI1_B4 = GUICtrlCreateButton("MIN", 1, 1, 100, 36)
Global $hGUI1_B5 = GUICtrlCreateButton("MAX. / RESTORE", 102, 1, 100, 36)
Global $hGUI1_B7 = GUICtrlCreateButton("EXIT", 202, 1, 100, 36)

GUICtrlSetTip($hGUI1_B5, "Maximize main window to full screen.", "MAXIMIZE wind&#111;w.", 0, 0)
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO")
GUISetState(@SW_SHOW, $hGUI1)

Local $aTmp1[1] = [0]
Local $hMsg = 0
; ----------------------------------------------------------------------------------------------------
$aTmp1 = WinGetPos($hGUI1, "")
If Not @error Then
    $___WINDOW_HEIGHT_MIN = $aTmp1[3]
    $___WINDOW_WIDTH_MIN = $aTmp1[2]
EndIf
; ----------------------------------------------------------------------------------------------------
While 1
    $hMsg = GUIGetMsg(1)
    Switch $hMsg[1]
        Case $hGUI1
            Switch $hMsg[0]
                Case $GUI_EVENT_CLOSE, $hGUI1_B7
                    ExitLoop
                Case $GUI_EVENT_Restore
                    GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                Case $hGUI1_B4
                    GUIRegisterMsg($WM_GETMINMAXINFO, "") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    GUISetState(@SW_MINIMIZE, $hMsg[1])
;~                         _SendMessage($hMsg[1], 0x0112, 0xF020, 0) ; $WM_SYSCOMMAND, $SC_MINIMIZE. ; [http://msdn.microsoft.com/en-us/library/ms646360.aspx].
                Case $hGUI1_B5
                    If BitAND(WinGetState($hMsg[1], ""), 32) = 32 Then
                        GUISetState(@SW_RESTORE, $hMsg[1])
                    Else ; Non-error.
                        GUISetState(@SW_MAXIMIZE, $hMsg[1])
                    EndIf
            EndSwitch
    EndSwitch
WEnd

GUIDelete($hGUI1)

#Region --- _WM_GETMINMAXINFO()
    Func _WM_GETMINMAXINFO($hWnd, $iMsg, $iwParam, $ilParam)
        #ForceRef $hWnd, $iMsg, $iwParam, $ilParam
        Switch $hWnd
            Case $hGUI1
                Local $tagMINMAXINFO = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $ilParam)
                DllStructSetData($tagMINMAXINFO, 7, $___WINDOW_WIDTH_MIN) ; Min. X.
                DllStructSetData($tagMINMAXINFO, 8, $___WINDOW_HEIGHT_MIN) ; Min. Y.
                DllStructSetData($tagMINMAXINFO, 9, @DesktopWidth) ; Max. X.
                DllStructSetData($tagMINMAXINFO, 10, @DesktopHeight) ; Max. Y.
                ; ----------------------------------------------------------------------------------------------------
                If BitAND(WinGetState($hWnd, ""), 32) = 32 Then
                    GUICtrlSetTip($hGUI1_B5, "Restore main window to original position / size.", "RESTORE DOWN")
                Else ; Non-error.
                    GUICtrlSetTip($hGUI1_B5, "Maximize main window to full screen.", "MAXIMIZE WINDOW")
                EndIf
        EndSwitch
        Return 0
    EndFunc   ;==>_WM_GETMINMAXINFO
#EndRegion --- _WM_GETMINMAXINFO()

How does it run for you? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba23,

thank you very much - again! It's the Xth time you helped me out! :)

Greets,

-supersonic.

Share this post


Link to post
Share on other sites

supersonic,

My pleasure as always. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0