Announcement

Collapse
No announcement yet.

Scrollbar control basics

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

  • Gösta H. Lovgren-2
    replied
    Started working on the Scroll Bars in Easy Tape and found this thread. I tool My Pal Rodney 's example (#9) and fooled around with it until I understood it better (removed all the unnecessary PBForms stuff and renamed some variables).

    Took me awhile to realize when the scroll posn is returned, it's actually figured from a percentage of the range of where the scroll "button' is in the range (that's probably not sensical to anyone else (except maybe My Pal)) but anyway here's the code:

    Code:
      
    'http://powerbasic.com/support/pbforums/showthread.php?t=38102&highlight=add+scrollbar
    'Rodney Hicks
    '--------------------------------------------------------------------------------------------------
    ' *******************************************************
    'PBWIN 9.02 - WinApi 05/2008 - XP Pro 
     '
    ' *******************************************************
    
    #Compile Exe
    #Dim All
    '--------------------------------------------------------------------------------------------------
    '   ** Includes **
    '--------------------------------------------------------------------------------------------------
    #If Not %Def(%WINAPI)
      #Include "WIN32API.INC"
    #EndIf
    '--------------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------------
    '   ** Constants **
    '--------------------------------------------------------------------------------------------------
    %IDD_DIALOG1 =  101
    %IDC_LABEL1  = 1001
    %IDC_LABEL2  = 1002
    %IDC_LABEL3  = 1003
    %IDC_HELPME  = 1004
    '--------------------------------------------------------------------------------------------------
    Global g_dlg_wd, g_dlg_ht As Long
    Global g_dlg_Widest_Control, g_dlg_Deepest_Control As Long
    '--------------------------------------------------------------------------------------------------
    '   ** Declarations **
    '--------------------------------------------------------------------------------------------------
    Declare CallBack Function ShowDIALOG1Proc()
    Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
    '--------------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '--------------------------------------------------------------------------------------------------
    Function PBMain()
      ShowDIALOG1 %HWND_DESKTOP
    End Function
    '--------------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------------
    '   ** CallBacks **
    '--------------------------------------------------------------------------------------------------
    CallBack Function ShowDIALOG1Proc()
      Local w As Long, h As Long, oldPos As Long, si As SCROLLINFO
      Local vt As Long, ht As Long, hs As Long, vs As Long
    '
      Local White_Space_Moves, Arrow_Moves As Long
    '
      w= 600 
      h= 600                ' '
      vt=50  'White space moves
      ht=50  'White space moves
      hs=5   'Arrow Moves
      vs=5   'Arrow Moves    
      White_Space_Moves = vt
      Arrow_Moves = vs
    '
      Select Case As Long CbMsg
        Case %WM_INITDIALOG
          ' Initialization handler
          si.cbSize=Len(si)
          si.fMask=%SIF_ALL
          si.nMin=0
          si.nMax= g_dlg_Deepest_Control'h
          si.nPage= White_Space_Moves 'vt
          SetScrollInfo CbHndl, %SB_VERT, si, 1
          si.nMin=0
          si.nMax= g_dlg_Widest_Control 'w
          si.nPage= White_Space_Moves
          si.nPos=0
          SetScrollInfo CbHndl, %SB_HORZ, si, 1
        Case %WM_NCACTIVATE
          Static hWndSaveFocus As Dword
          If IsFalse CbWParam Then
            ' Save control focus
            hWndSaveFocus = GetFocus()
          ElseIf hWndSaveFocus Then
            ' Restore control focus
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          End If
        Case %WM_COMMAND
          ' Process control notifications
          Select Case As Long CbCtl
            Case %IDC_LABEL1
            Case %IDC_LABEL2
            Case %IDC_HELPME
              ?"clicked"
          End Select
        Case %WM_HSCROLL
          si.cbSize=SizeOf(si)
          si.fMask=%SIF_ALL
          GetScrollInfo CbHndl, %SB_HORZ, si
          oldPos=si.nPos
          Select Case LoWrd(CbWParam)
            Case %SB_LINELEFT
              si.nPos=si.nPos- Arrow_Moves 'hs
            Case %SB_PAGELEFT
    '          si.nPos=si.nPos=si.nPage '<<< Error
              si.nPos=si.nPos - White_Space_Moves
            Case %SB_LINERIGHT
              si.nPos=si.nPos+ Arrow_Moves 'hs
            Case %SB_PAGERIGHT
              si.nPos=si.nPos+  White_Space_Moves'si.nPage
            Case %SB_THUMBTRACK
              si.nPos=HiWrd(CbWParam)
            Case Else
              Exit Function
          End Select
          si.nPos=Max&(si.nMin, Min&(si.nPos, si.nMax-si.nPage))
          si.fMask=%SIF_POS
          SetScrollInfo CbHndl,%SB_HORZ,si,1
          ScrollWindow CbHndl, oldPos-si.nPos,0,ByVal %Null, ByVal %Null
          Dialog Set Text CB.Hndl, Using$("Horizontal #, ", si.nPos)
          Function = 1
        Case %WM_VSCROLL
          si.cbSize=SizeOf(si)
          si.fMask=%SIF_ALL
          GetScrollInfo CbHndl, %SB_VERT, si
          oldPos=si.nPos
          Select Case LoWrd(CbWParam)
            Case %SB_LINEUP
              si.nPos=si.nPos- Arrow_Moves
            Case %SB_PAGEUP
              si.nPos=si.nPos- White_Space_Moves'si.nPage
            Case %SB_LINEDOWN
              si.nPos=si.nPos+ Arrow_Moves
            Case %SB_PAGEDOWN
              si.nPos=si.nPos+ White_Space_Moves'si.nPage
            Case %SB_THUMBTRACK
              si.nPos=HiWrd(CbWParam)
            Case Else
              Exit Function
          End Select
          si.nPos=Max&(si.nMin, Min&(si.nPos, si.nMax-si.nPage+1))
          si.fMask=%SIF_POS
          SetScrollInfo CbHndl, %SB_VERT, si, 1
          ScrollWindow CbHndl,0, oldPos-si.nPos,ByVal %Null, ByVal %Null
          Dialog Set Text CB.Hndl, Using$("Vertical #, ", si.nPos)
          Function = 1
          
      End Select
    End Function
    '--------------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------------
    '   ** Dialogs **
    '--------------------------------------------------------------------------------------------------
    Function ShowDIALOG1(ByVal hParent As Dword) As Long
      Local lRslt As Long
      Local hDlg  As Dword
      Local stile, stile_ex As Long
      Local n As String 
      
      n$ = " 1234567890"
      g_dlg_wd = 300' 283
      g_dlg_ht = 300 '359     
    '  
     ' 
    '  stile = %WS_POPUP 
      stile = stile Or %WS_BORDER
    '  stile = stile Or %WS_DLGFRAME
      stile = stile Or %WS_SYSMENU
      stile = stile Or %WS_MINIMIZEBOX
      stile = stile Or %WS_MAXIMIZEBOX
    '  stile = stile Or %WS_CLIPSIBLINGS
    '  stile = stile Or %WS_VSCROLL 'not needed as PB automatically adds it if needed
    '  stile = stile Or %WS_VISIBLE
    '  stile = stile Or %DS_MODALFRAME
    '  stile = stile Or %DS_3DLOOK
    '  stile = stile Or %DS_NOFAILCREATE
    '  stile = stile Or %DS_SETFONT
    '
    ' stile_ex = %WS_EX_CONTROLPARENT 
    ' stile_ex = stile_ex Or %WS_EX_RIGHTSCROLLBAR
    ' stile_ex = stile_ex Or %WS_EX_LEFT
    ' stile_ex = stile_ex Or %WS_EX_LTRREADING
    '
      Dialog New Pixels, hParent, "SCROLLER", , , g_dlg_wd, g_dlg_ht, Stile, Stile_ex, To hDlg
      Stile = %SS_Right
      Control Add Label,  hDlg, %IDC_LABEL1, "5 , 5 Label1" & n$, 5, 5, 100, 30, stile
      Control Add Label,  hDlg, %IDC_LABEL2, "510, 260  - 510 LEFT" & n$, 510, 260, 100, 30, stile
      Control Add Label,  hDlg, %IDC_LABEL3, "10, 405  -  405 BOTTOM" & n$, 10, 405, 100, 30, stile
      Control Add Button, hDlg, %IDC_HELPME, "475, 130 HELP", 475, 130, 200, 35
    '  
      g_dlg_Widest_Control = 510 'Label2 
      g_dlg_Deepest_Control = 405 'Label3 
    '
      Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
    '
      Function = lRslt
    End Function
    '--------------------------------------------------------------------------------------------------

    Leave a comment:


  • Marc Giao
    replied
    Hi Fred,

    Here's my DDT working effort, maybe it'll help:

    Code:
    	CASE %WM_VSCROLL ' vertical scrollbar has been used
    		SCROLLBAR GET PAGESIZE CB.HNDL, %VerSB TO S&
    		SCROLLBAR GET RANGE CB.HNDL, %VerSB TO L&, H&
    
    		SELECT CASE CB.CTL
    '			CASE %SB_THUMBPOSITION
    '			SCROLLBAR GET TRACKPOS CB.HNDL, %VerSB TO P&
    '			SCROLLBAR SET POS CB.HNDL, %VerSB, P&
    
    			CASE %SB_THUMBTRACK
    			SCROLLBAR GET TRACKPOS CB.HNDL, %VerSB TO P&
    			SCROLLBAR SET POS CB.HNDL, %VerSB, P&
    
    			CASE %SB_LINEDOWN
    			SCROLLBAR GET POS CB.HNDL, %VerSB TO P&
    			P& += D& ': P& = MIN&( H&, P& ) 'stay in range
    			SCROLLBAR SET POS CB.HNDL, %VerSB, P&
    
    			CASE %SB_LINEUP
    			SCROLLBAR GET POS CB.HNDL, %VerSB TO P&
    			P& -= D& ': P& = MAX&( L&, P& ) 'stay in range
    			SCROLLBAR SET POS CB.HNDL, %VerSB, P&
    
    			CASE %SB_PAGEDOWN
    			SCROLLBAR GET POS CB.HNDL, %VerSB TO P&
    			P& += S& ': P& = MIN&( H&, P& ) 'stay in range
    			SCROLLBAR SET POS CB.HNDL, %VerSB, P&
    
    			CASE %SB_PAGEUP
    			SCROLLBAR GET POS CB.HNDL, %VerSB TO P&
    			P& -= S& ': P& = MAX&( L&, P& ) 'stay in range
    			SCROLLBAR SET POS CB.HNDL, %VerSB, P&
    
    			CASE %SB_BOTTOM
    			SCROLLBAR SET POS CB.HNDL, %VerSB, H&
    
    			CASE %SB_TOP
    			SCROLLBAR SET POS CB.HNDL, %VerSB, L&
    	
    			CASE ELSE
    				EXIT FUNCTION
    		END SELECT
    The rest of the effort is here :

    http://www.powerbasic.com/support/pb...ad.php?t=40344

    Leave a comment:


  • Fred Buffington
    replied
    I have a small problem in my DDT scrollbar.

    the Graphic window displays correctly and the linedown/page down etc make the display correctly but the scrollbar sets the position to the correct point
    and displays it for a split second and
    then immediately goes back to the top making it appear that no scrolling has taken place.

    Written in pbwin8
    The control ID is %IDC_Scrollbar1
    It's a vertical control
    A portion of the callback:
    Code:
        CASE %WM_VSCROLL
          si.cbSize=SIZEOF(si)
          si.fMask=%SIF_ALL
         
         CONTROL HANDLE hDlgPreview, %IDC_SCROLLBAR1 TO hCtrl&
         GetScrollInfo hCtrl&, SFlag&, Si
         IF Offset!=0 THEN Offset!=32
         SELECT CASE LOWRD(CBWPARAM) 'wParam&)
              CASE %SB_LINEDOWN       ' sames as %SB_LINERIGHT
    '               Si.nPos=Si.nPos+12 '1
                   TopLine!=TopLine!+3
                   BottomLine!=BottomLine!+3
    
                   IF TopLine!+offSet!>65 THEN
                     TopLine!=65-Offset!+1
                     BottomLine!=65
                   END IF
                   BottomLine!=TopLine!+Offset!
                   Si.npos=TopLine!*4
                   IF TopLine!>=Offset! AND Offset!<>0 THEN downit&=1
                   IF downit& THEN
                     CONTROL KILL hDlgPreview,305
                     IF numcolors>8 THEN
                       CONTROL ADD  IMGBUTTONX,hDlgPreview,305,"PU1",188*xoffset!,02,45*xoffset!,16*yoffset!
                     ELSE
                       CONTROL ADD  BUTTON,hDlgPreview,305,"Page Up",188*xoffset!,02,45*xoffset!,16*yoffset!
                     END IF
                   END IF
    ''msgbox "topline!="+str$(topline!)+"  "+"Bottomline!="+STR$(bottomline!)
              CASE %SB_LINEUP         ' sames as %SB_LINELEFT
    '               Si.nPos=Si.nPos-12
                   TopLine!=TopLine!-3
                   IF TopLine!<0 THEN TopLine!=0
                   BottomLine!=TopLine!+Offset!
                   Si.nPos=TopLine!*4
                   IF BottomLine!<=Offset! THEN Downit&=0
                   IF downit&=0 THEN
                     CONTROL KILL hDlgPreview,305
                     IF numcolors>8 THEN
                       CONTROL ADD  IMGBUTTONX,hDlgPreview,305,"PD1",188*xoffset!,02,45*xoffset!,16*yoffset!
                     ELSE
                       CONTROL ADD  BUTTON,hDlgPreview,305,"Page Down",188*xoffset!,02,45*xoffset!,16*yoffset!
                     END IF
                   END IF
              CASE %SB_PAGEDOWN       ' sames as %SB_PAGERIGHT
                   Si.nPos=Si.nPos+135 'Si.nPage
                   TopLine!=Offset!
    '
                   BottomLine!=65
    
                   IF downit&=0 THEN
                     downit&=1
                     CONTROL KILL hDlgPreview,305
                     IF numcolors>8 THEN
                       CONTROL ADD  IMGBUTTONX,hDlgPreview,305,"PU1",188*xoffset!,02,45*xoffset!,16*yoffset!
                     ELSE
                       CONTROL ADD  BUTTON,hDlgPreview,305,"Page Up",188*xoffset!,02,45*xoffset!,16*yoffset!
                     END IF
                   END IF
    
              CASE %SB_PAGEUP         ' sames as %SB_PAGELEFT
                   'TopLine!=TopLine!-12
                   'if TopLine!<0 then TopLine!=0
                   'Si.nPos=TopLine!*4 'Si.nPos-Si.nPage
                   TopLine!=0
                   BottomLine!=Offset!
                   Si.nPos=0
              CASE %SB_THUMBPOSITION
                   Si.nPos=Si.nTrackPos    'SP&
              CASE %SB_THUMBTRACK
                   Si.nPos=Si.nTrackPos    'SP&
         END SELECT
         SetScrollInfo hCtrl&, %SB_CTL, si, %TRUE
         lResult&=previewit(coid$,pagespreviewed&) 'read from file
         EXIT FUNCTION
    The previewit reads the information from a file and prints it on the Graphic
    with the Graphic statements.

    I have a Page Down/Page Up button that either shows the bottom half of the page or the top half of the page and it works fine with the scroll bar either being at the top or bottom.

    **posted later***
    Figured out the problem
    It was in the GetScrollinfo statement
    Code:
    changed
         GetScrollInfo hCtrl&, SFlag&, Si
    to
         GetScrollInfo hCtrl&, %SB_CTL, si
    and it works fine now
    Last edited by Fred Buffington; 27 May 2009, 07:04 PM.

    Leave a comment:


  • Scott Turchin
    replied
    Yikes, I think I see some IF/THEN statements....

    This is my challenge, works on page down and scroll down but only goes back to 10....can't divide by zero so I'll be putting my thinking cap on tod ay.

    I haven't learned the last item we discussed about the handle just yet....time is tight lately

    Code:
         Case %WM_VSCROLL
             SB.cbSize=SizeOf(SB)
             SB.fMask=%SIF_ALL
             GetScrollInfo g_hScroll, %SB_CTL, SB
             Select Case LoWrd(CbWParam)
                 Case %SB_LINEDOWN,%SB_PAGEDOWN
                     If LoWrd(CbWParam) = %SB_PAGEDOWN Then SB.nPos=SB.nPos+SB.nPage
    
                     If SB.nPos = 9 Then Exit Function
                     Control Set Text CbHndl, %DEBUG,"SB.nPos: " & Format$(SB.nPos)
                     For lLoop = 1 To 10 'Change variables on the page
                         sTmp = "Command " & Format$(SB.nPos * 10 + lLoop)
                         Control Set Text CbHndl, %COMMANDLABEL0 + lLoop,sTmp
                         sTmp = Commands(SB.nPos * 10 + lLoop)
                         Control Set Text CbHndl, %COMMAND0 + lLoop,sTmp
                     Next
                     Incr SB.nPos  'INCREMENT AFTER otherwise it skips 10-20
    
                 Case %SB_LINEUP,%SB_PAGEUP
                     If LoWrd(CbWParam) = %SB_PAGEUP Then SB.nPos=SB.nPos-SB.nPage 'page value is 10
                     Decr SB.nPos  'DECREMENT AFTER otherwise it skips 10-20
                     Control Set Text CbHndl, %DEBUG,"SB.nPos: " & Format$(SB.nPos)
                     For lLoop = 1 To 10 'Change variables on the page
                         sTmp = "Command " & Format$(SB.nPos * 10 + lLoop)
                         Control Set Text CbHndl, %COMMANDLABEL0 + lLoop,sTmp
                         sTmp = Commands(SB.nPos * 10 + lLoop)
                         Control Set Text CbHndl, %COMMAND0 + lLoop,sTmp
                     Next
    
                 Case %SB_THUMBPOSITION
                     SB.nPos=SB.nTrackPos
                 Case %SB_THUMBTRACK
                     SB.nPos=SB.nTrackPos
                 Case Else
                     Exit Function
             End Select
             SetScrollInfo g_hScroll,ByVal %SB_CTL, SB, %TRUE

    Leave a comment:


  • Michael Mattias
    replied
    >OK NOW it's finally working

    I will make a guess that having to look up all that info to make it so, you are not likely to forget how you got it working.

    >just need to get my math correct ...appropriately for each page

    I'll trade you "lining up stuff on the page" tasks even up.

    I finally got the final specs on that invoice application. Now all I have to do is figure out where to break pages given ..

    - I have four (4) possible vertical inch values in which to print line items: First page which is last page; first page which is not last page; non-first last page; and non-first, non-last page.
    - Each line item requires a variable number of vertical inches (number of print lines).

    Deal?

    (Forgot: I don't want to break multiple-printline line items across a page, either)
    Last edited by Michael Mattias; 6 Aug 2008, 09:27 AM.

    Leave a comment:


  • Scott Turchin
    replied
    OK NOW it's finally working! Thanks!

    It wasn't moving the scroller last time, and on top of that I had left the same code in there from another section, thought I had removed it.

    So now I just need to get my math correct on my text and label's so that they rename appropriately for ea ch page I am on - no easy feat but I'll figure it out...

    Byval is gone, thanks!

    Leave a comment:


  • Michael Mattias
    replied
    >OK Mike ya got me, what are the answers for parameter 2 then????

    !!!

    Check your WinAPI doc for WM_HSCROLL, WM_VSCROLL, GetScrollInfo and SetScrollInfo.

    And while you're at it, check the doc under CONTROL ADD SCROLLBAR in your compiler help file. It even tells you explicitly there to be careful to avoid making the mistake of using SB_VERT or SB_HORZ!!

    (Now that we know this is DDT rather than SDK style I can point you there).

    In fairness... there is some bad inconsistency on that help file page as well. First, the syntax for CONTROL ADD SCROLLBAR allows you to enter a "txt$" parameter, although that text is never shown (cleverly explained away in the text of the help, however) ; second, it supports a CALLBACK option allowing you to have a control-level callback function WHICH CAN NEVER BE CALLED. (Surprise!).

    MCM

    Leave a comment:


  • Scott Turchin
    replied
    Originally posted by Michael Mattias View Post
    >SetScrollInfo ByVal VarPtr(g_hScroll) ,%SB_VERT, SB, %TRUE

    Time to re-

    When GetScrollInfo and SetScrollInfo are used for a standalone control, what is the correct value to use for parameter two? (Hint: it is not %SB_VERT!)

    And BYVAL VARPTR(g_hScroll) is not correct. That handle should be passed by value, not by reference ("BYVAL VARPTR()" = "BYREF")

    (FWIW, you do not need to save that handle in a global variable. It comes as lparam on every WM_SCROLL notification from a standalone scrollbar control)

    MCM
    OK Mike ya got me, what are the answers for parameter 2 then????

    Did not know about lparam but that would be easier to work with so I will change and test!

    Tx!

    Leave a comment:


  • Scott Turchin
    replied
    DId not know that!
    I'll see if I can test that here today, odds are it will be a few days - I will be back though!! Company flying in....ugh...

    Leave a comment:


  • Michael Mattias
    replied
    >SetScrollInfo ByVal VarPtr(g_hScroll) ,%SB_VERT, SB, %TRUE

    Time to re-

    When GetScrollInfo and SetScrollInfo are used for a standalone control, what is the correct value to use for parameter two? (Hint: it is not %SB_VERT!)

    And BYVAL VARPTR(g_hScroll) is not correct. That handle should be passed by value, not by reference ("BYVAL VARPTR()" = "BYREF")

    (FWIW, you do not need to save that handle in a global variable. It comes as lparam on every WM_SCROLL notification from a standalone scrollbar control)

    MCM
    Last edited by Michael Mattias; 4 Aug 2008, 07:17 PM.

    Leave a comment:


  • Scott Turchin
    replied
    This works almost flawlessly....debug time 2nite..

    Code:
    %IDVSCROLL          = %WM_USER + 208
    
    Winmain:
    Control Add ScrollBar, g_hDlg,%IDVSCROLL,"",410,150,10,60
    
    DialogProc:
    
    Local  SB               As SCROLLINFO
    Static PageNo           As Long
    Local  cStart           As Long
    Local  cStop            As Long
    
    Select Case CbMsg
        Case %WM_INITDIALOG
            Control Handle CbHndl, %IDVSCROLL To g_hScroll
            SB.cbSize=SizeOf(SB)
            SB.fMask=%SIF_ALL
            SB.nMin=0
            SB.nMax=100
            SB.nPage=10
            SB.nPos=10
            SB.nTrackPos=10
            SetScrollInfo ByVal VarPtr(g_hScroll) ,%SB_VERT, SB, %TRUE
            PageNo = 1
    
         Case %WM_VSCROLL
             SB.cbSize=SizeOf(SB)
             SB.fMask=%SIF_ALL
             GetScrollInfo ByVal VarPtr(g_hScroll), %SB_VERT, SB
             Select Case LoWrd(CbWParam)
    
                 Case %SB_LINEDOWN
                     SB.nPos=SB.nPos + 1
                     If PageNo = 10 Then  'Can't go past page 10
                         Exit Function
                     Else
                         Incr PageNo
                         cStart = PageNo * 10
                         cStop = (PageNo * 10) + 10
    '                     MsgBox "cStart: " & Format$(cStart) & $CrLf & "cStop: " & Format$(cStop)
                         For lLoop = cStart To cStop 'Change variables on the page
                             Incr lCount
                             sTmp = "Command " & Format$(lLoop)
                             Control Set Text CbHndl, %COMMANDLABEL0 + lCount,sTmp
                             sTmp = Commands(lLoop)
                             Control Set Text CbHndl, %COMMAND0 + lCount,sTmp
                         Next
                    End If
    
                 Case %SB_LINEUP
                     SB.nPos=SB.nPos - 1
                     If PageNo = 1 Then
                         Exit Function
                     Else
                         Decr PageNo
                         cStart = PageNo * 10
                         cStop = (PageNo * 10) + 10
    '                     MsgBox "cStart: " & Format$(cStart) & $CrLf & "cStop: " & Format$(cStop)
                         For lLoop = cStart To cStop
                             Incr lCount
                             sTmp = "Command " & Format$(lLoop)
                             Control Set Text CbHndl, %COMMANDLABEL0 + lCount,sTmp
                             sTmp = Commands(lLoop)
                             Control Set Text CbHndl, %COMMAND0 + lCount,sTmp
                         Next
                     End If
    
                 Case %SB_PAGEDOWN
                     SB.nPos=SB.nPos+SB.nPage
                     If PageNo = 10 Then  'Can't go past page 10
                         Exit Function
                     Else
                         Incr PageNo
                         cStart = PageNo * 10
                         cStop = (PageNo * 10) + 10
    '                     MsgBox "cStart: " & Format$(cStart) & $CrLf & "cStop: " & Format$(cStop)
                         For lLoop = cStart To cStop 'Change variables on the page
                             Incr lCount
                             sTmp = "Command " & Format$(lLoop)
                             Control Set Text CbHndl, %COMMANDLABEL0 + lCount,sTmp
                             sTmp = Commands(lLoop)
                             Control Set Text CbHndl, %COMMAND0 + lCount,sTmp
                         Next
                    End If
    
                 Case %SB_PAGEUP
                     SB.nPos=SB.nPos-SB.nPage
                     SB.nPos=SB.nPos - 1
                     If PageNo = 1 Then
                         Exit Function
                     Else
                         Decr PageNo
                         cStart = PageNo * 10
                         cStop = (PageNo * 10) + 10
                         MsgBox "cStart: " & Format$(cStart) & $CrLf & "cStop: " & Format$(cStop)
                         For lLoop = cStart To cStop
                             Incr lCount
                             sTmp = "Command " & Format$(lLoop)
                             Control Set Text CbHndl, %COMMANDLABEL0 + lCount,sTmp
                             sTmp = Commands(lLoop)
                             Control Set Text CbHndl, %COMMAND0 + lCount,sTmp
                         Next
                     End If
                 Case %SB_THUMBPOSITION
                     SB.nPos=SB.nTrackPos
                 Case %SB_THUMBTRACK
                     SB.nPos=SB.nTrackPos
                 Case Else
                     Exit Function
             End Select
             SetScrollInfo ByVal VarPtr(g_hScroll),ByVal %SB_VERT, SB, %TRUE

    Leave a comment:


  • Scott Turchin
    replied
    Ya can do, except it appears I have resolved that issue.......

    The handle to the scrollbar must be passed byval or it acts WEIRD....

    SetScrollInfo byval varptr(scrollhandle) etc etc....

    Tx!

    Leave a comment:


  • Michael Mattias
    replied
    >wish I could take a picture and send you

    Well, next best thing - actually a better thing when you think about it - make up a little one-screen demo program.

    I assume what we don't see in code posted so far is when you get WM_VSCROLL, you scroll some other control containing text and/or pictures.

    And, if the user uses he keyboard to scroll in that other control, you want to reset the external scrollbar so the thumb stays about where it belongs relative to "how far down the list" the user has scrolled.

    Surely you can cut and paste a few pieces from what you've got and post it here for others to play with?

    MCM

    Leave a comment:


  • Scott Turchin
    replied
    I did a Control Handle cbhndl, %IDVSCROLL to hScrollCtl but forgot to paste it.

    THe weird part is, and I wish I could take a picture and send you, AFTER I do the SetScroll, the scrollbar gets thinner and looks like a second one underneath it, UNLESS I do that byval stuff and even then it only works once and goes back to it again....

    Leave a comment:


  • Michael Mattias
    replied
    > [on WM_INITDIALOG]
    > SetScrollInfo ByVal hScrollCtl,ByVal %SB_VERT, SB, %TRUE

    Value of hScrollCtl was not set prior to this call in WM_INITDIALOG.

    When SetScrollInfo is called later after adjustment, SB values must be adjusted based in the settings used in SetScrollinfo... i.e. you must adjust your 'scroll position' based in the current page and position within the page. i.e, it is unlikely SB_LINEDOWN will correspond to exactly one "scroll unit" as set with SetScrollInfo, even if you had properly called SetScrollInfo with a valid control handle on WM_INITDIALOG.

    But it looks like you are getting closer.

    Leave a comment:


  • Scott Turchin
    replied
    Using my code above I REM'd out the initial SETSCROLLINFO and amazing enough the scrollbar "Looks" normal now, not like a shadow on another one.
    But as soon as I click it and do the SETSCROLLINFO it takes on that form and stops functioning....I think I"mdoing it correctly but I have a conflict of some kind...

    Leave a comment:


  • Michael Mattias
    replied
    Code:
          GetScrollInfo CBHNDL, %SB_VERT, si
    This gets scroll info for the scrollbar which is part of the dialog, not a child scrollbar control, which is what this question is about.

    See your documentation for more details.

    Leave a comment:


  • Rodney Hicks
    replied
    This I found in the forums, but I don't know who put it there, it does a good job with scrollbars and easy to understand, adapt, and adopt.
    Code:
    #PBFORMS CREATED V1.51
    '--------------------------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '--------------------------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    '--------------------------------------------------------------------------------------------------
    '   ** Includes **
    '--------------------------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES 
    #IF NOT %DEF(%WINAPI)
      #INCLUDE "WIN32API.INC"
    #ENDIF
    #PBFORMS END INCLUDES
    '--------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------
    '   ** Constants **
    '--------------------------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS 
    %IDD_DIALOG1 =  101
    %IDC_LABEL1  = 1001
    %IDC_LABEL2  = 1002
    %IDC_LABEL3  = 1003
    %IDC_HELPME  = 1004
    #PBFORMS END CONSTANTS
    '--------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------
    '   ** Declarations **
    '--------------------------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '--------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '--------------------------------------------------------------------------------------------------
    FUNCTION PBMAIN()
      ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '--------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------
    '   ** CallBacks **
    '--------------------------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
      LOCAL w AS LONG, h AS LONG, oldPos AS LONG, si AS SCROLLINFO
      LOCAL vt AS LONG, ht AS LONG, hs AS LONG, vs AS LONG
      w=600
      h=400
      vt=50
      ht=50
      hs=5
      vs=5
      SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG
          ' Initialization handler
          si.cbSize=LEN(si)
          si.fMask=%SIF_ALL
          si.nMin=0
          si.nMax=h
          si.nPage=vt
          SetScrollInfo CBHNDL, %SB_VERT, si, 1
          si.nMin=0
          si.nMax=w
          si.nPage=ht
          si.nPos=0
          SetScrollInfo CBHNDL, %SB_HORZ, si, 1
    
        CASE %WM_NCACTIVATE
          STATIC hWndSaveFocus AS DWORD
          IF ISFALSE CBWPARAM THEN
            ' Save control focus
            hWndSaveFocus = GetFocus()
          ELSEIF hWndSaveFocus THEN
            ' Restore control focus
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          END IF
    
        CASE %WM_COMMAND
          ' Process control notifications
          SELECT CASE AS LONG CBCTL
            CASE %IDC_LABEL1
    
            CASE %IDC_LABEL2
    
            CASE %IDC_LABEL3
    
          END SELECT
        CASE %WM_HSCROLL
          si.cbSize=SIZEOF(si)
          si.fMask=%SIF_ALL
          GetScrollInfo CBHNDL, %SB_HORZ, si
          oldPos=si.nPos
          SELECT CASE LOWRD(CBWPARAM)
            CASE %SB_LINELEFT
              si.nPos=si.nPos-hs
            CASE %SB_PAGELEFT
              si.nPos=si.nPos=si.nPage
            CASE %SB_LINERIGHT
              si.nPos=si.nPos+hs
            CASE %SB_PAGERIGHT
              si.nPos=si.nPos+si.nPage
            CASE %SB_THUMBTRACK
              si.nPos=HIWRD(CBWPARAM)
            CASE ELSE
              EXIT FUNCTION
          END SELECT
          si.nPos=MAX&(si.nMin, MIN&(si.nPos, si.nMax-si.nPage))
          si.fMask=%SIF_POS
          SetScrollInfo CBHNDL,%SB_HORZ,si,1
          ScrollWindow CBHNDL, oldPos-si.nPos,0,BYVAL %NULL, BYVAL %NULL
          FUNCTION = 1
    
        CASE %WM_VSCROLL
          si.cbSize=SIZEOF(si)
          si.fMask=%SIF_ALL
          GetScrollInfo CBHNDL, %SB_VERT, si
          oldPos=si.nPos
          SELECT CASE LOWRD(CBWPARAM)
            CASE %SB_LINEUP
              si.nPos=si.nPos-vs
            CASE %SB_PAGEUP
              si.nPos=si.nPos-si.nPage
            CASE %SB_LINEDOWN
              si.nPos=si.nPos+vs
            CASE %SB_PAGEDOWN
              si.nPos=si.nPos+si.nPage
            CASE %SB_THUMBTRACK
              si.nPos=HIWRD(CBWPARAM)
            CASE ELSE
              EXIT FUNCTION
          END SELECT
          si.nPos=MAX&(si.nMin, MIN&(si.nPos, si.nMax-si.nPage+1))
          si.fMask=%SIF_POS
          SetScrollInfo CBHNDL, %SB_VERT, si, 1
          ScrollWindow CBHNDL,0, oldPos-si.nPos,BYVAL %NULL, BYVAL %NULL
          FUNCTION = 1
      END SELECT
    END FUNCTION
    '--------------------------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------------------------------------
    '   ** Dialogs **
    '--------------------------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
      LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
      LOCAL hDlg  AS DWORD
    
      DIALOG NEW hParent, "SCROLLER", 359, 88, 283, 359, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR _
        %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VSCROLL OR _
        %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
        %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
      CONTROL ADD LABEL,  hDlg, %IDC_LABEL1, "Label1", 5, 5, 100, 10
      CONTROL ADD LABEL,  hDlg, %IDC_LABEL2, "510 LEFT", 510, 260, 100, 10
      CONTROL ADD LABEL,  hDlg, %IDC_LABEL3, "405BOTTOM", 10, 305, 100, 10
      CONTROL ADD BUTTON, hDlg, %IDC_HELPME, "HELP", 475, 130, 50, 15
    #PBFORMS END DIALOG
    
      DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
    
      FUNCTION = lRslt
    END FUNCTION
    '--------------------------------------------------------------------------------------------------
    Last edited by Rodney Hicks; 3 Aug 2008, 05:36 PM. Reason: add info

    Leave a comment:


  • Michael Mattias
    replied
    What doc?

    Whatever you use for your Windows API documentation,that's what doc.

    Ain't got nuttin' local? Start here: http://msdn.microsoft.com/en-us/default.aspx

    Leave a comment:


  • Scott Turchin
    replied
    What doc?

    Leave a comment:

Working...
X