Understanding Window Classes and Message Dispatching in Windows, Study notes of Computer Engineering and Programming

An in-depth explanation of creating windows and handling messages in the context of windows application development. Topics covered include registering window classes, setting window attributes, creating windows using the createwindow api, and message dispatching. Students will gain a solid understanding of the role of window classes and procedures in managing graphical user interfaces.

Typology: Study notes

2011/2012

Uploaded on 11/06/2012

ahsen
ahsen 🇵🇰

4.6

(88)

84 documents

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 9
9.1 MULTIPLE INSTANCES 2
9.2 WINDOW CLASS 2
9.3 REGISTERING WINDOW CLASS 2
9.4 ELEMENTS OF A WINDOW CLASS 3
9.4.1 CLASS NAME 5
9.4.2 WINDOW PROCEDURE ADDRESS 5
9.4.3 INSTANCE HANDLE 5
9.4.4 CLASS CURSOR 5
9.4.5 CLASS ICONS 6
9.4.6 CLASS BACKGROUND BRUSH 6
9.4.7 CLASS MENU 7
9.4.8 CLASS STYLES 7
9.5 USING WINDOW CLASS (EXAMPLE) 9
9.6 ABOUT WINDOWS 11
9.6.1 CLIENT AREA 11
9.6.2 NONCLIENT AREA 11
9.7 PROTOTYPE OF CREATEWINDOW 12
9.7.1 CLASS NAME (LPCLASSNAME) 13
9.7.2 WINDOW NAME (LPWINDOWNAME). 13
9.7.3 WINDOW STYLES (DWSTYLE) 13
BITWISE INCLUSIVE-OR OPERATOR ‘|’ 16
9.7.4 HORIZONTAL POSITION OF THE WINDOW (X) 16
9.7.5 VERTICAL POSITION OF THE WINDOW (Y) 16
9.7.6 WIDTH OF THE WINDOW (NWIDTH) 16
9.7.7 HEIGHT OF THE WINDOW (NHEIGHT) 17
9.7.8 PARENT OF THE WINDOW (HWNDPARENT) 17
9.7.9 MENU OF THE WINDOW (HMENU) 17
9.7.10 INSTANCE HANDLE (HINSTANCE) 17
9.7.11 LONG PARAM (LPPARAM) 17
9.7.12 RETURN VALUE 17
9.8 USING WINDOWS(EXAMPLE) 18
9.9 MESSAGES IN WINDOWS 18
9.9.1 MESSAGE QUEUING 19
9.9.2 MESSAGE ROUTING 19
9.10 WINDOW PROCEDURE 19
9.10.1 HANDLE TO WINDOW(HWND) 19
9.10.2 MESSAGE TYPE(UMSG) 20
9.10.3 MESSAGES WPARAM(WPARAM) 20
9.10.4 MESSAGES LPARAM(LPARAM) 20
9.10.5 RETURN VALUE 20
The return value is the result of the message processing and depends on the message sent. 20
9.11 GETTING MESSAGE FROM MESSAGE QUEUE 20
9.12 MESSAGE DISPATCHING 21
SUMMARY 21
EXERCISES 22
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Understanding Window Classes and Message Dispatching in Windows and more Study notes Computer Engineering and Programming in PDF only on Docsity!

  • Chapter
  • 9.1 M ULTIPLE INSTANCES
  • 9.2 WINDOW CLASS
  • 9.3 REGISTERING WINDOW CLASS
  • 9.4 ELEMENTS OF A WINDOW CLASS
  • 9.4.1 CLASS NAME
  • 9.4.2 W INDOW P ROCEDURE ADDRESS
  • 9.4.3 I NSTANCE H ANDLE
  • 9.4.4 CLASS CURSOR
  • 9.4.5 CLASS I CONS
  • 9.4.6 CLASS BACKGROUND BRUSH
  • 9.4.7 CLASS M ENU
  • 9.4.8 CLASS S TYLES
  • 9.5 USING WINDOW CLASS (EXAMPLE)
  • 9.6 ABOUT WINDOWS
  • 9.6.1 CLIENT AREA
  • 9.6.2 NONCLIENT AREA
  • 9.7 P ROTOTYPE OF CREATE WINDOW
  • 9.7.1 CLASS NAME ( LP CLASSNAME )
  • 9.7.2 W INDOW NAME ( LP WINDOW NAME )
  • 9.7.3 W INDOW S TYLES ( DW S TYLE )
  • BITWISE INCLUSIVE -OR OPERATOR ‘|’
  • 9.7.4 HORIZONTAL P OSITION OF THE W INDOW ( X )
  • 9.7.5 VERTICAL P OSITION OF THE W INDOW ( Y )
  • 9.7.6 W IDTH OF THE W INDOW ( NWIDTH )
  • 9.7.7 HEIGHT OF THE W INDOW ( NHEIGHT )
  • 9.7.8 P ARENT OF THE W INDOW ( HWNDP ARENT )
  • 9.7.9 M ENU OF THE W INDOW ( HMENU )
  • 9.7.10 I NSTANCE H ANDLE ( HI NSTANCE )
  • 9.7.11 L ONG P ARAM ( LP P ARAM )
  • 9.7.12 RETURN VALUE
  • 9.8 USING WINDOWS(EXAMPLE)
  • 9.9 M ESSAGES IN W INDOWS
  • 9.9.1 M ESSAGE QUEUING
  • 9.9.2 M ESSAGE ROUTING
  • 9.10 WINDOW P ROCEDURE
  • 9.10.1 HANDLE TO W INDOW( H W ND )
  • 9.10.2 M ESSAGE T YPE ( UMSG )
  • 9.10.3 M ESSAGE ’ S WPARAM( W P ARAM )
  • 9.10.4 M ESSAGE ’ S LPARAM( LP ARAM )
  • 9.10.5 RETURN VALUE
  • The return value is the result of the message processing and depends on the message sent.
  • 9.11 GETTING MESSAGE FROM M ESSAGE Q UEUE
  • 9.12 M ESSAGE DISPATCHING
  • SUMMARY
  • EXERCISES

