Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Splitter: Resize two controls in a dialog

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Splitter: Resize two controls in a dialog

    Code:
    '________________________________________________________________________________________
    '
    '  SplitBoxes
    '  ----------
    '
    '  Demonstrates using a 'splitter' between two controls.
    '
    '  This is probably the quickest way of doing it without having to use a custom control
    '  or by subclassing any controls. The controls are resized as they are split.
    '
    '
    '  Created by KGP Software. May 24, 2005.
    '________________________________________________________________________________________
     
    #Compile Exe
    #Register All
    #Dim All
     
    %USEMACROS = 1
    #Include "win32api.inc"
    #Include "commctrl.inc"
     
    %IDC_CONTROL1   = 100       ' Left-pane
    %IDC_CONTROL2   = 200       ' Right-pane
     
    
    '------------------------------------------------------------------------------
    ' Draws a simple drag rectanle using XOR
    '------------------------------------------------------------------------------
    Sub DrawDragRect(ByVal hDlg As Dword, ByVal rcDrag As RECT)
      Local i As Long, hDC As Dword
      hDC = GetDC(hDlg)
      rcDrag.nRight = rcDrag.nLeft
      For i = 1 To 5
          Incr rcDrag.nRight
          DrawFocusRect hDC, rcDrag
      Next i
      ReleaseDC hDlg, hDC
    End Sub
     
    
    '------------------------------------------------------------------------------
    ' Callback procedure for the main dialog
    '------------------------------------------------------------------------------
    CallBack Function dlgMain
     
      Local pt As POINTAPI, tmpRC As RECT
      Static rc1 As RECT, rc2 As RECT, nInside As Long, nMouseDown As Long, rcDrag As RECT
     
      Select Case CbMsg
     
             Case %WM_INITDIALOG
                  ' Set primary positions...
                  rc1.nLeft = 5
                  rc1.nTop = 5
                  GetClientRect CbHndl, tmpRC
                  rc1.nRight = (tmpRC.nRight \ 2)-10
                  rc1.nBottom = tmpRC.nBottom-rc1.nTop
                  rc2.nRight = (tmpRC.nRight-(rc1.nLeft+rc1.nRight+5))
                  rc2.nBottom = tmpRC.nBottom-rc1.nTop
     
                  ' Move the controls to primary positions...
                  SetWindowPos GetDlgItem(CbHndl, %IDC_CONTROL1), 0, rc1.nLeft, rc1.nTop, rc1.nRight-rc1.nLeft, rc1.nBottom-rc1.nTop, %SWP_NOZORDER
                  SetWindowPos GetDlgItem(CbHndl, %IDC_CONTROL2), 0, rc1.nRight+5, rc1.nTop, rc2.nRight-rc2.nLeft, rc2.nBottom-rc1.nTop, %SWP_NOZORDER
     
             Case %WM_LBUTTONDOWN
                  ' Mouse pressed over right border...
                  If nInside = %TRUE Then
     
                     nMouseDown = %TRUE
                     SetCapture CbHndl
     
                     ' Draw drag rectangle...
                     SendMessage CbHndl, %WM_USER + 401, 0, VarPtr(rcDrag)
                     DrawDragRect CbHndl, rcDrag
                  End If
     
             Case %WM_MOUSEMOVE
                  ' Size border...
                  If nMouseDown Then
     
                     ' Remove last drag rectangle...
                     DrawDragRect CbHndl, rcDrag
     
                     ' Check bounds...
                     GetCursorPos pt
                     GetWindowRect CbHndl, tmpRC
     
                     If (pt.x < (tmpRC.nLeft+rc1.nLeft)) Then
                        ' Left side...
                        pt.x = tmpRC.nLeft
                     Else
                        If (pt.x > tmpRC.nRight-10) Then
                           ' Right side...
                           pt.x = tmpRC.nRight-10
                        End If
                     End If
                     ScreenToClient GetDlgItem(CbHndl, %IDC_CONTROL1), pt
     
                     ' This is where the controls are moved or 'split',
                     ' Each window is resized to fit the parent dialog...
                     GetClientRect CbHndl, tmpRC
                     rc1.nRight = rc1.nLeft + Max&(pt.x, 0)
                     rc1.nBottom = tmpRC.nBottom-rc1.nTop
                     SetWindowPos GetDlgItem(CbHndl, %IDC_CONTROL1), 0, 0, 0, rc1.nRight-rc1.nLeft, rc1.nBottom-rc1.nTop, %SWP_NOMOVE Or %SWP_NOZORDER
                     rc2.nRight = (tmpRC.nRight-(rc1.nLeft+rc1.nRight+5))
                     rc2.nBottom = rc1.nBottom
                     SetWindowPos GetDlgItem(CbHndl, %IDC_CONTROL2), 0, rc1.nRight+5, rc1.nTop, rc2.nRight, rc2.nBottom-rc1.nTop, %SWP_NOZORDER
     
                     ' Draw drag rectangle...
                     SendMessage CbHndl, %WM_USER + 401, 0, VarPtr(rcDrag)
                     DrawDragRect CbHndl, rcDrag
     
                  Else
                     ' Track border location...
                     GetCursorPos pt
                     ScreenToClient CbHndl, pt
                     SendMessage CbHndl, %WM_USER + 401, 0, VarPtr(tmpRC)
                     If PtInRect(tmpRC, pt.x, pt.y) Then
                        nInside = %TRUE
                        SetCapture CbHndl
                        SetCursor LoadCursor(0, ByVal %IDC_SIZEWE)
                     Else
                        nInside = %FALSE
                        ReleaseCapture
                        SetCursor LoadCursor(0, ByVal %IDC_ARROW)
                     End If
                  End If
     
             Case %WM_LBUTTONUP
                  ' Mouse released if sizing...
                  If nMouseDown Then
                     ReleaseCapture
                     Exit Function
                  End If
     
             Case %WM_CAPTURECHANGED
                  ' Mouse no longer captured...
                  If nMouseDown Then
                     If (CbLParam <> CbHndl) Then
                        nMouseDown = %FALSE
                        ' Remove last drag rectangle...
                        DrawDragRect CbHndl, rcDrag
                     End If
                  End If
     
            Case %WM_USER + 401
                 ' Special message, returns splitter rectangle...
                 Local prc As RECT Ptr
                 prc = CbLParam
                 @prc.nTop = rc1.nTop
                 @prc.nLeft = rc1.nRight
                 @prc.nRight = rc1.nRight + 5
                 @prc.nBottom = rc1.nBottom
     
      End Select
     
    End Function
     
    
     
    '------------------------------------------------------------------------------
    ' Program Start Point
    '------------------------------------------------------------------------------
    Function PBMain
     
      Local hDlg As Dword, lvc As LV_COLUMN, szText As Asciiz * 128
     
      InitCommonControls
     
      Dialog New 0, "Splitter Test", , , 300, 250, %WS_OVERLAPPEDWINDOW To hDlg
     
      Control Add $WC_LISTVIEW, hDlg, %IDC_CONTROL1, "", 0, 0, 0, 0, %WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %LVS_SINGLESEL Or %LVS_REPORT Or %LVS_SHOWSELALWAYS, %WS_EX_CLIENTEDGE
      Control Add TextBox, hDlg, %IDC_CONTROL2, "Sample Text", 0, 0, 0, 0, %ES_MULTILINE Or %ES_WANTRETURN Or %WS_TABSTOP, %WS_EX_CLIENTEDGE
     
      ' Add some sample columns...
      szText = "List Items"
      lvc.mask = %LVCF_TEXT Or %LVCF_WIDTH
      lvc.cx = 189
      lvc.pszText = VarPtr(szText)
      Control Send hDlg, %IDC_CONTROL1, %LVM_INSERTCOLUMN, 0, VarPtr(lvc)
     
      Dialog Show Modal hDlg Call dlgMain
     
    End Function
    ------------------
    email
    http://www.kgpsoftware.com
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me
Working...
X