Windows graphical applications (GUI) are based on message queues. Windows operating system has an event and graphical management server running as a background system process. This process acts as a message queue server and all windows applications act as message queue clients. Application calls GetMessage to receive a message from the event server. This is a blocking call and it waits for a message to arrive. The operating system receives keyboard inputs and mouse movements or clicks or other system events. All these are events are passed to the event and graphical management server. The server constructs a message object of type MSG and sends this to the message queue client which is the current application. There can be many applications running but the server decides to send the message to the application whose top-level window is focused on inputs. GetMessage blocking call in WinMain returns and this event MSG is further passed to DispatchMessage(). DispatchMessage() is an API that indirectly triggers a call back to window procedure which is registered by application with windows class. The application does not call this function directly, Win32 subsystem calls this function when the application dispatches the particular message. GetMessage and DispatchMessage are generally placed in an infinite loop. It keeps receiving new messages and further dispatches to wndproc till the application exits.
The WindowProc function is an application-defined function that processes messages sent to a window. The WNDPROC type defines a pointer to this callback function. WindowProc is a place holder for the application-defined function name. Application processes only messages those are needed and for the rest, it passes to DefWindowProc() for default handling in Win32 subsystem.
- hwnd - Handle to the window.
- uMsg - Specifies the message.
- wParam - Specifies additional message information. The contents of this parameter depend on the value of the uMsg parameter.
- lParam -Specifies additional message information. The contents of this parameter depend on the value of the uMsg parameter.
The return value is the result of the message processing and depends on the message sent.
About our authors: Team EQA
Where is WinMain() function in MFC application ?
MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.
What is the utility of CWinApp class?
This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...
Basic steps in Win32 GUI Application with source code.
Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.
What is a Window CallBack procedure and what is its utility?
DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.
What are LPARAM and WPARAM in window proc function?
LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.
What are the basic steps of a typical MFC based application?
We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average