9.1 Multiple Instances

Every running application is an Application Instance. So if you open more than one

application, more than one instance will be running simultaneously. If you write a

program and run it, this running program will be known as a process running in memory.

Whenever you press ALT-CONTROL-DELETE, you can open Task Manager to watch

all the processes present in task list, running under Windows. Each process can have one

or more than one windows. Every process has at least one thread running, which is UI

thread.

9.2 Window Class

Every window in Windows has its own registered Window class. This window class has

set of attributes which are later used by windows. These attributes could be windows

background brush, windows style, cursors, Icons, etc. So Windows class tells the

Operating system about the characteristics and physical layout of its windows. Window

Class is simply a structure named WNDCLASS or WNDCLASSEX that only contains

set of attributes for window.

Each window class has an associated window procedure shared by all windows of the same class. The window procedure processes messages for all windows of that class and therefore, controls their behavior and appearance. For more information, see Window Procedures.

A process must register a window class before it creates a window. Registering a window class associates a window procedure, class styles and other class attributes particularly a class name. When a process specifies a class name in the CreateWindow or CreateWindowEx function, the system creates a window using a registered class name.

A window class defines the attributes of a window such as style, icon, cursor, menu, and window procedure. The first step in registering a window class is to fill a WNDCLASS structure. For more information, see Elements of a Window Class. Next step is to pass the structure to the RegisterClass function.

To register an application global class, specify the CS_GLOBALCLASS style in the style member of the WNDCLASSEX structure. When registering an application local class, do not specify the CS_GLOBALCLASS style.

If you register the window class using the ANSI version of RegisterClassEx , RegisterClassExA , the application requests that the system pass text parameters of messages to the windows of the created class using the ANSI character set; if you register the class using the Unicode version of RegisterClassEx , RegisterClassExW , the application requests that the system pass text parameters of messages to the windows of the created class using the Unicode character set. The IsWindowUnicode function enables

The Structure of Window Class is as follows.

WNDCLASS Structure

typedef struct _WNDCLASS {

LPCTSTR lpszClassName;

WNDPROC lpfnWndProc;

UINT style;

int cbClsExtra;

int cbWndExtra;

HINSTANCE hInstance;

HICON hIcon;

HCURSOR hCursor;

HBRUSH hbrBackground;

LPCTSTR lpszMenuName;

} WNDCLASS, *PWNDCLASS;

Although a complete window class consists of many elements, the system requires the application which supplies a class name, the window-procedure address and an instance handle. Use the other elements to define default attributes for windows of the class, such as the shape of the cursor and the content of the menu for the window. You must initialize any unused members of the WNDCLASSEX structure to zero or NULL. The window class elements are as shown in the following table.

Element Purpose

Class Name Distinguishes the class from other registered classes.

Window Procedure Address

Pointer to the function that processes all messages sent to windows in the class and defines the behavior of the window.

