Lresult callwindowproc (wndproc lpprevwndfunc, hwnd. uint MSG, wparam
Wparam, lparamiparam );
Function. callwindowproc transmits the specified message information to the specified window. lpprevwndfunc is the window message processing function pointer (function name ),
Hwnd is used to accept the form handle.
Defwindowproc (hwnd. uint MSG, wparam, lparamiparam) is the default message processing function for Windows to process messages.
Function: This function calls the default window process to provide default processing for any window messages that are not processed by the application. This function ensures that each message is processed. When calling the defwindowproc function, use the same parameters received by the window process.
The key differences between the two are: callwindowproc is to send a message to a processing function (including a custom message processing function), and defwindowproc is to send a message to Windows by default) message Processing function.
If you understand the difference, you can understand,
Calwindowpro (defwindowproc, hwnd, MSG, wparam, lparam) and
Defwindowproc (hwnd, MSG, wparam, lparam); the execution results are the same at this time.
In Windows, when the window is displayed, it can receive a steady stream of messages from the system, and then the window needs to process these messages, therefore, a function is required to process these messages. The API defines a function as a callback function. When the system needs to send a message to the window, it calls the callback function WindowProc provided by the window. If the WindowProc function does not process the message, you can turn it to the DefWindowProc function for processing. This is the default message processing function of the system. When you press the menu or click a window, the window needs to run the message processing function.
The WindowProc function declaration is as follows:
Lresult callback WindowProc (HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
Hwnd is the handle of the current window.
UMsg is a message sent by the system.
WParam is a message parameter.
LParam is a message parameter.
This function must be a static function, that is, a global function. The address has been determined during compilation. Because it needs to be set in the registered window type, as follows:
#008 ATOM MyRegisterClass (HINSTANCE hInstance)
#009 {
#010 WNDCLASSEX wcex;
#011
#012 wcex. cbSize = sizeof (WNDCLASSEX );
#013
#014 wcex. style = CS_HREDRAW | CS_VREDRAW;
#015 wcex. lpfnWndProc = WndProc;
Row 15th is the message processing function of the window.
The DefWindowProc function declaration is as follows:
LRESULT DefWindowProc (HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
This function parameter is the same as the above function.
However, it processes all default messages.
Examples of calling these two functions are as follows:
#001 //
#002 // function: WndProc (HWND, UINT, WPARAM, LPARAM)
#003 //
#004 // purpose: to process messages in the main window.
#005 //
#006 // Cai junsheng 2007/07/12
#007 //
#008 lresult callback WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
#009 {
#010 int wmId, wmEvent;
#011 PAINTSTRUCT ps;
#012 HDC hdc;
#013
#014 switch (message)
#015 {
#016 case WM_COMMAND:
#017 wmId = LOWORD (wParam );
#018 wmEvent = HIWORD (wParam );
#019 // menu option command response:
#020 switch (wmId)
#021 {
#022 case IDM_ABOUT:
#023 dialogbox (hinst, makeintresource (idd_aboutbox), hwnd, about );
#024 break;
#025 case idm_exit:
#026 destroywindow (hwnd );
#027 break;
#028 default:
#029 return defwindowproc (hwnd, message, wparam, lparam );
#030}
#031 break;
#032 case wm_paint:
#033 HDC = beginpaint (hwnd, & PS );
#034 //
#035 endpaint (hwnd, & PS );
#036 break;
#037 case wm_destroy:
#038 postquitmessage (0 );
#039 break;
#040 default:
#041 return defwindowproc (hwnd, message, wparam, lparam );
#042}
#043 return 0;
#044}
8th rows define message processing functions
The first line starts Processing Based on different messages.
Both lines 29th and 41st call the defwindowproc function to process unprocessed messages.
With the window message processing function, you can respond to different messages and implement various functions.