ive looked everywhere for a good explanation on scrollbars
the one at www.gametutorials.com isnt that impressive, and i've read the info at MSDN
can you tell me what i need to do to scroll a simple window?
ive looked everywhere for a good explanation on scrollbars
the one at www.gametutorials.com isnt that impressive, and i've read the info at MSDN
can you tell me what i need to do to scroll a simple window?
I suppose what many people would ask is, what kind of application are you gearing this towards? Are you going to be using MFC or just the straight API? Do you just want simple scrollbars or something more complex? If you can answer those it would help people give you a better answer.
no MFC just straight API and a simple scrollbar for a simple window
You might be able to get away with somethign simple by using the CreateWindowEx function and then specifying WS_EX_LEFTSCROLLBAR as one of the dwExStyle Params.
Or you can use WS_EX_RIGHTSCROLLBAR as well...
Last edited by dpro; 12-20-2004 at 07:02 PM. Reason: made a silly error...
i know of that but it's not gonna scroll for me i need to add some extra stuff which i know some of like scrollwindow() function and so
but i dont know how this works, i need an explaining on some things that make the window scroll
what du i need to be able to scroll?
It is a pretty big case to cover, but I can try.
First, there are two ways of handling the windows-scrollbar.
Number 1:
First of all, to add the scrollbars to your window, add "WS_HSCROLL or "WS_VSCROLL" to the 3.rd parameter to the CreateWindow() function. The 3.rd parameter is as known, the place where all WindowStyles are placed. "WS=WindowStyle".
H=HorizontalScroll, V=Vertical scroll.
Windows takes care of the mouse-input to the scrollbars, so you dont neet to bother about that. But if you want to have a keyboard-interface, I take that later. You will have to make that yourself. But its very simple.
The magic you probably look for are in way1, two functions:
"SetScrollRange()" and "SetScrollPos()". As the name says, ScrollRange sets the "range of the Scrollbar", a number(Integer), for how long the scrollbar should be able to scroll.
The "SetScrollPos()" sets the ScrollBar Thumb and scrollposition to a number in the scroll-range. For example:
SetScrollRange(hwnd,SB_VERT,0,100,TRUE);
SetScrollPos(hwnd,SB_VERT,50,TRUE);
This means that i :Sets the scrollrange to one of the scrollbars in to the window which my HWND is pointing to. Further, I specify in parameter 2 that it is the Vertical scrollbar I'm messing with.
I set the minimun scrollrange to zero and the maximum to 100.
Then, I Sets the Scroll-position and Scrollbar thumb to number "50" of "100", with function two.
So after this, I would have got a Scrollbar with its thumb in the middle.
And ofcaurse, Windows also gives you thease functions:
"GetScrollRange()" and "SetScrollRange()". I wont be explaining how they work, as I guess you got the point
Let me guess, you now think something similar to this "Wow, this is all great, but how can I actually make the scrollbar move when i click on it?
Here comes the answer:
When you click on them with the mouse, Windows sends your WindowsProcedure either a WM_VSCROLL or a WM_HSCROLL message. You trap thease messages as you do with everything else, like this:
...
case WM_VSCROLL:
*do something to the scrollbar*
return0;
...
What should you call when the message appears?
First, you need to check the "low word of wParam", like this
switch(LOWORD(wParam)) {
case something:
break;
case somethingelse:
break;
}
But instead of writing something and something else, insert the possible notifactioncodes.
They are
SB_LINEUP
SB_LINELEFT
SB_LINEDOWN
SB_LINERIGHT
SB_PAGEUP
SB_PAGELEFT
SB_PAGEDOWN
SB_PAGERIGHT
SB_THUMBPOSITION
SB_TOP
SB_BOTTOM
SB_RIGHT
SB_ENDSCROLL
I wont be telling more 'bout thease, as the names says it all.
If you wanna know more though, scearch it up in MSDN.
Important: Windows wont change the contents of the window, or the scrollbar, that must you make yourself.
Now, how to move the scrollbar?
In your windowsprocedure, add a int varaible named scroll for instance.
Then, on the WM_VSCROLL message, simply do something like this:
...
case WM_VSCROLL:
switch(LOWORD(wParam)) {
case SB_LINEUP:
scroll+=1; // This is similar to "scroll = scroll+1;"
}
SetScrollPos(use your "scroll integer here");
return 0;
...
Great, now you know how to administrate the scrollbar. Your last task is to update the contents according to what position the thumb is in.. Which is plain maths in your WM_PAINT part.
Here is a example application, if you need a example:
http://amalfi.dis.unina.it/~carlosan...2/sysmets2.htm
EDIT: I try to cover the other scrolling method tomorrow
http://livebad.com/nuka
Da-Nuka
Here is an example program that displays vertically scrolling the window. Hopefully it will get you started.
Happy coding!
The example program andyhunter come up with, uses the other way of Scrollbar managing. Contact me if you would like to know more about it
http://livebad.com/nuka
Da-Nuka
A really good in depth tutorial for win32 and scrollbars is here
thx alot all of you ,hey the autoscroll is so easy why dont you use that?
It depends what you want...
When using autoscrolls, you do little work yourself..
If you are like me, you want to have as much power as possible at your hand, which means as few windows-side-messing as possible.. hmm...I sound like a Linux programmer
http://livebad.com/nuka
Da-Nuka
what does this mean?
Code:case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam);
During the Size message that the window proc recieves whenever the window is resized, the new size of the window is passed via lParam.
The code simply splits up lParam into its parts and retrieves the new width of the window cxClient and the new height cyClient.
It then uses that information to fill out the scroll information structure in the code immediately following.
Last edited by andyhunter; 12-24-2004 at 08:17 PM.
my compilers cannot use LOWORD i have both msvc6 and dev++
can i set the words manually?
maybe with MAKEWORD();