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

DDT: Scrolling (classic method)

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

  • DDT: Scrolling (classic method)

    Two days ago I posted a code, how to scroll a bitmap.
    The same way works fine for entire dialog (at least on my PC under Win2000).

    09.02. Added MOUSEWHEEL (if wheel is pressed - horizontal direction)

    Code:
       #Compile Exe
       #Dim All
       #Register None
       #Include "WIN32API.INC"
    
       Global DlgProcOr As Long
    
       CallBack Function SC_DlgProc
          Dim si(1) As Static SCROLLINFO, szPg(1) As Static Long, szBm(1) As Static Long, CurrentScroll(1) As Static Long
          Dim rc As RECT, i As Long, j As Long, Delta(1) As Long, ij As Integer
          Select Case CbMsg
             Case %WM_SIZE
                PostMessage CbHndl, %WM_USER + 402, CbWparam, CbLparam
             Case %WM_USER + 401
                Dialog Units CbHndl, CbWparam, CbLparam To Pixels szBm(0), szBm(1)
             Case %WM_USER + 402
                GetClientRect CbHndl, rc
                szPg(0) = rc.nRight - rc.nLeft
                szPg(1) = rc.nBottom - rc.nTop
                ScrollWindowEx  CbHndl, CurrentScroll(0), CurrentScroll(1), ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&, _
                   %SW_ERASE Or %SW_INVALIDATE Or %SW_SCROLLCHILDREN
                For i = 0 To 1
                   CurrentScroll(i) = 0
                   si(i).cbSize     = SizeOf(si(i))
                   si(i).fMask      = %SIF_ALL
                   si(i).nPage      = szPg(i)
                   si(i).nMax       = szBm(i)
                   si(i).nPos       = CurrentScroll(i)
                   If i = 0 Then j = %SB_HORZ Else j = %SB_VERT
                   SetScrollInfo CbHndl, j, si(i), 1
                Next
                SetFocus CbHndl
              
             Case %WM_HSCROLL, %WM_VSCROLL, %WM_MOUSEWHEEL
                If CbMsg = %WM_HSCROLL Then i = 0 Else i = 1
                j = CurrentScroll(i)
                If CbMsg = %WM_MOUSEWHEEL Then
                   If IsFalse(GetSystemMetrics(%SM_MOUSEWHEELPRESENT)) Then
                   Else
                      If (LoWrd(CbWparam) And %MK_MBUTTON) = %MK_MBUTTON Then i = 0: j = CurrentScroll(i)
                      ij = HiWrd(CbWparam)
                      j = CurrentScroll(i) + 0.1 * si(i).nPage * ij / 120
                   End If
                Else
                   Select Case LoWrd(CbWparam)
                      Case %SB_PAGEUP       : j = CurrentScroll(i) - si(i).nPage
                      Case %SB_PAGEDOWN     : j = CurrentScroll(i) + si(i).nPage
                      Case %SB_LINEUP       : j = CurrentScroll(i) - 0.1 * si(i).nPage
                      Case %SB_LINEDOWN     : j = CurrentScroll(i) + 0.1 * si(i).nPage
                      Case %SB_THUMBPOSITION: j = HiWrd(CbWparam)
                   End Select
                End If
                
                j = Max(0, j): j = Min(Max(szBm(i) - szPg(i), 0), j)
                If j <> CurrentScroll(i) Then
                Delta(i) = j - CurrentScroll(i)
                CurrentScroll(i) = j
                ScrollWindowEx  CbHndl, -Delta(0), -Delta(1), ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&, _
                   %SW_ERASE Or %SW_INVALIDATE Or %SW_SCROLLCHILDREN
                UpdateWindow CbHndl
               
                si(i).nPos   = CurrentScroll(i)
                If i = 0 Then j = %SB_HORZ Else j = %SB_VERT
                SetScrollInfo CbHndl, j, si(i), 1
                End If
          End Select
          Function = CallWindowProc(DlgProcOr, CbHndl, CbMsg, CbWparam, CbLparam)
       End Function
       
       CallBack Function DlgProc
          Select Case CbMsg
             Case %WM_INITDIALOG
                Local i As Long, j As Long
                For j = 0 To 20: For i = 0 To 5
                   Control Add Button, CbHndl, 100 + j * 10 + i, "Row =" + Str$(j) + " Col =" + Str$(i), 5 + 120 * i, 5 + 30 * j, 100, 15
                Next: Next
                PostMessage CbHndl, %WM_USER + 401, 710, 625
                
             Case %WM_ERASEBKGND
                PaintDesktop CbWparam: Function = 1: Exit Function
          End Select
       End Function
    
       Function PbMain()
          Dim hDlg As Long
          Dialog New %HWND_DESKTOP, "Scroll DDT", , , 300, 300, _
             %WS_CAPTION Or %WS_SYSMENU Or %WS_VSCROLL Or %WS_HSCROLL Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX Or %WS_THICKFRAME To hDlg
          DlgProcOr = SetWindowLong (hDlg, %GWL_WNDPROC, CodePtr(SC_DlgProc))
          Dialog Show Modal hDlg Call DlgProc
      End Function
    [This message has been edited by Semen Matusovski (edited February 09, 2001).]
Working...
X