Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32api.inc"
%IDC_Left = 500 : %IDC_Bottom = 502
%IDC_LabelV = 533
Global hDlg As Dword
Global SplitVInWork, VBarTop 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 Label, hDlg, %IDC_LabelV, "", 0,170, 410, 6, %SS_Notify , %WS_Ex_ClientEdge ' left/right - does vertical split
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_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)
Case %WM_MouseMove
'Repositions splitter bars to match mouse position (if position has changed)
If SplitVInWork Then If MoveBarUpDown Then ResizeWindow(0)
Case %WM_LButtonUp
If SplitVInWork Then
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
Sub ResizeWindow(Flag As Long)
Local h, w, M, T, 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
'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
'resize splitterbars
If Flag Or SplitVInWork Then
Control Set Size hDlg, %IDC_LabelV, w - 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, w - 10, VTop - 20
Control Set Loc hDlg, %IDC_Bottom, 5, VTop + 15
Control Set Size hDlg, %IDC_Bottom, w - 10, h - VTop - 25
End If
Dialog ReDraw hDlg
End Sub
'gbs_01185
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm