Date: 02-16-2022
Return to Index
created by gbSnippets
'This snippet shows how to implement splitterbars with text controls. It
'does not resize the controls until the splitter bar is released.
'Primary Code:
'Due to the length of this example, the primary code is only included in
'the example below.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32api.inc"
%IDC_Left = 500 : %IDC_Right = 501 : %IDC_Bottom = 502
%IDC_LabelH = 532 : %IDC_LabelV = 533
Global hDlg As DWord
Global SplitVInWork, SplitHInWork As Long
Global HBarLeft, VBarTop, OldProc As Long
Function PBMain()
Local style&
style& = %WS_TabStop Or %WS_Border Or %ES_Left Or %ES_AutoHScroll _
Or %ES_MultiLine Or %ES_NoHideSel Or %ES_WantReturn Or %WS_ClipSiblings
Dialog New Pixels, 0, "Splitter Text",300,300,410,340, %WS_OverlappedWindow Or %WS_ClipChildren To hDlg
'add the controls + splitter bars (labels)
Control Add TextBox, hDlg, %IDC_Left, "TopLeft", 20, 20, 160, 80, style&
Control Add TextBox, hDlg, %IDC_Bottom, "Bottom", 20, 200, 370, 90, style&
Control Add TextBox, hDlg, %IDC_Right, "Right", 20, 80, 160, 80, style&
Control Add Label, hDlg, %IDC_LabelH, "", 200, 20, 6, 125, %SS_Notify , %WS_Ex_ClientEdge ' up/down - does horizontal split
Control Add Label, hDlg, %IDC_LabelV, "", 0,170, 410, 6, %SS_Notify , %WS_Ex_ClientEdge ' left/right - does vertical split
HBarLeft = 150 : VBarTop = 150 'starting position
Dialog Show Modal hDlg Call DlgProc()
End Function
CallBack Function DlgProc() As Long
Local iReturn As Long, x As Long, y As Long, w As Long, h As Long
Select Case CB.Msg
Case %WM_Size
ResizeWindow(1)
Case %WM_SetCursor
iReturn = GetDlgCtrlID (CB.wParam) 'determine which over which label control mouse was moved
If iReturn = %IDC_LabelH Then MousePTR 9 : Function = 1 '9 = horizontal cursor
If iReturn = %IDC_LabelV Then MousePTR 7 : Function = 1 '7 = vertical cursor
Select Case Hi(Word, CB.lParam)
Case %WM_LButtonDown
If iReturn = %IDC_LabelV Then SplitVInWork = 1 : ResizeWindow(0)
If iReturn = %IDC_LabelH Then SplitHInWork = 1 : ResizeWindow(0)
Case %WM_MouseMove
'Repositions splitter bars to match mouse position (if position has changed)
If SplitVInWork Then If MoveBarUpDown Then ResizeWindow(0)
If SplitHInWork Then If MoveBarLeftRight Then ResizeWindow(0)
Case %WM_LButtonUp
If SplitHInWork Or SplitVInWork Then
SplitHInWork = 0 : SplitVInWork = 0 'sets flags to say splitter action has ended
ResizeWindow(1)
End If
End Select
End Select
End Function
Function MoveBarUpDown As Long
'returns true if mouse moved vertically while button was down over the horizontal bar
Local pt As Point, h As Long, w As Long
Static oldY As Long
Dialog Get Client hDlg To w,h
GetCursorPos pt 'pt has xy screen coordinates
ScreenToClient hDlg, pt 'pt now has client coordinates
VBarTop = h - (Pt.y-3)
If pt.y <> oldY Then Function = %True : oldY = pt.y
End Function
Function MoveBarLeftRight As Long
'returns true if mouse moved horizontaolly while button was down over the vertical bar
Local pt As Point, h As Long, w As Long
Static oldX As Long
Dialog Get Client hDlg To w,h
GetCursorPos pt 'pt has xy screen coordinates
ScreenToClient hDlg, pt 'pt now has client coordinates
HBarLeft = pt.x-3
If pt.x <> oldX Then Function = %True : oldX = pt.x
End Function
Sub ResizeWindow(Flag As Long)
Local h, w, M, T, HLeft, VTop, Color As Long
'Resize Splitter Bars
Dialog Get Client hDlg To w,h
M = 5 'margin around controls
T = 6 'splitter thickness (smallest dimension)
VTop = h - VBarTop 'VTop will be position of horizontal bar
HLeft = HBarLeft 'HLeft will be position of vertical bar
'splitterbar colors - change colors when move is in work
If SplitVInWork Then Color = %Gray Else Color = %Red
Control Set Color hDlg, %IDC_LabelV, %Black, Color
If SplitHInWork Then Color = %Gray Else Color = %Blue
Control Set Color hDlg, %IDC_LabelH, %Black, Color
'resize splitterbars
If Flag Or SplitHInWork Then
Control Set Size hDlg, %IDC_LabelH, T, h - 2*M - 10
Control Set Loc hDlg, %IDC_LabelH, HLeft, 10
End If
If Flag Or SplitVInWork Then
Control Set Size hDlg, %IDC_LabelV, HLeft - M - 5, T
Control Set Loc hDlg, %IDC_LabelV, M, VTop
End If
If Flag Then
'Resize controls only when form resizes or left/right move is NOT in work
Control Set Loc hDlg, %IDC_Left, 5, 10
Control Set Size hDlg, %IDC_Left, HLeft - 10, VTop - 20
Control Set Loc hDlg, %IDC_Right, HLeft + 10, 10
Control Set Size hDlg, %IDC_Right, w - HLeft - 20, h - 20
Control Set Loc hDlg, %IDC_Bottom, 5, VTop + 15
Control Set Size hDlg, %IDC_Bottom, HLeft - 10, h - VTop - 25
End If
Dialog Redraw hDlg
End Sub
'gbs_00684
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm