Scrollbar problem

Hello there.

I'm attempting to learn WinAPI, and I want to create a scroll bar control. I managed to create it, but it looks like a scroll bar from Windows 98 and I got Windows 7. Do anyone know what I could have done wrong?

This is the code I use to create it:
1
2
3
4
5
6
7
8
9
hwndScroll[1] = CreateWindowEx (NULL,
				L"scrollbar",
				NULL,
				WS_CHILD | WS_VISIBLE | WS_TABSTOP | SBS_VERT,
				20, 82, 17, 490, 
				hWnd,
				(HMENU) 1,
				hInstance,
				NULL);


I thought maybe I am using the wrong class or something?
Also, do anyone know what the 10th parameter is, (HMENU) 1?

I got the code from Programming Windows 5th Edition by Charles Petzold.
I'm sure glad I'm not plagued with worries about visual appearances! It makes my life easier! If I was just learning to use the WinApi I think I'd be happy just to get it to function correctly.


However, your tenth parameter above to the CreateWindowEx() call is kind of a tricky one. It functions in two completely different modes, so to speak. Its typed as a HMENU parameter, and when used in that sense is the handle to a menu for the window probably obtained through a LoadMenu() call on a menu defined in a resource script.

Its other use is as a integer numeric control id for the control being created. In other words, you may have a #define somewhere in one of your *.h files for an equate something like this...

#define MY_SCROLLBAR_CONTROL 2500

Then, for the create window call to create the scroll bar control you would use this...

... , (HMENU)MY_SCROLLBAR_CONTROL, ....

I never save HWNDs returned from CreateWindow() calls in global variables, preferring instead to obtain them anywhere I need them in a program with GetDlgItem(). So, in some message handling routine for the window with the scroll bar control I'd get the handle of the control like so...

hScrollBar=GetDlgItem(hWnd, MY_SCROLLBAR_CONTROL);

So to make a long story short that 10th parameter can be 0 for a top level window, the handle to the window's menu, or a control id for a child window control.

I occasionally create scroll bar controls, but in most cases I just create a window with an included scroll bar by using the appropriate window style flag to add a scroll bar.

Oh, one other thing you'll sometimes see in that tenth parameter; sometimes a -1 is there. In that case you are telling windows not to worry about the control id. You won't be using it.
Last edited on
Topic archived. No new replies allowed.