Jump to content

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

 

Link to comment
Share on other sites

#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 :)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
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:

Link to comment
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! 👍

Link to comment
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.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 5 weeks later...

Here's a subsequent insight that shows you shouldn't do something just because MS says so. ;)

The point at issue is the commented out line in the sample code below. To see the difference, uncomment the line.
; Return 0 ; <== If enabled, prevents the edit from being sized along with the GUI!

WM_Size Return Value (Microsoft Docs)

Quote

Return value

Type: LRESULT

If an application processes this message, it should return zero.

#include <AutoItConstants.au3>
#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

Global $g_hGui

Example()

Func Example()
  ; Create a GUI with various controls.
  $g_hGui = GUICreate("Example", 300, 100, -1, -1, $GUI_SS_DEFAULT_GUI + $WS_MAXIMIZEBOX + $WS_SIZEBOX)
  Local $idOK = GUICtrlCreateButton("OK", 10, 10, 85, 25)
  Local $edtUserParams = GUICtrlCreateEdit("", 10, 40, 280, 44, $WS_HSCROLL)

  GUISetState(@SW_SHOW, $g_hGui)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop

    EndSwitch
  WEnd
EndFunc   ;==>Example

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam, $lParam

  If $hWnd = $g_hGui Then
    ; Just for the demo show a little information.
    If BitAND(WinGetState($g_hGui), $WIN_STATE_MAXIMIZED) = $WIN_STATE_MAXIMIZED Then
      ToolTip("maximized")
      WinSetTitle($g_hGui, "", "maximized")
    Else
      ToolTip("restored")
      WinSetTitle($g_hGui, "", "restored")
    EndIf

;     Return 0 ; <== If enabled, prevents the edit from being sized along with the GUI!
  EndIf

  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

 

Edited by Professor_Bernd
Link to comment
Share on other sites

6 hours ago, Professor_Bernd said:

To see the difference, uncomment the line.
; Return 0 ; <== If enabled, prevents the edit from being sized along with the GUI!

Playing devil’s advocate: We do not actually know what is being returned to the calling function because we are just returning from an Autoit level function.  Some internal autoit code (written in C ?) actually handles the return.

Maybe this code is modifying the return value?  Just throwing out as a possibility.

Code hard, but don’t hard code...

Link to comment
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
 Share

  • Recently Browsing   0 members

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