Home > Back-end >  MFC message callback function
MFC message callback function

Time:09-22

When I was at the code had some grammar problems: under the reference of the great god some opinions
Typedef void (AFX_MSG_CALL CCmdTarget: : * AFX_PMSG) (void);
And this can transform each other here
(AFX_PMSG) (AFX_PMSGW) (static_cast & lt; Void (AFX_MSG_CALL CWnd: : *) (CWnd *) & gt; (& amp; ThisClass: : OnSetFocus)},
The background: due to the MFC to do a lot of messages, message processing functions have different function parameters, so can't find a unified interface, MFC process here into all the functions (return type and parameter type, number) to the return type is empty, the parameter types as empty function,
Eg: AFX_PMSG PFN=(AFX_PMSG) (AFX_PMSGW) (static_cast & lt; Void (AFX_MSG_CALL CWnd: : *) (CWnd *) & gt; (& amp; ThisClass: : OnSetFocus),
That this case can be turned, but can't direct call (similar to strong can turn to zero for any type of object, but not be able to access his members)
* PFN (CWnd *),//can't compile
So in the MFC way is to define a Shared body, save memory
The union MessageMapFunctions
{
AFX_PMSG PFN.//generic member function pointer

BOOL (AFX_MSG_CALL CCmdTarget: : * pfn_b_D) (CDC *);
.
} and a logo return values and parameters of
Enum AfxSig
{
AfxSig_end=0,//[marks the end of the message map]

AfxSig_b_D_v,//BOOL (CDC *)
AfxSig_b_b_v,//BOOL (BOOL)
AfxSig_b_u_v,//BOOL (UINT)
AfxSig_b_h_v,//BOOL (HANDLE)
.
}
According to the AfxSig, the callback function of PFN callback function to select parameters,
Case AfxSigCmd_b:
//normal command or control notification
ASSERT (CN_COMMAND==0);//CN_COMMAND same as BN_CLICKED
ASSERT (pExtra==NULL);
BResult=(pTarget - & gt; * MMF. PfnCmd_b_v ());
break;

Case AfxSigCmd_RANGE:
//normal command or control notification in a range
ASSERT (CN_COMMAND==0);//CN_COMMAND same as BN_CLICKED
ASSERT (pExtra==NULL);
(pTarget - & gt; * MMF. PfnCmd_v_u) (nID);
break;
Is then one thing ah,

CodePudding user response:

By the way, add a question: static library and dynamic library itself under Windows will be used, but encountered a problem
The main function can be made into a static link library by another module, but why can't make it dynamic library to use other modules link? To solve the MFC is WinMain is how to do it

CodePudding user response:

Attached to the second demonstration:
http://www.zhangley.com/article/mfc-winmain/
  • Related