Beruflich Dokumente
Kultur Dokumente
To create a window, you must "fill out" this class, which means you must provide a value for each of its members so the operating system would know what your program is expected to do. The first thing you must do in order to create an application is to declare a variable of either WNDCLASS or WNDCLASSEX type. Here is an example of a WNDCLASSEX variable:
Window Extra-Memory
When an application has been launched and is displaying on the screen, which means an instance of the application has been created, the operating system allocates an amount of memory space for that application to use. If you think that your application's instance will need more memory than that, you can request that extra memory bytes be allocated to it. Otherwise, you can let the operating system handle this instance memory issue and initialize the cbWndExtra member variable to 0: I N TW I N A P IW i n M a i n ( H I N S T A N C Eh I n s t a n c e ,H I N S T A N C Eh P r e v I n s t a n c e , L P S T Rl p C m d L i n e ,i n tn C m d S h o w ) { W N D C L A S S E XW n d C l s E x ;
W n d C l s E x . c b S i z e =s i z e o f ( W N D C L A S S E X ) ; W n d C l s E x . c b C l s E x t r a=0 ; W n d C l s E x . c b W n d E x t r a=0 ; W n d C l s E x . h I n s t a n c e =h I n s t a n c e ; r e t u r n0 ; }
Message Processing
The name of the window procedure we reviewed in the previous lesson must be assigned to the lpfnWndProc member variable of the WNDCLASS or WNDCLASSEX variable. This can be defined as follows: # i n c l u d e< w i n d o w s . h > L R E S U L TW n d P r o c e d u r e ( H W N Dh W n d ,U I N Tu M s g ,W P A R A Mw P a r a m ,L P A R A Ml P a r a m ) ; I N TW I N A P IW i n M a i n ( H I N S T A N C Eh I n s t a n c e ,H I N S T A N C Eh P r e v I n s t a n c e , L P S T Rl p C m d L i n e ,i n tn C m d S h o w ) { W N D C L A S S E XW n d C l s E x ; W n d C l s E x . c b S i z e =s i z e o f ( W N D C L A S S E X ) ; W n d C l s E x . s t y l e =C S _ H R E D R A W|C S _ V R E D R A W ; W n d C l s E x . l p f n W n d P r o c=W n d P r o c e d u r e ; W n d C l s E x . c b C l s E x t r a =0 ; W n d C l s E x . c b W n d E x t r a =0 ; W n d C l s E x . h I n s t a n c e =h I n s t a n c e ; r e t u r n0 ; } L R E S U L TC A L L B A C KW n d P r o c e d u r e ( H W N Dh W n d ,U I N TM s g ,W P A R A Mw P a r a m ,L P A R A Ml P a r a m ) { s w i t c h ( M s g ) { c a s eW M _ D E S T R O Y : P o s t Q u i t M e s s a g e ( W M _ Q U I T ) ; b r e a k ; d e f a u l t : r e t u r nD e f W i n d o w P r o c ( h W n d ,M s g ,w P a r a m ,l P a r a m ) ; } r e t u r n0 ; }
To make your programming a little faster, Microsoft Windows installs a few icons. The icon is assigned to the hIcon member variable using the LoadIcon() function. For a Win32 application, the syntax of this function is: H I C O NL o a d I c o n ( H I N S T A N C Eh I n s t a n c e ,L P C T S T Rl p I c o n N a m e ) ; The hInstance argument is a handle to the file in which the icon was created. This file is usually stored in a library (DLL) of an executable program. If the icon was created as part of your application, you can use the hInstance of your application. If your are using one of the icons below, set this argument to NULL. The lpIconName is the name of the icon to be loaded. This name is added to the resource file when you create the icon resource. It is added automatically if you add the icon as part of your resources; otherwise you can add it manually when creating your resource script. Normally, if you had created and designed an icon and gave it an identifier, you can pass it using the MAKEINTRESOURCE macro. To make your programming a little faster, Microsoft Windows installs a few icons you can use for your application. These icons have identification names that you can pass to the LoadIcon() function as the lpIconName argument. The icons are: ID IDI_APPLICATION IDI_INFORMATION IDI_ASTERISK IDI_QUESTION IDI_WARNING IDI_EXCLAMATION IDI_HAND IDI_ERROR If you designed your own icon (you should make sure you design a 32x32 and a 16x16 versions, even for convenience), to use it, specify the hInstance argument of the LoadIcon() function to the instance of your application. Then use the MAKEINTRESOURCE macro to convert its identifier to a null-terminated string. This can be done as follows: W n d C l s . h I c o n=L o a d I c o n ( h I n s t a n c e ,M A K E I N T R E S O U R C E ( I D I _ S T A P L E ) ) ; The icon can be specified by its name, which would be a null-terminated string passed as lpszResourceName. If you had designed your icon and gave it an ID, you can pass this identifier to the LoadIcon() method. The LoadIcon() member function returns an HICON object that you can assign to the hIcon member variable of your WNDCLASS object. Besides the regular (32x32) icon, the WNDCLASSEX structure allows you to specify a small icon (16x16) to use in some circumstances. You can specify both icons as follows: I N TW I N A P IW i n M a i n ( H I N S T A N C Eh I n s t a n c e ,H I N S T A N C Eh P r e v I n s t a n c e , L P S T Rl p C m d L i n e ,i n tn C m d S h o w ) { W N D C L A S S E XW n d C l s E x ; W n d C l s E x . c b S i z e =s i z e o f ( W N D C L A S S E X ) ; W n d C l s E x . s t y l e =C S _ H R E D R A W|C S _ V R E D R A W ; W n d C l s E x . l p f n W n d P r o c=W n d P r o c e d u r e ; W n d C l s E x . c b C l s E x t r a =0 ; W n d C l s E x . c b W n d E x t r a =0 ; W n d C l s E x . h I c o n =L o a d I c o n ( N U L L ,I D I _ A P P L I C A T I O N ) ; W n d C l s E x . h I n s t a n c e =h I n s t a n c e ; W n d C l s E x . h I c o n S m =L o a d I c o n ( N U L L ,I D I _ A P P L I C A T I O N ) ; r e t u r n0 ; } Picture
Introduction to Cursors
A cursor is used to locate the position of the mouse pointer on a document or the screen. To use a cursor, call the Win32 LoadCursor() function. Its syntax is: H C U R S O RL o a d C u r s o r ( H I N S T A N C Eh I n s t a n c e ,L P C T S T Rl p C u r s o r N a m e ) ; The hInstance argument is a handle to the file in which the cursor was created. This file is usually stored in a library (DLL) of an executable program. If the cursor was created as part of your application, you can use the hInstance of your application. If your are using one of the below cursors, set this argument to NULL.
below cursors, set this argument to NULL. When Microsoft Windows installs, it also installs various standard cursors you can use in your program. Each one of these cursors is recognized by an ID which is simply a constant integers. The available cursors are:
ID
IDC_APPSTARTING IDC_ARROW IDC_CROSS IDC_HAND
Picture
Description
Used to show that something undetermined is going on or the application is not stable This standard arrow is the most commonly used cursor The crosshair cursor is used in various circumstances such as drawing The Hand is standard only in Windows 2000. If you are using a previous operating system and need this cursor, you may have to create your own. The combined arrow and question mark cursor is used when providing help on a specific item on a window object The I-beam cursor is used on text-based object to show the position of the caret This cursor is not used anymore This cursor can be used to indicate an unstable situation This cursor is not used anymore The four arrow cursor pointing north, south, east, and west is highly used to indicate that an object is selected or that it is ready to be moved The northeast and southwest arrow cursor can be used when resizing an object on both the length and the height The north - south arrow pointing cursor can be used when shrinking or heightening an object The northwest - southeast arrow pointing cursor can be used when resizing an object on both the length and the height The west - east arrow pointing cursor can be used when narrowing or enlarging an object The vertical arrow cursor can be used to indicate the presence of the mouse or the caret The Hourglass cursor is usually used to indicate that a window or the application is not ready.
The LoadCursor() member function returns an HCURSOR value. You can assign it to the hCursor member variable of your WNDCLASS object. Here is an example: I N TW I N A P IW i n M a i n ( H I N S T A N C Eh I n s t a n c e ,H I N S T A N C Eh P r e v I n s t a n c e , L P S T Rl p C m d L i n e ,i n tn C m d S h o w ) { W N D C L A S S E XW n d C l s E x ; W n d C l s E x . c b S i z e =s i z e o f ( W N D C L A S S E X ) ; W n d C l s E x . s t y l e =C S _ H R E D R A W|C S _ V R E D R A W ; W n d C l s E x . l p f n W n d P r o c=W n d P r o c e d u r e ; W n d C l s E x . c b C l s E x t r a =0 ; W n d C l s E x . c b W n d E x t r a =0 ; W n d C l s E x . h I c o n =L o a d I c o n ( N U L L ,I D I _ A P P L I C A T I O N ) ; W n d C l s E x . h C u r s o r =L o a d C u r s o r ( N U L L ,I D C _ A R R O W ) ; W n d C l s E x . h I n s t a n c e =h I n s t a n c e ; W n d C l s E x . h I c o n S m =L o a d I c o n ( N U L L ,I D I _ A P P L I C A T I O N ) ; r e t u r n0 ; }
In addition to the stock objects, the Microsoft Windows provides a series of colors for its own internal use. These are the colors used to paint the borders of frames, buttons, scroll bars, title bars, text, etc. The colors are named (you should be able to predict their appearance or role from their name) COLOR_ACTIVEBORDER, COLOR_ACTIVECAPTION, COLOR_APPWORKSPACE, COLOR_BACKGROUND, COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNTEXT, COLOR_CAPTIONTEXT, COLOR_GRAYTEXT, COLOR_HIGHLIGHT, COLOR_HIGHLIGHTTEXT, COLOR_INACTIVEBORDER, COLOR_INACTIVECAPTION, COLOR_MENU, COLOR_MENUTEXT, COLOR_SCROLLBAR, COLOR_WINDOW, COLOR_WINDOWFRAME, and COLOR_WINDOWTEXT. You can use any of these colors to paint the background of your window. First cast it to HBRUSH and assign it to hbrBackground: I N TW I N A P IW i n M a i n ( H I N S T A N C Eh I n s t a n c e ,H I N S T A N C Eh P r e v I n s t a n c e , L P S T Rl p C m d L i n e ,i n tn C m d S h o w ) { W N D C L A S S E XW n d C l s E x ; W n d C l s E x . c b S i z e =s i z e o f ( W N D C L A S S E X ) ; W n d C l s E x . s t y l e =C S _ H R E D R A W|C S _ V R E D R A W ; W n d C l s E x . l p f n W n d P r o c =W n d P r o c e d u r e ; W n d C l s E x . c b C l s E x t r a =0 ; W n d C l s E x . c b W n d E x t r a =0 ; W n d C l s E x . h I c o n =L o a d I c o n ( N U L L ,I D I _ A P P L I C A T I O N ) ; W n d C l s E x . h C u r s o r =L o a d C u r s o r ( N U L L ,I D C _ A R R O W ) ; W n d C l s E x . h b r B a c k g r o u n d=G e t S t o c k O b j e c t ( W H I T E _ B R U S H ) ; W n d C l s E x . h I n s t a n c e =h I n s t a n c e ; W n d C l s E x . h I c o n S m =L o a d I c o n ( N U L L ,I D I _ A P P L I C A T I O N ) ; r e t u r n0 ; }
W n d C l s E x . c b W n d E x t r a =0 ; W n d C l s E x . h I c o n =L o a d I c o n ( N U L L ,I D I _ A P P L I C A T I O N ) ; W n d C l s E x . h C u r s o r =L o a d C u r s o r ( N U L L ,I D C _ A R R O W ) ; W n d C l s E x . h b r B a c k g r o u n d=G e t S t o c k O b j e c t ( W H I T E _ B R U S H ) ; W n d C l s E x . l p s z M e n u N a m e =N U L L ; W n d C l s E x . l p s z C l a s s N a m e=C l s N a m e ; W n d C l s E x . h I n s t a n c e =h I n s t a n c e ; W n d C l s E x . h I c o n S m =L o a d I c o n ( N U L L ,I D I _ A P P L I C A T I O N ) ; r e t u r n0 ; }
Previous
Next