Jump to content
Professor_Bernd

Does a registered WM_GETMINMAXINFO function need a "Return"?

Recommended Posts

Today a very simple question (if you know how to do it, everything is easy!) :P

"Return, or not return, that is the question.;)

In a registered function (GUIRegisterMsg()) for WM_GETMINMAXINFO, is there a "Return" needed?

See the 3 places marked with "<==".

#include <GUIConstants.au3>

GUIRegisterMsg($WM_GETMINMAXINFO, "MY_WM_GETMINMAXINFO")

Global $nMsg, $minmaxinfo

; Gui-1
Global $hGui_1 = GUICreate("", 400, 75, 232, 122, BitOR($WS_CAPTION, $WS_POPUPWINDOW, $WS_SIZEBOX)) ; Show close button only.
WinSetTitle($hGui_1, "", "Gui-1 - set: min width/height, max height")

Global $iGUI_1_Height = WinGetPos($hGui_1)[3]

GUISetState(@SW_SHOW)

; Gui-2
Global $hGui_2 = GUICreate("", 629, 200, 232, 244, BitOR($GUI_SS_DEFAULT_GUI , $WS_SIZEBOX, $WS_MAXIMIZEBOX))
WinSetTitle($hGui_2, "", "Gui-2 - set: min width/height - maximized left, top, width, height")

Global $iGUI_2_Height = WinGetPos($hGui_2)[3]

GUISetState(@SW_SHOW)

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      ExitLoop

  EndSwitch
WEnd

; Set minimum and maximum for height and width of GUI.
Func MY_WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
  #forceref $iMsg, $wParam, $lParam

  ; Gui-1
  If $hWnd = $hGui_1 Then
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, 400) ; min width
    DllStructSetData($minmaxinfo, 8, $iGUI_1_Height) ; min height
;     DllStructSetData($minmaxinfo, 9, 2000) ; max width ; <== If a value is NOT specified, it is NOT restricted.
    DllStructSetData($minmaxinfo, 10, $iGUI_1_Height) ; max height

;     Return 0 ; or Return $GUI_RUNDEFMSG or nothing?   <==
  EndIf

  ; Gui-2
  If $hWnd = $hGui_2 Then
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 3, 1200) ; width of the maximized window
    DllStructSetData($minmaxinfo, 4, 800) ; height of the maximized window
    DllStructSetData($minmaxinfo, 5, 20) ; left of the maximized window
    DllStructSetData($minmaxinfo, 6, 40) ; top of the maximized window
    DllStructSetData($minmaxinfo, 7, 400) ; min width
    DllStructSetData($minmaxinfo, 8, 200) ; min height

;     Return 0 ; or Return $GUI_RUNDEFMSG or nothing?   <==
  EndIf

;   Return 0 ; or Return $GUI_RUNDEFMSG or nothing?     <==
EndFunc   ;==>MY_WM_GETMINMAXINFO

 

Share this post


Link to post
Share on other sites
Posted (edited)
#include <GUIConstantsEx.au3>
ConsoleWrite('$GUI_RUNDEFMSG = ' & $GUI_RUNDEFMSG & ' ; VarGetType: ' & VarGetType( $GUI_RUNDEFMSG ) & @CRLF)

From the help file: So an early return from the user function requires Return $GUI_RUNDEFMSG if the AutoIt internal handler for that message is to run (see other examples).

So yes, unless you have a very good reason to do otherwise, do the Return "GUI_RUNDEFMSG", as AutoIt gets an "ok" ( via the string ) to take it from there.

Edited by argumentum
clarification, ....maybe :)

Share this post


Link to post
Share on other sites
Quote

By default the AutoIt internal message handler (if there is one for that message) will be actioned after the user function exits. The AutoIt internal message handler will also be actioned if the keyword Return is used with the constant $GUI_RUNDEFMSG (found in GUIConstantsEx.au3).

I have read that, of course. ;) This means that if I don't use Return, it's the same as if I use Return with $GUI_RUNDEFMSG. The question is rather if a return with a different value is needed. Here for example @Zedna has used a Return 0. But I can't see the reason for that.

Quote

So an early return from the user function requires Return $GUI_RUNDEFMSG if the AutoIt internal handler for that message is to run (see other examples).

