Announcement

Collapse
No announcement yet.

GetScrollInfo

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

    GetScrollInfo

    Hi, guys --
    Noticed one strange moment (at least, under Win2000).
    I expected that GetScrollInfo should return 0, if there is no scroll bar.
    But it retrieves something.
    I can find workaround, because I enable/disable scroll bars by myself, but maybe you know reliable way to determine, whether scroll bar exist ?

    BTW, situation is following.
    I set ScrollInfo. When I see that scroll bar is not neccessary I do ShowScrollBar %False.
    Looks, like it's necessary to do SetScrollInfo with zeroes also.

    ------------------
    E-MAIL: [email protected]

    [This message has been edited by Semen Matusovski (edited October 23, 2001).]

    #2
    Maybe can use GetClientRect? With/without scrollbar - different rects.


    ------------------

    Comment


      #3
      Have you tried testing the window style for WS_HSCROLL and/or WS_VSCROLL?
      If you try to make something idiot-proof, someone will invent a better idiot.

      Comment


        #4
        Semen--

        Quick question, are you using a normal window, or one of the predefined controls?

        --Jules


        ------------------

        Comment


          #5
          A control can have WS_VSCROLL/WS_HSCROLL style but not show scrollbar.
          In empty control, can grab "clean" client rect in static RECT for
          later compare in WM_SIZE.

          Then again, filling SetScrollInfo with zeroes on hide looks like a
          better/faster/prettier way to me..


          ------------------

          Comment


            #6
            Guys --
            In certain situation (my custom control by itself decides to turn on or off scroll bars) I found simple workaround - decided to keep SCROLLINFO instead of retrieving it.
            Just now I mostly worry about external windows, because somehow I wrote a fragment, which simply tests return code of GetScrollInfo.

            I agree with Borje about styles - at least for my control it's not important.
            To use GetClientRect is reliable, but will be flickers, because this method means that it's neccessary to do ShowScrollBar %FALSE, and if client area was changed, to mark "there is scroll bar" and to turn it on.

            Maybe something else return status of scroll bar ?

            ------------------
            E-MAIL: [email protected]

            Comment


              #7
              Thats exactly what I do too... I track my own scroll positions, etc, and just set the control according to the %WM_xSCROLL message type (line up/down, page up/down, etc).

              I find it much easier than reading the info and trying to correlate it back to the desired position.


              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment


                #8
                Without storing anything, or causing flicker - tested and works with
                ClientEdge on/off..
                Code:
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                ' Check if a control's scrollbars are shown.
                ' Returns zero if none, 1 if vertical, 2 if horizontal and 3 if both.
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                FUNCTION ScrollShown(BYVAL hWnd AS LONG) AS LONG
                  LOCAL lRes AS LONG, rc AS RECT, rc2 AS RECT
                 
                  GetWindowRect hWnd, rc
                  GetClientRect hWnd, rc2
                 
                  IF rc2.nRight <= rc.nRight - rc.nLeft - GetSystemMetrics(%SM_CXVSCROLL) THEN lRes = 1
                  IF rc2.nBottom <= rc.nBottom - rc.nTop - GetSystemMetrics(%SM_CXHSCROLL) THEN lRes = lRes + 2
                  FUNCTION = lRes
                END FUNCTION

                ------------------

                Comment


                  #9
                  Borje -
                  What about windows with caption / menu ?
                  I agree that it's possible anyway (to test styles, is menu present), but strange that API doesn't offer direct way.

                  [This message has been edited by Semen Matusovski (edited October 24, 2001).]

                  Comment


                    #10
                    Borje's code states "control" rather than "dialog" or "window", so I gather he is just demonstrating a general concept.

                    ------------------
                    Lance
                    PowerBASIC Support
                    mailto:[email protected][email protected]</A>
                    Lance
                    mailto:[email protected]

                    Comment


                      #11
                      Yes, controls only there. Agree - strange that there is no way to find
                      this out easily. Hm, looked at messages. WM_WINDOWPOSCHANGED, WM_NCCALCSIZE
                      and WM_SIZE are triggered when scrollbars are added. Guess WM_SIZE is good
                      checkpoint.

                      But, also looked at styles. Looks like Matthew is right. WS_VSCROLL and
                      WS_HSCROLL style seems to depends on if any of those scrollbars are visible.
                      So following actually seems to work (only tested with list and edit control)
                      Code:
                      '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                      ' Check if a control's scrollbars are shown.
                      ' Returns zero if none, 1 if vertical, 2 if horizontal and 3 if both.
                      '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                      FUNCTION ScrollShown(BYVAL hWnd AS LONG) AS LONG
                        LOCAL lRes AS LONG
                       
                        IF (GetWindowLong(hWnd, %GWL_STYLE) AND %WS_VSCROLL) THEN lRes = 1
                        IF (GetWindowLong(hWnd, %GWL_STYLE) AND %WS_HSCROLL) THEN lRes = lRes + 2
                       
                        FUNCTION = lRes
                      END FUNCTION
                      ------------------
                      Did a quick test in MDI app's client area and moved pads in/out to force
                      scrollbars on/off - worked fine! Think Matthew is right..


                      [This message has been edited by Borje Hagsten (edited October 24, 2001).]

                      Comment


                        #12
                        I also tested (under Win2000).

                        Code:
                           #Compile Exe
                           #Register None
                           #Dim All
                           #Include "win32api.inc"
                        
                           Sub ScrollTest (hWnd As Long)
                               Local w As Asciiz * 20
                        
                               If (GetWindowLong(hWnd, %GWL_STYLE) And %WS_VSCROLL) Then w$ = "VSCROLL"
                               If (GetWindowLong(hWnd, %GWL_STYLE) And %WS_HSCROLL) Then w$ = Trim$(w$ + " HSCROLL")
                               SetWindowText hWnd, w
                               
                            End Sub
                        
                           CallBack Function ShowHScroll: ShowScrollBar CbHndl, %SB_HORZ, 1: ScrollTest CbHndl: End Function
                           CallBack Function ShowVScroll: ShowScrollBar CbHndl, %SB_VERT, 1: ScrollTest CbHndl: End Function
                           CallBack Function HideHScroll: ShowScrollBar CbHndl, %SB_HORZ, 0: ScrollTest CbHndl: End Function
                           CallBack Function HideVScroll: ShowScrollBar CbHndl, %SB_VERT, 0: ScrollTest CbHndl: End Function
                        
                                                        
                            Function PbMain
                               Local hDlg  As Long
                               Dialog New hDlg, "Test", , ,  120, 150, %WS_OVERLAPPEDWINDOW To hDlg
                               Control Add Button, hDlg, 101,  "Show HScroll", 10, 10, 80, 12 Call ShowHScroll
                               Control Add Button, hDlg, 102,  "Show VScroll", 10, 30, 80, 12 Call ShowVScroll
                               Control Add Button, hDlg, 103,  "Hide HScroll", 10, 50, 80, 12 Call HideHScroll
                               Control Add Button, hDlg, 104,  "Hide VScroll", 10, 70, 80, 12 Call HideVScroll
                               Dialog Show Modal hDlg
                            End Function
                        If Windows actually resets styles in all OSes this way looks normal


                        ------------------
                        E-MAIL: [email protected]

                        Comment


                          #13
                          You mean - trust MS? Hm - no comments..


                          ------------------

                          Comment


                            #14
                            Borje:
                            GetWindowLong(hWnd, GWL_STYLE) returns the current state of the window
                            so this behaviour is normal. See the following MSKB article.

                            Value Returned by GetWindowLong(hWnd, GWL_STYLE) Article ID: Q83366

                            ------------------
                            Dominic Mitchell
                            Dominic Mitchell
                            Phoenix Visual Designer
                            http://www.phnxthunder.com

                            Comment

                            Working...
                            X
                            😀
                            🥰
                            🤢
                            😎
                            😡
                            👍
                            👎