Instance Handle Identifies the application or .dll that registered the class.

Class Cursor Defines the mouse cursor that the system displays for a window of the class.

Class Icons Defines the large icon and the small icon (Windows NT 4.0 and later).

Class Background Brush.

Defines the color and pattern that fill the client area when the window is opened or painted.

Class Menu Specifies the default menu for windows that do not explicitly define a menu.

Class Styles

Defines how to update the window after moving or resizing it, how to process double-clicks of the mouse, how to allocate space for the device context, and other aspects of the window.

Extra Class Memory

Specifies the amount of extra memory, in bytes, that the system should reserve for the class. All windows in the class share the extra memory

and can use it for any application-defined purpose. The system initializes this memory to zero.

Extra Window Memory

Specifies the amount of extra memory, in bytes, that the system should reserve for each window belonging to the class. The extra memory can be used for any application-defined purpose. The system initializes this memory to zero.

9.3.1 Class Name

Every window class needs a Class Name to distinguish one class from another. Assign a class name by setting the lpszClassName member of the WNDCLASSEX structure to the address of a null-terminated string that specifies the name. Because window classes are process specific, window class names need to be unique only within the same process. Also, because class names occupy space in the system's private ATOM table, you should keep class name strings as short a possible.

The GetClassName function retrieves the name of the class to which a given window belongs.

9.3.2 Window Procedure Address

Every class needs a window-procedure address to define the entry point of the window procedure used to process all messages for windows in the class. The system passes messages to the procedure when it requires the window to carry out tasks, such as painting its client area or responding to input from the user. A process assigns a window procedure to a class by copying its address to the lpfnWndProc member of the WNDCLASSEX structure. For more information, see Window Procedures.

9.3.3 Instance Handle

Every window class requires an instance handle to identify the application or .dll that registers the class. The system requires instance handles to keep track of all modules. The system assigns a handle to each copy of a running executable or .dll.

The system passes an instance handle to the entry-point function of each executable. The executable or .dll assigns this instance handle to the class by copying it to the hInstance member of the WNDCLASSEX structure.

9.3.4 Class Cursor

The class cursor defines the shape of the cursor when it is in the client area of a window in the class. The system automatically sets the cursor to the given shape when the cursor enters the window's client area and ensures it keeps that shape while it remains in the client area. To assign a cursor shape to a window class, load a predefined cursor shape by using the LoadCursor function and then assign the returned cursor handle to the hCursor

Instead of creating a brush, an application can set the hbrBackground member to one of the standard system color values. For a list of the standard system color values, see System Colors from Microsoft Documentation.

To use a standard system color, the application must increase the background-color value by one. For example, COLOR_BACKGROUND + 1 are the system background color. Alternatively, you can use the GetSysColorBrush function to retrieve a handle to a brush that corresponds to a standard system color, and then specify the handle in the hbrBackground member of the WNDCLASSEX structure.

The system does not require that a window class has a class background brush. If this parameter is set to NULL, the window must paint its own background whenever it receives the WM_ERASEBKGND message.

9.3.7 Class Menu

A class menu defines the default menu to be used by the windows in the class if no explicit menu is given when the windows are created. A menu is a list of commands from which a user can choose actions for the application to carry out.

You can assign a menu to a class by setting the lpszMenuName member of the WNDCLASSEX structure to the address of a null-terminated string that specifies the resource name of the menu. The menu is assumed to be a resource in the given application. The system automatically loads the menu when it is needed. If the menu resource is identified by an integer and not by a name, the application can set the lpszMenuName member to that integer by applying the MAKEINTRESOURCE macro before assigning the value.

The system does not require a class menu. If an application sets the lpszMenuName member of the WNDCLASSEX structure to NULL, window in the class has no menu bar. Even if no class menu is given, an application can still define a menu bar for a window when it creates the window.

If a menu is given for a class and a child window of that class is created, the menu is ignored.

9.3.8 Class Styles

The class styles define additional elements of the window class. Two or more styles can be combined by using the bitwise OR (|) operator. To assign a style to a window class, assign the style to the style member of the WNDCLASSEX structure. The class styles are as follows.

Style Action

CS_BYTEALIGNCLIENT

Aligns the window's client area on a byte boundary (in the x direction). This style affects the width of the window and its horizontal placement on the display.

CS_BYTEALIGNWINDOW

Aligns the window on a byte boundary (in the x direction). This style affects the width of the window and its horizontal placement on the display.

CS_CLASSDC

Allocates one device context to be shared by all windows in the class. Because window classes are process specific, it is possible for multiple threads of an application to create a window of the same class. It is also possible for the threads to attempt to use the device context simultaneously. When this happens, the system allows only one thread to successfully finish its drawing operation.

CS_DBLCLKS

Sends a double-click message to the window procedure when the user double-clicks the mouse while the cursor is within a window belonging to the class.

CS_DROPSHADOW

Windows XP: Enables the drop shadow effect on a window. The effect is turned on and off through SPI_SETDROPSHADOW. Typically, this is enabled for small, short-lived windows such as menus to emphasize their Z order relationship to other windows.

CS_GLOBALCLASS Specifies that the window class is an application global class. For more information.

CS_HREDRAW Redraws the entire window if a movement or size adjustment changes the width of the client area.

CS_NOCLOSE Disables Close on the window menu.

CS_OWNDC Allocates a unique device context for each window in the class.

CS_PARENTDC

Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style bit receives a regular device context from the system's cache of device contexts. It does not give the child the parent's device context or device context settings. Specifying CS_PARENTDC enhances an application's performance.

CS_SAVEBITS

Saves, as a bitmap, the portion of the screen image obscured by a window of this class. When the window is removed, the system uses the saved bitmap to restore the screen image, including other windows that were obscured. Therefore, the system does not send WM_PAINT messages to windows that were obscured if the memory used by the bitmap has not been discarded and if other screen actions have not invalidated the stored image.

wcx.cbSize = sizeof(wcx); // size of

structure

wcx.style = CS_HREDRAW |

CS_VREDRAW; // redraw if

size changes

wcx.lpfnWndProc = MainWndProc; // points to

window procedure

wcx.cbClsExtra = 0; // no extra

class memory

wcx.cbWndExtra = 0; // no extra

window memory

wcx.hInstance = hinstance; // handle to

instance

wcx.hIcon = LoadIcon(NULL,

IDI_APPLICATION); // predefined

app. icon

wcx.hCursor = LoadCursor(NULL,

IDC_ARROW); // predefined

arrow

wcx.hbrBackground = GetStockObject(

WHITE_BRUSH); // white

background brush

wcx.lpszMenuName = "MainMenu"; // name of menu

resource

wcx.lpszClassName = "MainWClass"; // name of

window class

wcx.hIconSm = LoadImage(hinstance, // small class

icon

MAKEINTRESOURCE(5),

IMAGE_ICON,

GetSystemMetrics(SM_CXSMICON),

GetSystemMetrics(SM_CYSMICON),

LR_DEFAULTCOLOR);

// Register the window class.

return RegisterClassEx(&wcx);

9.5 About Windows

Every graphical Microsoft® Windows®-based application creates at least one window, called the main window that serves as the primary interface between the user and the application. Most applications also create other windows, either directly or indirectly, to perform tasks related to the main window. Each window plays a part in displaying output and receiving input from the user.

When you start an application, the system also associates a taskbar button with the application. The taskbar button contains the program icon and title. When the application is active, its taskbar button is displayed in the pushed state.

An application window includes elements such as a title bar, a menu bar, the window menu (formerly known as the system menu), the minimize button, the maximize button, the restore button, the close button, a sizing border, a client area, a horizontal scroll bar, and a vertical scroll bar. An application's main window typically includes all of these components. The following illustration shows these components in a typical main window.

9.5.1 Client Area

The client area is the part of a window where the application displays output, such as text or graphics. For example, a desktop publishing application displays the current page of a document in the client area. The application must provide a function, called a window procedure, to process input to the window and display output in the client area.

9.5.2 Nonclient Area

The title bars, menu bar, window menu, minimizes and maximize buttons, sizing border, and scroll bars are referred to collectively as the window's nonclient area. The system

Int y; //starting Y point of window on screen Int width; //Width of the window from starting point Int height; //height of the window from starting Y point HWND hWndParent; //handle the parent window if any HMENU hMenu; // handle the Menu if any HINSTANCE hInstance; //handle of the instance LPVOID lpParam; //void parameter

);

//Documentation is described below

9.6.1 Class Name ( lpClassName )

[in] Pointer to a null-terminated string or a class atom created by a previous call to the

RegisterClass or RegisterClassEx function. The atom must be in the low-order word of

lpClassName ; the high-order word must be zero.

If lpClassName is a string, it specifies the window class name. The class name can be any

name registered with RegisterClass or RegisterClassEx , provided that the module that

