Is there an easy way to set the maximum size of a dialog. I found DIALOG SET MINSIZE for minimum size, but couldn't find anything for maximum size...
Petr Schreiber
23-05-2009, 21:42
Hi,
there is no such a functionality directly available, but you can try following approach:
- process WM_SIZING message
- overlap RECT structure over it
- trim width/height to maximum allowed values
Just one personal side note from my side - I do not like programs limiting maximum window size. I have bought video editing software, which does not allow to resize window over 1024x768, it is locked to this resolution even when clicking maximize. You can imagine on big screen this can be big trouble for user.
Here is the code:
' Limiting maximum dialog size
' Created by Petr Schreiber
USES "UI"
' -- ID numbers of controls
Begin Const
%btnClose = 1000
%lblStatus
End Const
' -- Create dialog here
FUNCTION TBMAIN()
LOCAL hDlg AS DWORD
%maxWidth = 400
%maxHeight = 300
DIALOG New 0, "Resize to no more than 400x300 units",-1,-1, 160, 120, _
%WS_POPUP Or %WS_VISIBLE Or _
%WS_CLIPCHILDREN Or %WS_CAPTION OR _
%WS_SYSMENU Or %WS_MINIMIZEBOX or %WS_THICKFRAME, 0 To hDlg
' -- Place controls here
CONTROL ADD LABEL, hDlg, %lblStatus, "Resize!", 5, 5, 100, 28
CONTROL ADD BUTTON, hDlg, %btnClose, "Click to close", 95, 100, 60, 14, CALL btnCloseProc
DIALOG SHOW MODAL hDlg, CALL dlgProc
END FUNCTION
' -- Callback for dialog
CALLBACK FUNCTION dlgProc()
' -- Test for messages
SELECT CASE CBMSG
CASE %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
CASE %WM_COMMAND
' -- Essential message for managing dialog size
CASE %WM_SIZING
dim lp as RECT at cblparam
dim currentWidth as long = (lp.nRight-lp.nLeft)
dim currentHeight as long = (lp.nBottom-lp.nTop)
dim maximumWidth, maximumHeight as long
' -- Convert units to pixels
dialog units cbhndl, %maxWidth, %maxHeight to pixels maximumWidth, maximumHeight
if currentWidth > maximumWidth or currentHeight > maximumHeight then
lp.nRight = lp.nLeft + min(currentWidth , maximumWidth)
lp.nBottom = lp.nTop + min(currentHeight , maximumHeight)
end if
currentWidth = (lp.nRight-lp.nLeft)
currentHeight = (lp.nBottom-lp.nTop)
dim currentWidthU as long
dim currentHeightU as long
dialog pixels cbhndl, currentWidth, currentHeight to units currentWidthU, currentHeightU
control set text cbhndl, %lblStatus, STRFORMAT$("W:{1}/{2} u, H{3}/{4} u", currentWidthU, %maxWidth, currentHeightU, %maxHeight)
CASE %WM_CLOSE
' -- Put code to be executed before dialog end here
END SELECT
END FUNCTION
' -- Callback for close button
CALLBACK FUNCTION btnCloseProc()
IF CBMSG = %WM_COMMAND THEN
IF CBCTLMSG = %BN_CLICKED THEN
' -- Closes the dialog
DIALOG END CBHNDL
END IF
END IF
END FUNCTION
Hi Petr,
Many thanks for your example!
Just one personal side note from my side - I do not like programs limiting maximum window size. I have bought video editing software, which does not allow to resize window over 1024x768, it is locked to this resolution even when clicking maximize. You can imagine on big screen this can be big trouble for user.
You are absolutely right about this, but in some rare cases I will need this.
BTW I didn't know %WM_SIZING exists. Is there a list available with all %WM parameters?
Martin
Petr Schreiber
24-05-2009, 09:58
Hi Martin,
I must admit I did not used WM_SIZING in this way before too.
Here is a script, which will save to file list of all WM_ equates UI module supports now:
uses "UI", "console", "File"
DIM allEquates AS STRING
DIM Equate() AS STRING
DIM i AS LONG
DIM sOut AS STRING
printl "Retrieving equates..."
'---Get a string with equates separated by $TAB
allEquates = APP_ListEquates
'---Parse string into an array
PARSE allEquates, Equate, $TAB
'---Creates output buffer
FOR i = 1 TO UBOUND(Equate(1))
IF LEFT$(Equate(i), 4) = "%WM_" THEN sOut += Equate(i) + $CRLF
NEXT
printl "Saving equates..."
'---Save buffer into .INC file
File_Save(APP_SourcePath & "WM_Equates.txt", sOut)
printl "Done..."
waitkey
Documentation on these can be found on MS website for example here:
http://msdn.microsoft.com/en-us/library/dd469354(VS.85).aspx
Petr
ErosOlmi
25-05-2009, 12:26
Just one personal side note from my side - I do not like programs limiting maximum window size. I have bought video editing software, which does not allow to resize window over 1024x768, it is locked to this resolution even when clicking maximize. You can imagine on big screen this can be big trouble for user.
I think this quote from Petr is important.
Programs limiting how windows can size is something to avoid as much as possible.
Minimum size can be understandable (in my opinion) if minimum dimensions are very little but not max size unless there is a valid reason of course.
Programmers have to design their applications in such a way applications react correctly regardless window sizing.
Programmers have also to consider there are multi-monitor situations where a window can span over more than one monitor.
Ciao
Eros