Date: 02-16-2022
Return to Index
created by gbSnippets
'in this example, two textboxes divide the client area equally
'resizing the window resizes the two controls
'the resize code is found under %WM_Size
'Primary Code:
'The %WM_Size is the place to put your resize code. When the
'users resizes the window, the %WM_Size message is received.
Select Case CB.Msg
Case %WM_Size
'this is the resize code - it sets size/location of the controls
'NOTE: Dialog Get Size (exterior dialog dimensions) is NOT used
Dim w As Long, h As Long
Dialog Get Client CB.Hndl To w,h
Control Set Loc CB.Hndl, %ID_TextBoxA, 5,5
Control Set Size CB.Hndl, %ID_TextBoxA, (w-20)/2, h-10
Control Set Loc CB.Hndl, %ID_TextBoxB, w/2+5, 5
Control Set Size CB.Hndl, %ID_TextBoxB, (w-20)/2, h-10
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%ID_TextBoxA = 200 : %ID_TextBoxB = 300
Function PBMain () As Long
Local hDlg As Dword
Dialog New Pixels, 0, "Control Resize",100,100,200,200, %WS_OverlappedWindow To hDlg
Control Add TextBox, hDlg, %ID_TextBoxA, "BoxA", 0,0,50,50
Control Add TextBox, hDlg, %ID_TextBoxB, "BoxB", 0,0,50,50
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Size
'this is the resize code - it sets size/location of the controls
'NOTE: Dialog Get Size (exterior dialog dimensions) is NOT used
Dim w As Long, h As Long
Dialog Get Client CB.Hndl To w,h
Control Set Loc CB.Hndl, %ID_TextBoxA, 5,5
Control Set Size CB.Hndl, %ID_TextBoxA, (w-20)/2, h-10
Control Set Loc CB.Hndl, %ID_TextBoxB, w/2+5, 5
Control Set Size CB.Hndl, %ID_TextBoxB, (w-20)/2, h-10
End Select
End Function
'gbs_00054
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm