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?
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...
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.