Can I post an example? No. Because it would be about 100 lines long.
(That's the joy of the Windows API. If you don't want to deal with it, use
a toolkit. I recommend wxWindows. The toolkit also gives you more portable
code that will be cross platform.)
But I can point you in the right direction. Look these up in the API
documentation.
SetScrollRange
SetScrollInfo
GetScrollInfo
SetViewPortOrgEx
SetWindowOrgEx
In a nutshell, Windows API scrollbars don't do anything by themselves.
They don't even set their own position much less the position of the text
or whatever in their window. You have to explicitly program the logic for
this in your callback function by catching the following:
SB_LINEUP
SB_LINEDOWN
SB_PAGEUP
SB_PAGEDOWN
SB_THUMBTRACK or SB_THUMBPOS
And even this won't let you use the arrow keys or page up/page down keys
to scroll. You will need to program more logic to do that.
If this all sounds daunting, it is. And if you are starting to think the
Windows API is very poorly designed, you are right. It is. It requires
some very esoteric programming methods, such as odd use of structures
and such. This is why both Microsoft and Borland wrapped the API with
MFC in Microsot's case, and OWL in Borland's case. Programmers were just
getting too many migraines from using the Windows API directly. If you
still are feeling masochistic and you want to program Windows this way,
then buy the book "Programming Windows, 5th Edition" by Charles Petzold.
When you aren't reading, it, you can use it to anchor your house
in a wind storm.
If this all sounds like more work than you want to do (and it should. 100
lines of code or more just to make scrolling work is unreasonable.
Espcially when I can do the same thing with 2 lines of code in Java), then
get a toolkit. Once again, I'll put in a plug for wxWindows. It uses
native widgets, and is very cross platform, so you can easily port your
program to Linux, UNIX, or Macintosh. Don't count on being able to port
your program to any other platform if you use the Windows API. Possibly
even Longhorn if you aren't careful. (Longhorn will have depricated the
Win32 API and replaced it with the WinFX API, which doesn't resemble the
Win32 API at all.)
On Mon, 22 Dec 2003, Russell Schiwal wrote:
> I am having a devil of a time getting my Win32 scroll bars to work.
> Could someone post an example of the c-code required?
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Photos - Get your photo on the big screen in Times Square
|