The reason I ask in this thread is because I don't know, is there even an early return from the user function in this case? To me it looks like the user function runs through "normally" and thus no return is needed, or a return with $GUI_RUNDEFMSG 1x at the end of the user function. Is this correct? (oh, now I got myself confused). :wacko:

Share this post


Link to post
Share on other sites

And I was beginning to think it was a simple question. :P

Thanks to your info, it's starting to make sense. Here's how I understood it:

; Set minimum and maximum for height and width of GUI.
Func MY_WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
  #forceref $iMsg, $wParam, $lParam

  ; Gui-1
  If $hWnd = $hGui_1 Then
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, 400) ; min width
    DllStructSetData($minmaxinfo, 8, $iGUI_1_Height) ; min height
;     DllStructSetData($minmaxinfo, 9, 2000) ; max width ; <== If a value is NOT specified, it is NOT restricted.
    DllStructSetData($minmaxinfo, 10, $iGUI_1_Height) ; max height

    Return 0 ;                           <==
  EndIf

  ; Gui-2
  If $hWnd = $hGui_2 Then
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 3, 1200) ; width of the maximized window
    DllStructSetData($minmaxinfo, 4, 800) ; height of the maximized window
    DllStructSetData($minmaxinfo, 5, 20) ; left of the maximized window
    DllStructSetData($minmaxinfo, 6, 40) ; top of the maximized window
    DllStructSetData($minmaxinfo, 7, 400) ; min width
    DllStructSetData($minmaxinfo, 8, 200) ; min height

    Return 0 ;                           <==
  EndIf

  Return $GUI_RUNDEFMSG ; or nothing     <==
EndFunc   ;==>MY_WM_GETMINMAXINFO

 

Thank you all for your quick reply and competent opinion/info! 👍

Share this post


Link to post
Share on other sites

my way ...

Global $__g_aGETMINMAXINFO[4] = [0, 0, 0, 0] ; for WM_GETMINMAXINFO() to limit GUI minimum and/or maximum size. Default of zero means disable.
Func WM_GETMINMAXINFO($hWnd, $msg, $wParam, $lParam)
    Local $tagMINMAXINFO = DllStructCreate("struct;long;long;long;long;long;long;long MinTrackSizeX;long MinTrackSizeY;long MaxTrackSizeX;long MaxTrackSizeY;endstruct", $lParam)
    If $__g_aGETMINMAXINFO[0] Then $tagMINMAXINFO.MinTrackSizeX = $__g_aGETMINMAXINFO[0] ; DllStructSetData($tagMINMAXINFO, 7, $__g_aGETMINMAXINFO[0]) ; min X
    If $__g_aGETMINMAXINFO[1] Then $tagMINMAXINFO.MinTrackSizeY = $__g_aGETMINMAXINFO[1]
    If $__g_aGETMINMAXINFO[2] Then $tagMINMAXINFO.MaxTrackSizeX = $__g_aGETMINMAXINFO[2]
    If $__g_aGETMINMAXINFO[3] Then $tagMINMAXINFO.MaxTrackSizeY = $__g_aGETMINMAXINFO[3]
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_GETMINMAXINFO

... is not about the return but ... my usage. It may give you ideas.

Share this post


Link to post
Share on other sites
Posted (edited)
31 minutes ago, argumentum said:

my way ...

Global $__g_aGETMINMAXINFO[4] = [0, 0, 0, 0] ; ... Default of zero means disable.

Func WM_GETMINMAXINFO($hWnd, $msg, $wParam, $lParam)
    ...
    If $__g_aGETMINMAXINFO[0] Then $tagMINMAXINFO.MinTrackSizeX = $__g_aGETMINMAXINFO[0] 
    If $__g_aGETMINMAXINFO[1] Then $tagMINMAXINFO.MinTrackSizeY = $__g_aGETMINMAXINFO[1]
    If $__g_aGETMINMAXINFO[2] Then $tagMINMAXINFO.MaxTrackSizeX = $__g_aGETMINMAXINFO[2]
    If $__g_aGETMINMAXINFO[3] Then $tagMINMAXINFO.MaxTrackSizeY = $__g_aGETMINMAXINFO[3]
    ...
31 minutes ago, argumentum said:

... is not about the return but ... my usage. It may give you ideas.

The idea to change a member of the struct only if a value greater than 0 was passed is indeed an interesting idea! 👍

Edited by Professor_Bernd

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...