32-bit Scrollbars
32-bit Scrollbars
32-bit Scrollbars
32-bit Scrollbars
32-bit Scrollbars
32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars
32-bit Scrollbars 32-bit Scrollbars
32-bit Scrollbars
Go Back  Xtreme Visual Basic Talk > > > 32-bit Scrollbars


Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2015, 12:16 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default 32-bit Scrollbars


MSDN says the Scrollbar APIs have been updated to allow for 32-bit position values via SCROLLINFO structure.

I can set the max value of the scrollbar to a LONG, but setting the position value has no affect (no overflow error, just doesn't change the position).

Code:
Private Sub Command1_Click()

    Dim si As SCROLLINFO

    si.cbSize = Len(si)
    si.fMask = SIF_TRACKPOS Or SIF_RANGE Or SIF_PAGE
    si.nMax = 60000
    si.nPos = 50000
    si.nTrackPos = 50000
    si.nPage = 2

    ret = SetScrollInfo(HScroll1.hwnd, SB_CTL, si, True)
    MsgBox ret
    
End Sub
Now what am I doing wrong?
Reply With Quote
  #2  
Old 05-27-2015, 05:21 PM
OnErr0r's Avatar
OnErr0r32-bit Scrollbars OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

I think you want SIF_POS there instead of SIF_TRACKPOS.

"nTrackPos

Specifies the immediate position of a scroll box that the user is dragging. An application can retrieve this value while processing the SB_THUMBTRACK notification message. An application cannot set the immediate scroll position; the SetScrollInfo function ignores this member."

Technically, APIs use "TRUE" which is 1. "True" in VB is -1. This may work if the internal code is looking for non-zero, but I would still use the correct value.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #3  
Old 05-27-2015, 06:10 PM
passel's Avatar
passel32-bit Scrollbars passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

A bit slow to respond..., but OnErr0r explained it better than I was going to anyway.

Bet you haven't tried to drag the thumb all the way to the right and release after pressing that button.

Since you are probably going to have to implement other related API functions in order to use the scrollbar(s), you may want to check out this class.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #4  
Old 05-27-2015, 10:06 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

OnErrOr
SIF_POS WORKS!! Thanks


passel
Quote:
Bet you haven't tried to drag the thumb all the way to the right and release after pressing that button.
Yes I have... the thumb button springs back to the midway point of the scrollbar (I assume to the 32,767 value)

I saw the link to the vbaccelerator site, and read where the author states also that 32-bit scrollbars are possible using the GetScrollInfo/SetScrollInfo APIs

Unfortunately for me, that code is way over my head.


The code I have in my test project now is simply this (one HScroll_Change function).

It sets the scroll bar max value to 60,000 and then user can drag thumb bar anywhere from 0 to 60,000 (59,999 actually... don't know why)
A big but however, each subsequent drag must be in the opposite direction of the previous, for the scrollbar thumb bar to position correctly
(and report position in MsgBox correctly), otherwise scrollbar thumb jumps to a middle position (32,767?)

I've searched everywhere and can find nothing, other than what passel linked.

If anyone has further ideas, I'd appreciate them.
Code:
Option Explicit

Dim si As SCROLLINFO

Private Sub HScroll1_Change()
    
    
    ' Get
    
    si.cbSize = Len(si)
    si.fMask = SIF_TRACKPOS Or SIF_RANGE Or SIF_PAGE

    ret = GetScrollInfo(HScroll1.hwnd, SB_CTL, si)
    
    Debug.Print "HScroll1_Change: " & ret & " " & si.nTrackPos & " " & si.nMax
    
    
    ' Set
    
    si.cbSize = Len(si)
    si.fMask = SIF_POS Or SIF_RANGE Or SIF_PAGE
    si.nMax = 60000
    si.nPos = si.nTrackPos
    si.nPage = 2

    ret = SetScrollInfo(HScroll1.hwnd, SB_CTL, si, 1)
    MsgBox ret

    
End Sub
Reply With Quote
  #5  
Old 05-28-2015, 11:58 AM
passel's Avatar
passel32-bit Scrollbars passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Personally, I've almost never used scrollbars.
I either drag on the thing to be scrolled itself and implement the scrolling and zooming using the mouse events in that control (usually a picturebox displaying some drawing or image),
or add long skinny pictureboxes that I can click and drag on, and implement scrolling behavior depending on what I want it to be, such as changing the "scroll" position value relative to its current position, like a mouse pad does, which is useful when you want to have accurate positioning capability (i.e. down to the pixel) when the thing being scrolled may be many times the size of the view window you're scrolling in.
Or, scroll to an absolute position, where the position you click or drag on in the "scrollbar" directly maps to a value within your min,max range.

I started doing that back in the day (in the 80's) before we had all these controls, so had to implement any GUI buttons, scrollbars and labels and text input fields ourselves, using primitive line and rectangle fill drawing primitives.

I still find it more convenient to just add the picturebox and a few lines of code to tailor the user input to what I want, rather than plop a scrollbar down.
You also have the option of filling the "scrollbar/trackbar" with a color to indicate the value of the range, as well as print the value in the bar, like a progress bar if you want.

The main drawback is if the application is to be used by others, being able to drag on those areas for input is not intuitively obvious or recognizable to a user as a scrollbar would be. You could always add the extra three buttons to make it look and act like a scrollbar, and shouldn't be that difficult to create a user control to do that.
Fortunately, my stuff is mostly for my use, or local tools within the company, so I can always document and/or instruct users of the tool, so can get away with the less traditional method of input.

If it were me, I wouldn't fight with the existing scrollbar, or with API interfaced scrollbars, but just do something manually.

Another option I've used, but doesn't allow precise positioning with the scrollbar, is just pick a max value less than 32K and calculate a scalefactor that the value is to be multiplied by to give the full range needed.
To get the value when the scrollbar value changes
myScrollPos = HScroll1.Value * ScaleFactor

To set the value
HScroll1.Value = myScrollPos / ScaleFactor
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #6  
Old 05-28-2015, 11:00 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

I think your idea of dragging "on the thing to be scrolled itself" could be pretty slick.
I imagine something like the iPhone where transparent left and right arrows appear over the image when finger (mouse)
is over the image indicating when there is more image in those directions.
And having the scrolling speed initiated by the mouse speed and then slowing by gravity.

For another day however, as my main app is already set up to use scrollbars and I think it would be easier to continue down this path for now at least.

Also it is personal now, this 32-bit scrollbar thing should not be that difficult to use if it is already set up to take advantage of.

Surely someone (in some language) most be doing this.

I am making some progress; I am subclassing and made my own procedure to handle scrollbar messages.

Everything seems to work, except the stupid thumb won't stay in the correct position when I let go of it (I bypassed the original windowproc).
Reply With Quote
  #7  
Old 05-31-2015, 01:52 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

I notice doing it this way (subclassing) the HScroll_Scroll / VScroll_Scroll events don't fire.

Is there a way to make these events fire when subclassing?
Reply With Quote
  #8  
Old 06-04-2015, 07:11 AM
fafalone fafalone is offline
Freshman
 
Join Date: May 2010
Posts: 37
Default

If you're handling the scroll messages in your subclassing procedure, and not forwarding to DefWndProc afterwards, that causes the events not to fire. It's really not a good idea to have 2 separate handlers for the same event, so really you should move the code from the vb event to where those messages are being intercepted in your subclassing code and do everything there.
..you could also call the events from the subclassing code or, depending on what you're doing, process the message AND let it fall through to DefWndProc.
Reply With Quote
  #9  
Old 06-04-2015, 09:21 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

Quote:
It's really not a good idea to have 2 separate handlers for the same event...
Not sure I'm understanding you correctly.

What I'm trying to do is:
1. Process code to handle 32-bit values inside my ScrollBar WndProc
2. ByPass DefWndProc
3. Somehow cause ScrollBar event to fire inside form where ScrollBar is
4. Respond to ScrollBar Change & Scroll events in normal manner

I'm only doing the 32-bit stuff inside my new ScrollBar WndProc, so I think I have it set up as you suggest.
Reply With Quote
  #10  
Old 06-04-2015, 12:14 PM
passel's Avatar
passel32-bit Scrollbars passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Quote:
Originally Posted by mms View Post
...
For another day however, as my main app is already set up to use scrollbars and I think it would be easier to continue down this path for now at least.

Also it is personal now, this 32-bit scrollbar thing should not be that difficult to use if it is already set up to take advantage of.

Surely someone (in some language) most be doing this.
...
The scrollbar window may be setup to support it, but probably not the scrollbar controls, which is why the thumb refuses to exceed 32K.
If you created your own window (i.e. scrollbar) with CreateWindowEX API call, and set it up with scrollbar attributes instead of using the controls, it would probably work. Not that I have experience with it.
If you want to use the API to get 32-bit scrollbars, you probably have to go all the way with the API to create the scrollbars as well.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #11  
Old 06-05-2015, 07:23 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

As I have it now, the scrollbar control (conventionally placed on form),
will correctly deal with max/min values +2,147,483,647/-2,147,483,648 (thumb responds correctly)

Everything seems to draw/respond correctly with max/min values of:
Code:
-2,147,483,648 to 0
             0 to +2,147,483,648
-1,050,000,000 to +1,050,000,000
Still working on making Scroll_Change / Scroll_Scroll events fire
(fooling with PostMessage / SendMessage APIs)

I should try your suggestion of using CreateWindowEX, and see if
-2,147,483,648 to +2,147,483,648 limits can be used together.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
32-bit Scrollbars
32-bit Scrollbars
32-bit Scrollbars 32-bit Scrollbars
32-bit Scrollbars
32-bit Scrollbars
32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars 32-bit Scrollbars
32-bit Scrollbars
32-bit Scrollbars
 
32-bit Scrollbars
32-bit Scrollbars
 
-->