Window Proc and DefWindowProc

What Does CContainedWindowT Process?

If you are running an application when trying to shut down Windows, it will show you the “This app is preventing shutdown” message. It is important to close all applications before attempting to shut down the computer.

Some causes of the “This app is preventing Windows from shutting down” error include corrupted files. To fix this issue, you can use System Restore.


DefWindowProc provides default processing for any window messages that an application doesn’t handle. It ensures that every message is processed. DefWindowProc is called with the same parameters received by the window procedure that received the message. The Msg parameter specifies the message data and the lParam and wParam members specify additional message information.

If an application subclasses a window class, it should save the function pointer of the original window procedure for that class. This is because an unrecoverable system error can occur if the function pointer is lost. This can be accomplished by using the SetClassLong function, which stores the address of the original window procedure for the class.

After the user releases the mouse button, DefWindowProc sends a WM_SYSCOMMAND message to the window procedure that informs it that the user has finished resizing the window. DefWindowProc then receives more messages that reposition and repaint the window. Finally, DefWindowProc sends the window a WM_EXITSIZEMOVE message to exit the resize modal loop.


There are hundreds of Windows messages, including those generated by mouse button clicks, key presses and other events. DefWindowProc allows you to use these messages to perform various actions. Some examples include WM_CREATE, sent when a window is created, WM_PAINT, used for painting a window, and WM_DESTroy, used to close a window. Each message contains an identifier (Msg), an hwnd handle, and two message data integers, wParam and lParam. The application function can check the Msg identifier and either use or ignore the wParam and lParam information.

This class also includes a public property that sets the member variable m_lOrigWndProc. This member variable is needed to pass the address of the original window procedure to the subclassed window. This is important because if the original window procedure is removed from memory, the subclassed windows will attempt to call this function using an invalid pointer, which could cause the application to crash. DefWindowProc handles this by checking the Msg identifier and then calling the hwnd’s window procedure function, if it exists.


The CContainedWindowT class has several methods that you can use to create and manage windows contained within another window. These methods include RegisterWindowClass, DispatchMessage, TranslateMessage, and DisableSubclass. The class also supports two types of subclassing: instance and global. Instance subclassing allows you to replace the window procedure address of a single window, while global subclassing allows you to replace the window procedures for all instances of a class.

DispatchMessage passes the window handle, message identifier, and two message parameters (LParam and WParam) to the “Window Proc”. The “Window Proc” can extract additional information from these parameters, such as the time when the message was posted or the cursor position in a mouse message.

The lParam member contains the new width and height values, which are 16-bit values packed into one 32- or 64-bit number. To retrieve these values, you need to use the LOWORD and HIWORD macros in the header file WinDef.h. The msg member contains a description of the message.


Every window uses a “Window Proc,” a function that processes messages sent to it. The Window Proc is set by the Class that the window belongs to; each registered Class has a unique Window Proc. A window procedure receives the hWnd parameter, which identifies the window it is processing; the lParam member carries additional message information.

A window procedure can discard system keystroke messages such as WM_SYSKEYDOWN and WM_SYSKEYUP. Nonsystem keystroke messages, on the other hand, are primarily for use by application windows. A window procedure can process these messages by passing them to DefWindowProcD.

The DefWindowProcD function performs default processing for any window messages that an application doesn’t handle. It identifies the window that received the message by using the hWnd parameter; wMsg and lParam specify additional message information, which varies by message type. Once the message is processed, the DefWindowProcD function removes the subclassed window procedure from the message queue. As a result, the window is able to pull new messages from its queue.

Return to the home screen

Leave a Reply

Your email address will not be published. Required fields are marked *