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:
[code=thinbasic]
' 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
[/code]
Bookmarks