|
-
Oct 7th, 2009, 02:15 AM
#1
Thread Starter
Lively Member
Copying scrollbar setting
Hi,
Is there a way to copy a control(textbox, listbox etc..) scrollbar settings to a VB6 scrollbar. For e.g. lets say i have a list box on a form and a vertical scrollbar. When adding items to the listbox, at some time the scrollbar in the listbox will be displayed. I want the vertical scrollbar to ressemble that of the listbox scrollbar i.e. same max value, same current value and if there is no scrollbar in the listbox the vb6 vertical scrollbar becomes invisible etc...
I have a previous post in the forum abt scrollbar where RobDog888 gave a nice code but i'm unable to use that for the above context now i.e. to copy the settings to another scrollbar.
Regards
Krishley
-
Oct 7th, 2009, 03:28 AM
#2
Re: Copying scrollbar setting
Hi Krishley. Why cant you use the previous API code I posted? It retrieves the min/max change etc. You could read all the settings and duplicate the positioning in your duplicate listview or whatnot. As long as you have the same number of records/entries and same viewable workspace.
More info needed
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 
-
Oct 7th, 2009, 07:54 AM
#3
Thread Starter
Lively Member
Re: Copying scrollbar setting
Hi RobDog888
Actually I’m using your code for a third party control that I’ve downloaded at http://www.hi-components.com/ndownloads_imageenocx.asp
You can download it and copy the ocx file to System32 folder. Open a VB project and add this component. You will see that 2 components will be added to your VB project : ImageEnX and ImageEnMultiX.
Click on ImageEnMultiX and use it to draw a rectangle like shape on your form.
Also add a command button and a Horizontal scrollbar to your form and the following code (I’ve not written the declarations here but have them in my codes)
Private Sub Command1_Click()
Dim si As SCROLLINFO
Dim lRetVal As Long
ImageEnMultiX1.StoreMode = 1
ImageEnMultiX1.FillFromDirectory “ENTER THE PATH OF A FOLDER CONTAINING ATLEAST 25 PHOTOS HERE”
si.cbSize = Len(si)
si.fMask = SIF_ALL
lRetVal = GetScrollInfo(ImageEnMultiX1.hWnd, ByVal SB_HORZ, si)
HScroll1.Min = si.nMin
HScroll1.Max = si.nMax
HScroll1.Value = si.nPos
End Sub
You will see that when the above code is executed you will get an error message telling you that there was an overflow. Whatever the scrollbar size in the component si.nmax is always returning 65535. Any idea or help on how I can solve this? Also how do I get the LargeChange and SmallChange value?
Thanks
Regards
Krishley
-
Oct 7th, 2009, 08:35 AM
#4
Re: Copying scrollbar setting
Here's some code that may help.
Form with a ListBox and a VScroll
Code:
Option Explicit
Private Const SIF_RANGE = 1
Private Const SIF_PAGE = 2
Private Const SIF_POS = 4
Private Const SIF_DISABLENOSCROLL = 8
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS
Private Const LB_GETITEMHEIGHT = &H1A1
Private Const SB_VERT As Long = 1
Private Const LB_GETITEMHEIGHT = &H1A1
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
Private Declare Function GetScrollInfo Lib "user32" (ByVal HWnd As Long, ByVal nBar As Long, ByRef SI As SCROLLINFO) As Long
Private Declare Function SetScrollInfo Lib "user32.dll" (ByVal HWnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal HWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private MaxVis As Long
Private Function MaxVisible(ByVal LB As ListBox) As Long
Dim ItemHt As Long
ItemHt = SendMessage(LB.HWnd, LB_GETITEMHEIGHT, 0&, ByVal 0&)
MaxVisible = (LB.Height \ Screen.TwipsPerPixelY) \ ItemHt
End Function
Private Function VSInfo(ByVal HWnd As Long) As SCROLLINFO
VSInfo.cbSize = Len(VSInfo)
VSInfo.fMask = SIF_ALL
GetScrollInfo HWnd, SB_VERT, VSInfo
End Function
Private Sub Form_Load()
Dim i As Long
Dim SI As SCROLLINFO
MaxVis = MaxVisible(List1)
For i = 0 To 50 'change to smaller number
List1.AddItem i ' to see the effect below
Next
If List1.ListCount > MaxVis Then
SI = VSInfo(List1.HWnd)
VScroll1.Max = SI.nMax - SI.nPage
VScroll1.LargeChange = SI.nPage
Else
VScroll1.Visible = False
End If
End Sub
Private Sub List1_Scroll()
Dim SI As SCROLLINFO
SI = VSInfo(List1.HWnd)
SetScrollInfo VScroll1.HWnd, SB_VERT, SI, True
End Sub
-
Oct 7th, 2009, 01:38 PM
#5
Thread Starter
Lively Member
Re: Copying scrollbar setting
 Originally Posted by VBClassicRocks
Here's some code that may help.
Form with a ListBox and a VScroll
Code:
Option Explicit
Private Const SIF_RANGE = 1
Private Const SIF_PAGE = 2
Private Const SIF_POS = 4
Private Const SIF_DISABLENOSCROLL = 8
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS
Private Const LB_GETITEMHEIGHT = &H1A1
Private Const SB_VERT As Long = 1
Private Const LB_GETITEMHEIGHT = &H1A1
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
Private Declare Function GetScrollInfo Lib "user32" (ByVal HWnd As Long, ByVal nBar As Long, ByRef SI As SCROLLINFO) As Long
Private Declare Function SetScrollInfo Lib "user32.dll" (ByVal HWnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal HWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private MaxVis As Long
Private Function MaxVisible(ByVal LB As ListBox) As Long
Dim ItemHt As Long
ItemHt = SendMessage(LB.HWnd, LB_GETITEMHEIGHT, 0&, ByVal 0&)
MaxVisible = (LB.Height \ Screen.TwipsPerPixelY) \ ItemHt
End Function
Private Function VSInfo(ByVal HWnd As Long) As SCROLLINFO
VSInfo.cbSize = Len(VSInfo)
VSInfo.fMask = SIF_ALL
GetScrollInfo HWnd, SB_VERT, VSInfo
End Function
Private Sub Form_Load()
Dim i As Long
Dim SI As SCROLLINFO
MaxVis = MaxVisible(List1)
For i = 0 To 50 'change to smaller number
List1.AddItem i ' to see the effect below
Next
If List1.ListCount > MaxVis Then
SI = VSInfo(List1.HWnd)
VScroll1.Max = SI.nMax - SI.nPage
VScroll1.LargeChange = SI.nPage
Else
VScroll1.Visible = False
End If
End Sub
Private Sub List1_Scroll()
Dim SI As SCROLLINFO
SI = VSInfo(List1.HWnd)
SetScrollInfo VScroll1.HWnd, SB_VERT, SI, True
End Sub
Thanks for the code VBClassicRocks but its not working. The following is always returning 0 : ItemHt = SendMessage(ImageEnMultiX1.HWnd, LB_GETITEMHEIGHT, 0&, ByVal 0&). So i'm getting division by 0.
Regards
Krishley
-
Oct 7th, 2009, 03:31 PM
#6
Re: Copying scrollbar setting
Regarding the problem of getting overflow errors. VB horizontal/vertical scrollbars only accept integer values. But the GetScrollInfo API can return Long values in the scrollbarinfo structure. I doubt you will be able to use VB scrollbars without using some sort of scaling. You might have better luck using scrollbars created with CreateWindowEx API, but that will also force you to use subclassing if you want to receive events from the scrollbars.
Regarding LB_GETITEMHEIGHT returning zero. I haven't downloaded the ocx you linked to. If the control is not a listbox (ownerdrawn or otherwise), sending it LB_GETITEMHEIGHT will have no effect. You can use Spy++, WinSpector, or other tools to determine what windows class that control is, it might not be a ListBox control/class.
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
|