Results 1 to 6 of 6

Thread: Detect Listview Vertical Scrollbar [Resolved]

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Detect Listview Vertical Scrollbar [Resolved]

    I just want to determine if the listview has the vertical scrollbar or
    not. As I populate a lvw (report display) I want to shorten the
    width of the last columnheader if the lvw has enough items in it
    to invoke a vertical scrollbar to be displayed. I have searched and
    only found was of turning them on or off, but not detecting when
    they are added.

    Thanks in advance for any help.
    Last edited by RobDog888; May 22nd, 2004 at 02:29 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Ok, I have found this from M$, but I need it converted to VB.
    Code:
    typedef struct tagSCROLLBARINFO {
        DWORD cbSize;
        RECT rcScrollBar;
        int dxyLineButton;
        int xyThumbTop;
        int xyThumbBottom;
        int reserved;
        DWORD rgstate[CCHILDREN_SCROLLBAR+1];
    } SCROLLBARINFO, *PSCROLLBARINFO, *LPSCROLLBARINFO;
    VB API
    VB Code:
    1. Private Declare Function GetScrollBarInfo Lib "user32.dll" (ByVal hwnd As Long, _
    2. ByVal idObject As Long, ByRef psbi As PSCROLLBARINFO) As Long
    Or maybe subclass the lvw and trap for the WM_VSCROLL message. Or test somehow for the SBS_VERT scrollbar style???
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Dunno bout those API's, but I found these:

    Public Type SCROLLINFO
    cbSize As Long
    fMask As Long
    nMin As Long
    nMax As Long
    nPage As Long
    nPos As Long
    nTrackPos As Long
    End Type

    Public Declare Function GetScrollInfo Lib "user32" Alias "GetScrollInfo" (ByVal hWnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long

  4. #4

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    This is what I have been working on so far. Just trying to tell if
    the scrollbar is present or not. Not working though.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type SCROLLINFO
    4.     cbSize As Long
    5.     fMask As Long
    6.     nMin As Long
    7.     nMax As Long
    8.     nPage As Long
    9.     nPos As Long
    10.     nTrackPos As Long
    11. End Type
    12.  
    13. 'SCROLLBAR STYLE
    14. Private Const SBS_VERT As Long = &H1&
    15.  
    16. 'SCROLLBAR MESSAGE
    17. Private Const WM_VSCROLL As Long = &H115
    18.  
    19. 'SCROLLBAR CONST
    20. Private Const SB_VERT As Long = 1
    21.  
    22. 'Private Declare Function GetScrollBarInfo Lib "user32.dll" (ByVal hwnd As Long, ByVal idObject As Long, ByRef psbi As PSCROLLBARINFO) As Long
    23.  
    24. Private Declare Function GetScrollInfo Lib "user32.dll" (ByVal hWnd As Long, ByVal n As Long, ByRef lpScrollInfo As SCROLLINFO) As Long
    25.  
    26. Private Sub cmdAdd_Click()
    27.     ListView1.ListItems.Add , , "Test"
    28. End Sub
    29.  
    30. Private Sub cmdCheck_Click()
    31.    
    32.     Dim si As SCROLLINFO
    33.     Dim lRetVal As Long
    34.    
    35.     si.cbSize = Len(si)
    36.     si.fMask = SB_VERT
    37.     lRetVal = GetScrollInfo(ListView1.hWnd, ByVal SB_VERT, si)
    38.     If si.fMask = SB_VERT Then
    39.         MsgBox lRetVal & "-True"
    40.     Else
    41.         MsgBox lRetVal & "-False"
    42.     End If
    43. End Sub
    44.  
    45. Private Sub cmdRemove_Click()
    46.     ListView1.ListItems.Remove ListView1.ListItems.Count
    47. End Sub
    48.  
    49. Private Sub Form_Load()
    50.     ListView1.ColumnHeaders.Add , , "Test"
    51. End Sub
    Can you see where I may be going wrong?

    Thanks.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Thumbs up

    I finally got it! After researching at M$ I found that you can get
    the number of listitems that can be displayed in the lvw client
    area without a vertical scrollbar (.nPage of the SCROLLINFO
    structure). Then compare with the number of listitems and if more
    than .nPage then scrollbar must be visible.

    Complete example.
    VB Code:
    1. 'NEED 3 COMMANDBUTTONS AND 1 LISTVIEW
    2. Option Explicit
    3.  
    4. Private Type SCROLLINFO
    5.     cbSize As Long
    6.     fMask As Long
    7.     nMin As Long
    8.     nMax As Long
    9.     nPage As Long
    10.     nPos As Long
    11.     nTrackPos As Long
    12. End Type
    13.  
    14. 'SCROLLBAR STYLE
    15. 'Private Const SBS_HORZ As Long = &H0&
    16. 'Private Const SBS_VERT As Long = &H1&
    17.  
    18. 'SCROLLBAR MESSAGE
    19. 'Private Const WM_HSCROLL As Long = &H114
    20. 'Private Const WM_VSCROLL As Long = &H115
    21.  
    22. 'SCROLLBAR CONSTS
    23. Private Const SB_HORZ As Long = 0
    24. Private Const SB_VERT As Long = 1
    25. Private Const SB_CTL As Long = 2
    26. Private Const SB_BOTH As Long = 3
    27.  
    28. Private Const SIF_PAGE As Long = &H2
    29. Private Const SIF_POS As Long = &H4
    30. Private Const SIF_RANGE As Long = &H1
    31. Private Const SIF_TRACKPOS As Long = &H10 'FOR DETECTING WHEN USER CLICKS AND DRAGS THUMB CTL
    32. Private Const SIF_ALL As Long = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
    33.  
    34. Private Declare Function GetScrollInfo Lib "user32.dll" (ByVal hWnd As Long, ByVal n As Long, _
    35. ByRef lpScrollInfo As SCROLLINFO) As Long
    36.  
    37. Private Sub cmdAdd_Click()
    38.     ListView1.ListItems.Add , , "Test " & ListView1.ListItems.Count + 1
    39. End Sub
    40.  
    41. Private Sub cmdCheck_Click()
    42.    
    43.     Dim si As SCROLLINFO
    44.     Dim lRetVal As Long
    45.    
    46.     si.cbSize = Len(si)
    47.     si.fMask = SIF_PAGE
    48.     lRetVal = GetScrollInfo(ListView1.hWnd, ByVal SB_VERT, si)
    49.     If ListView1.ListItems.Count > si.nPage Then
    50.         MsgBox "Vertical ScrollBar Visible = True"
    51.     Else
    52.         MsgBox "Vertical ScrollBar Visible = False"
    53.     End If
    54.    
    55. End Sub
    56.  
    57. Private Sub cmdRemove_Click()
    58.     If ListView1.ListItems.Count = 0 Then Exit Sub
    59.     ListView1.ListItems.Remove ListView1.ListItems.Count
    60. End Sub
    61.  
    62. Private Sub Form_Load()
    63.     ListView1.ColumnHeaders.Add , , "Vertical ScrollBar Test"
    64. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    New Member
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    9
    This code works fine, but there's a small problem I'm having... Sometimes si.nPage = 1 when there's no vertical scrollbar. This doesn't happen when I break and debug.
    Drew (aka Headdy)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width