|
-
May 21st, 2004, 10:51 PM
#1
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 21st, 2004, 11:34 PM
#2
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:
Private Declare Function GetScrollBarInfo Lib "user32.dll" (ByVal hwnd As Long, _
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 21st, 2004, 11:48 PM
#3
So Unbanned
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
-
May 21st, 2004, 11:50 PM
#4
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:
Option Explicit
Private 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
'SCROLLBAR STYLE
Private Const SBS_VERT As Long = &H1&
'SCROLLBAR MESSAGE
Private Const WM_VSCROLL As Long = &H115
'SCROLLBAR CONST
Private Const SB_VERT As Long = 1
'Private Declare Function GetScrollBarInfo Lib "user32.dll" (ByVal hwnd As Long, ByVal idObject As Long, ByRef psbi As PSCROLLBARINFO) As Long
Private Declare Function GetScrollInfo Lib "user32.dll" (ByVal hWnd As Long, ByVal n As Long, ByRef lpScrollInfo As SCROLLINFO) As Long
Private Sub cmdAdd_Click()
ListView1.ListItems.Add , , "Test"
End Sub
Private Sub cmdCheck_Click()
Dim si As SCROLLINFO
Dim lRetVal As Long
si.cbSize = Len(si)
si.fMask = SB_VERT
lRetVal = GetScrollInfo(ListView1.hWnd, ByVal SB_VERT, si)
If si.fMask = SB_VERT Then
MsgBox lRetVal & "-True"
Else
MsgBox lRetVal & "-False"
End If
End Sub
Private Sub cmdRemove_Click()
ListView1.ListItems.Remove ListView1.ListItems.Count
End Sub
Private Sub Form_Load()
ListView1.ColumnHeaders.Add , , "Test"
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 22nd, 2004, 02:28 AM
#5
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:
'NEED 3 COMMANDBUTTONS AND 1 LISTVIEW
Option Explicit
Private 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
'SCROLLBAR STYLE
'Private Const SBS_HORZ As Long = &H0&
'Private Const SBS_VERT As Long = &H1&
'SCROLLBAR MESSAGE
'Private Const WM_HSCROLL As Long = &H114
'Private Const WM_VSCROLL As Long = &H115
'SCROLLBAR CONSTS
Private Const SB_HORZ As Long = 0
Private Const SB_VERT As Long = 1
Private Const SB_CTL As Long = 2
Private Const SB_BOTH As Long = 3
Private Const SIF_PAGE As Long = &H2
Private Const SIF_POS As Long = &H4
Private Const SIF_RANGE As Long = &H1
Private Const SIF_TRACKPOS As Long = &H10 'FOR DETECTING WHEN USER CLICKS AND DRAGS THUMB CTL
Private Const SIF_ALL As Long = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
Private Declare Function GetScrollInfo Lib "user32.dll" (ByVal hWnd As Long, ByVal n As Long, _
ByRef lpScrollInfo As SCROLLINFO) As Long
Private Sub cmdAdd_Click()
ListView1.ListItems.Add , , "Test " & ListView1.ListItems.Count + 1
End Sub
Private Sub cmdCheck_Click()
Dim si As SCROLLINFO
Dim lRetVal As Long
si.cbSize = Len(si)
si.fMask = SIF_PAGE
lRetVal = GetScrollInfo(ListView1.hWnd, ByVal SB_VERT, si)
If ListView1.ListItems.Count > si.nPage Then
MsgBox "Vertical ScrollBar Visible = True"
Else
MsgBox "Vertical ScrollBar Visible = False"
End If
End Sub
Private Sub cmdRemove_Click()
If ListView1.ListItems.Count = 0 Then Exit Sub
ListView1.ListItems.Remove ListView1.ListItems.Count
End Sub
Private Sub Form_Load()
ListView1.ColumnHeaders.Add , , "Vertical ScrollBar Test"
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Sep 14th, 2004, 05:16 AM
#6
New Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|