registers the class is also the module that creates the window. The class name can also be

any of the predefined system class names

9.6.2 Window Name ( lpWindowName ).

[in] Pointer to a null-terminated string that specifies the window name.

If the window style specifies a title bar, the window title pointed to by lpWindowName is

displayed in the title bar. When using CreateWindow to create controls, such as buttons,

check boxes, and static controls, use lpWindowName to specify the text of the control.

When creating a static control with the SS_ICON style, use lpWindowName to specify the

icon name or identifier. To specify an identifier, use the syntax "#num".

9.6.3 Window Styles ( dwStyle )

[in] Specifies the style of the window being created. This parameter can be a combination

of Window Styles.

The following styles can be specified wherever a window style is required.

Style Meaning

WS_BORDER Creates a window that has a thin-line border.

WS_CAPTION Creates a window that has a title bar (includes the WS_BORDER style).

WS_CHILD Creates a child window. A window with this style

cannot have a menu bar. This style cannot be used with the WS_POPUP style.

WS_CHILDWINDOW Same as the WS_CHILD style.

WS_CLIPCHILDREN Excludes the area occupied by child windows when drawing occurs within the parent window. This style is used when creating the parent window.

WS_CLIPSIBLINGS Clips child windows relative to each other; that is, when a particular child window receives a WM_PAINT message, the WS_CLIPSIBLINGS style clips all other overlapping child windows out of the region of the child window to be updated. If WS_CLIPSIBLINGS is not specified and child windows overlap, it is possible, when drawing within the client area of a child window, to draw within the client area of a neighboring child window.

WS_DISABLED Creates a window that is initially disabled. A disabled window cannot receive input from the user. To change this after a window has been created, use EnableWindow.

WS_DLGFRAME Creates a window that has a border of a style typically used with dialog boxes. A window with this style cannot have a title bar.

WS_GROUP Specifies the first control of a group of controls. The group consists of this first control and all controls defined after it, up to the next control with the WS_GROUP style. The first control in each group usually has the WS_TABSTOP style so that the user can move from group to group. The user can subsequently change the keyboard focus from one control in the group to the next control in the group by using the direction keys.

You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use SetWindowLong.

WS_HSCROLL Creates a window that has a horizontal scroll bar.

WS_ICONIC Creates a window that is initially minimized. Same as the WS_MINIMIZE style.

WS_MAXIMIZE Creates a window that is initially maximized.

WS_MAXIMIZEBOX Creates a window that has a maximize button. Cannot be combined with the WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified.

WS_MINIMIZE Creates a window that is initially minimized. Same as the WS_ICONIC style.

WS_VSCROLL Creates a window that has a vertical scroll bar.

This is updated documents from Microsoft Help Desk.

Bitwise Inclusive-OR Operator ‘|’

The bitwise inclusive OR ‘|’ operator compares the values (in binary format) of each operand and yields a value whose bit pattern shows which bits in either of the operands has the value 1 (one). If both of the bits are 0 (zero), the result of the comparison is 0 (zero); otherwise, the result is 1 (one).

9.6.4 Horizontal Position of the Window ( x )

This member specifies the initial horizontal position of the window. For an overlapped or

pop-up window, the x parameter is the initial x-coordinate of the window's upper-left

corner, in screen coordinates. For a child window, x is the x-coordinate of the upper-left

corner of the window relative to the upper-left corner of the parent window's client area.

If this parameter is set to CW_USEDEFAULT, the system selects the default position for

the window's upper-left corner and ignores the y parameter. CW_USEDEFAULT is valid

only for overlapped windows; if it is specified for a pop-up or child window, the x and y

parameters are set to zero.

9.6.5 Vertical Position of the Window ( y )

This member specifies the initial vertical position of the window. For an overlapped or

pop-up window, the y parameter is the initial y-coordinate of the window's upper-left

corner, in screen coordinates. For a child window, y is the initial y-coordinate of the

upper-left corner of the child window relative to the upper-left corner of the parent

window's client area. For a list box, y is the initial y-coordinate of the upper-left corner of

the list box's client area relative to the upper-left corner of the parent window's client

area.

If an overlapped window is created with the WS_VISIBLE style bit set and the x

parameter is set to CW_USEDEFAULT, the system ignores the y parameter.

9.6.6 Width of the Window ( nWidth )

This specifies the width, in device units, of the window. For overlapped windows, nWidth

is either the window's width, in screen coordinates, or CW_USEDEFAULT. If nWidth is

