Download presentation
Presentation is loading. Please wait.
Published byLetitia Kelly Modified over 9 years ago
1
Registering a window class Windows allows many styles of window to be created. To tell Windows to create a window as you want it you need to define a class of window and register it with windows. In order to register a class you call the API function: ATOM RegisterClassEx(CONST WNDLCASSEX *lpwcx); This function takes a pointer to a structure you have defined to describe your window class. The return value ATOM is one of those Microsoft typedefs again and resolves to unsigned short. This function returns 0 if there was an error. The const indicates that the function will not change the structure.
2
style - this allows us to combine some flags to describe the low level style for our window, CS_HREDRAW means we want our window redrawing if the width is ever changed. lpfnWindProc - this is essential, this is where we tell Windows which of our functions is going to handle messages sent to this window. Remember from earlier that Windows is event driven, so if someone clicks on the window Windows responds to that even by telling us what has happened. We provide a function to receive these messages and in this structure element we pass the pointer to the function (a callback function). The WNDPROC is used to cast the function pointer into the correct form for Windows. hIcon and hIconSm - defines the icons used by the program. The small one (16 by 16) is displayed in the top left of the window and on the taskbar. The big one (32 by 32) is visible when you look at the executable in explorer on your hard drive and also when you ALT-TAB between applications. These icons are defined using the resource editor,described elsewhere, and referred to using a #define. hCursor - this describes the default mouse cursor displayed whenever the mouse is over this window. Usually this is an arrow (IDC_ARROW) but you can also have things like IDC_CROSS or IDC_WAIT (the hourglass) or even define your own. hBrBackground - the colour you want the background of your window to be. By using COLOR_WINDOW+1 we are saying we want to use whatever background the user of the PC has defined. If we wanted to use a basic colour we need to define a brush or use one of the stock brushes. e.g. to set the background to black we could use: hBrBackground=(HBRUSH) GetStockObject(BLACK_BRUSH); Note that if you are drawing the whole screen yourself you are better to leave this as 0 which means Windows will not fill the background.brush lpszMenuName - the menu you want to be displayed in this window. Again you define this in the resource editor and give it an identifier or 0 if no menu used. lpszClassName - this is essential, this is your name you want to give to this class, it can be anything you want.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.