Skip to main content
gamedev.net
🔒 Locked

Implementing A Scrollbar?

Started by MajorShredd 0 replies 650+ views
Original Post
MajorShredd
MajorShredd
Hi there =) I''ve looked almost everywhere on the forums here and I didn''t quite find anything about actually coding a behavior for a scrollbar, so I''m just gonna take the newbie way out and ask the pros =P I have a home-brewed child window that was granted the gift of scrollbars via CreateWindowEx() flags. Supposing that the window will have a bitmap way larger than the window''s bounds inside it, what exactly would I need to do to make the scrollbars scroll through the bitmap (in my case, I need to scroll by 16 pixels at a time)? I have a handmade child window class that has its own event handler, so I will do whatever I need to in the WM_HSCROLL | WM_VSCROLL messages, and I *think* I need to just move the bitmap itself when the scrolling occurs. But like I said, I''m not sure (which is why I''m posting!) Many thanks in advance, ~ MajorShredd ~
"Great nations built on the bones of the dead with mud and straw, blood and sweat, you know your worth when your enemies praise your architecture of aggression" - Megadeth
IndirectX
IndirectX
You pretty much have the right idea. If you''re not scared , look at MFC''s CScrollView which is a generic scrollview implementation. It''s somewhat big and may be confusing, but it handles the scrolling pretty good. You need to handle scrollbar messages and either adjust the origin of the viewport accordingly (the general approach), ie if you''re scrolling 16 pixels to the right the bitmap drawing should start at x=-16, OR if you know exactly what you''re drawing you can just blit an appropriate rectangle from your image to the screen. Basically, the first way allows you to write a handler that isn''t concerned with scrolling at all, it just draws whatever necessary to create a complete view, while the second way uses some information about the data being drawn so that you only draw the visible data; in this case, the paint handler must know what the current scroll position is.

Hope this wasn''t too confusing .
---visit #directxdev on afternet <- not just for directx, despite the name

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.