CW_USEDEFAULT, the system selects a default width and height for the window; the

default width extends from the initial x-coordinate to the right edge of the screen, and the

default height extends from the initial y-coordinate to the top of the icon area.

CW_USEDEFAULT is valid only for overlapped windows; if CW_USEDEFAULT is

specified for a pop-up or child window, nWidth and nHeight are set to zero.

9.6.7 Height of the Window ( nHeight )

This member specifies the height, in device units, of the window. For overlapped

windows, nHeight is the window's height, in screen coordinates.

If nWidth is set to CW_USEDEFAULT, the system ignores nHeight.

9.6.8 Parent of the Window ( hWndParent )

This member is a HANDLE to the parent or owner window of the window being created.

To create a child window or an owned window, supply a valid window handle. This

parameter is optional for pop-up windows.

9.6.9 Menu of the Window ( hMenu )

This member is a HANDLE to a menu, or specifies a child-window identifier depending

on the window style. For an overlapped or pop-up window, hMenu identifies the menu to

be used with the window; it can be NULL if the class menu is to be used. For a child

window, hMenu specifies the child-window identifier, an integer value used by a dialog

box control to notify its parent about events. The application determines the child-

window identifier; it must be unique for all child windows with the same parent window.

9.6.10 Instance Handle ( hInstance )

This member is Application instance handle.

In Windows NT/2000 or later This value is ignored.

9.6.11 Long Param ( lpParam )

This member is a pointer to a value to be passed to the window through the

CREATESTRUCT structure passed in the lParam parameter the WM_CREATE

message. If an application calls CreateWindow to create a multiple document interface

(MDI) client window, lpParam must point to a CLIENTCREATESTRUCT structure.

9.6.12 Return Value

If the CreateWindow function is successful, then it returns a valid handle of the newly

created window. Otherwise it returns NULL.

a window procedure that the system calls whenever it has input for the window. The

window procedure processes the input and returns control to the system.

Note: We are presenting here a brief description of messages. Detailed discussion about

messages, message routing, message types, message filtering etc will be given in next

lectures.

9.8.1 Message Queuing

  • Operating system keeps the generated messages in a queue.
  • Every application has its own message queue.

Messages generated in a system first reside in System Message Queue, then dispatch to application message queue and to the windows procedure.

Windows programming is basically message driven programming.

9.8.2 Message Routing

The system uses two methods to route messages to a window procedure: posting

messages to a first-in, first-out queue called a message queue, a system-defined memory

object that temporarily stores messages, and sending messages directly to a window

procedure.

Messages posted to a message queue are called queued messages. They are primarily the

result of user input entered through the mouse or keyboard.

9.9 Window Procedure

Every window has its procedure that is called windows procedure. All messages that are

sent be DispatchMessage API or SendMessage API will be received by windows

procedure. So windows procedure is the particular address in memory that receives

messages. Windows operating system gets this address through registered window class

member lpfnWndProc. You have to provide address or name of window procedure in

windows class.

Windows procedure receives four parameters,

LRESULT (CALLBACK *WNDPROC) (HWND hWnd,UINT message,WPARAM

wParam,LPARAM lParam);

9.9.1 Handle to Window( hWnd )

This member is a HANDLE to the window to which message was sent.

9.9.2 Message Type( uMsg )

This member specifies the message type; the message could be a Mouse message,

character message, keyboard message, etc. Message is unsigned 32bit number.

9.9.3 Message’s WPARAM( wParam )

This specifies additional message information. The contents of this parameter depend on

the value of the uMsg parameter e.g. key down message keeps the key pressed value in

this parameter.

9.9.4 Message’s LPARAM( lParam )

This specifies additional message information. The contents of this parameter depend on

the value of the uMsg parameter e.g. mouse down messages keep information of mouse

pointer’s x and y position in this parameter.

9.9.5 Return Value

The return value is the result of the message processing and depends on the message sent

function.

9.10 Getting message from Message Queue

We can get message from message Queue by using GetMessage or PeekMessage APIs.

The GetMessage function retrieves a message from the calling thread's message queue

and also removes the message from the queue. And then function dispatches incoming

sent messages until a posted message is available for retrieval.

GetMessage inputs four parameters,

BOOL GetMessage()

(

LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax

)

lpMsg

[out] Pointer to an MSG structure that receives message information from the thread's message queue.

hWnd

[in] Handle to the window whose messages are to be retrieved. The window must belong to the calling thread. The following value has a special meaning.

wMsgFilterMin