Date: 02-16-2022
Return to Index
created by gbSnippets
'Often, a programmer wants to limit the size of dialog, usually to avoid hiding
'controls when a window size is decreased, but also to avoid making an area
'larger than the programmer can handle.
'Note: neither of the approaches here prevent flicker when a dialog is maximized.
'see the snippet on using the %WM_SysCommand for more information.
'Primary Code:
'Example#1 - responds to %WM_GetMinMaxInfo message in Callback function
Case %WM_GETMINMAXINFO
Local MM As MINMAXINFO Ptr
MM=CB.lParam
@MM.ptMinTrackSize.x=150 '<-- Min X size of your window
@MM.ptMinTrackSize.y=150 '<-- Min Y size of your window
@MM.ptMaxTrackSize.x=500 '<-- Max X size of your window
@MM.ptMaxTrackSize.y=500 '<-- Max Y size of your window
'Example#2 - responds to %WM_Size message in Callback function
'NOTE: although this might be an obvious approach (and it will work),
'it is NOT recommended because WM_Size occurs after the window
'size has changed, so flickering may be seen on slower systems.
Case %WM_Size
Local MaxWidth&, MaxHeight&, MinWidth&, MinHeight&, w As Long, h As Long
MaxWidth& = 500 : MaxHeight& = 500
MinWidth& = 150 : MinHeight& = 150
Dialog Get Size hDlg To w,h
If w > MaxWidth Then Dialog Set Size hDlg, MaxWidth,h
If h > MaxHeight Then Dialog Set Size hDlg, w,MaxHeight
If w < MinWidth Then Dialog Set Size hDlg, MinWidth,h
If h < MinHeight Then Dialog Set Size hDlg, w,MinHeight
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10 Uses Example#1 method
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_GETMINMAXINFO
Local MM As MINMAXINFO Ptr
MM=CB.lParam
@MM.ptMinTrackSize.x=150 '<-- Min X size of your window
@MM.ptMinTrackSize.y=150 '<-- Min Y size of your window
@MM.ptMaxTrackSize.x=500 '<-- Max X size of your window
@MM.ptMaxTrackSize.y=500 '<-- Max Y size of your window
End Select
End Function
'gbs_00045
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm