It is possible to override the cwnd :: windowproc
function to handle the message of an external application, or this function is used as auxiliary for objects CWND
?
Determination of the window procedure WindowProc (WinAPI)
Lresult Callback WindowProc (
HWND HWND,
UINT Message,
WParam WParam,
LPARAM LPARAM)
{
Switch (Message)
{
Case WM_Destroy:
PostQuitmessage (0);
Break;
Default:
Return DefwindowProc (HWND, Message, Wparam, LParam);
}
Return 0;
}
Window procedure definition afxwndproc (MFC)
Lresult Callback AFXWndProc (
HWND HWND,
Uint nmsg,
WParam WParam,
LPARAM LPARAM)
{
// Special Message Which Identifies The Window As using
AFXWNDPROC.
if (nmsg == wm_queryafxwndproc)
Return 1;
// All Other Messages Route Through Message Map
CWND * PWND = CWND :: FROMHANDLEPERMANENT (HWND);
Assert (PWND! = NULL);
Assert (PWND- & GT; M_HWND == HWND);
RETURN AFXCALLWNDPROC (PWND, HWND, NMSG, WPARAM, LPARAM);
}
How to properly organize the redefinition of the MFC window procedure? And if not difficult, explain the principal difference. Thank you
The question is related to CMENU :: INSERTMENU – message processing
Answer 1, Authority 100%
To override the window procedure, you do not have to use MFC tools for this. Simply write your windowproc
function and install it with SetWindowlongProc (HWND, GWL_WNDPROC, (Long_PTR) NewWndProc).
WndProc PorigProc = (WndProc) SetWindowLongProc (HWND, GWL_WNDPROC, (Long_PTR) newwndproc);
// New Window Procedure - Global or Static (Static) Class Function
Lresult Callback NewwndProc (Hwnd Hwnd, Uint Umsg, WPARAM WPARAM, LPARAM LPARAM)
{
Switch (UMSG)
{
Case WM_Command:
If (LOWORD (WPARAM) == ID_EXPCATXML)
{
MessageBox (NULL, "Hello", "", MB_OK);
Return 0;
}
Break;
}
Return CallWindowProc (Porigproc, HWND, UMSG, WPARAM, LPARAM);
}
afxwndproc is a special case of the usual window procedure
Answer 2
Standard CWND :: WondowProc
should work normally, but I can not understand exactly where to make a mistake. Did strictly according to the instructions:
Plugin.h
class plugin: public cwnd
{
...
Protected:
Virtual Lresult WindowProc (Uint UMSG, WPARAM WPARAM, LPARAM LPARAM);
};
plugin.cpp
lresult plugin :: windowproc (uint umsg, wparam wparam, lparam lparam)
{
Switch (UMSG)
{
Case WM_Command:
If (LOWORD (WPARAM) == ID_EXPCATXML)
{
AFXMESSAGEBOX (L "TEST");
Return 0;
}
Break;
}
Return CWND :: WindowProc (UMSG, WPARAM, LPARAM);
}
Here is a similar question on MSDN
can you need to add auxiliary method to the Plugin class message card?