Click here to Skip to main content
15,925,602 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Process Priority Pin
Bob Stanneveld13-Aug-05 6:07
Bob Stanneveld13-Aug-05 6:07 
GeneralRe: Process Priority Pin
S. Senthil Kumar13-Aug-05 7:01
S. Senthil Kumar13-Aug-05 7:01 
GeneralATL Pin
Pham van hoi12-Aug-05 22:35
Pham van hoi12-Aug-05 22:35 
GeneralSDI Doc/View, synchronizing splitter windows w/ DirectX Pin
dtowers2312-Aug-05 19:32
dtowers2312-Aug-05 19:32 
GeneralUnion member cast and MFC message handling Pin
LiYS12-Aug-05 18:25
LiYS12-Aug-05 18:25 
GeneralRe: Union member cast and MFC message handling Pin
Jose Lamas Rios12-Aug-05 18:39
Jose Lamas Rios12-Aug-05 18:39 
GeneralRe: Union member cast and MFC message handling Pin
LiYS12-Aug-05 20:12
LiYS12-Aug-05 20:12 
GeneralRe: Union member cast and MFC message handling Pin
PJ Arends12-Aug-05 22:12
professionalPJ Arends12-Aug-05 22:12 
The MFC message map is just an array of message map structures. When you add a macro to the message map of your class all it does is add a structure to the array.

The macro BEGIN_MESSAGE_MAP(class, baseclass) sets up the message map, and declares the start of the array of AFX_MSGMAP_ENTRY structures.
struct AFX_MSGMAP_ENTRY
{
	UINT nMessage;   // windows message
	UINT nCode;      // control code or WM_NOTIFY code
	UINT nID;        // control ID (or 0 for windows messages)
	UINT nLastID;    // used for entries specifying a range of control id's
	UINT nSig;       // signature type (action) or pointer to message #
	AFX_PMSG pfn;    // routine to call (or special value)
};
Each entry in the message map adds another entry to the message map array.

For instance, ON_WM_CREATE is defined as
#define ON_WM_CREATE() \
	{ WM_CREATE, 0, 0, 0, AfxSig_is, \
		(AFX_PMSG)(AFX_PMSGW)(int (AFX_MSG_CALL CWnd::*)(LPCREATESTRUCT))&OnCreate },
So it sets nMessage to WM_CREATE,
nCode, NID, and nLastID to 0,
nSig to AfxSig_is (an enum defined in afxmsg.h - a function that returns int and takes a single parameter that is a pointer)
and pfn is set as a pointer to the function to call.

END_MESSAGE_MAP() simply adds one last entry to the array that is all zeroes, and closes the array declaration.

Now in CWnd::OnWndMsg what happens is that the the code searches through the message map for the class, looking for the entry for the message (WM_CREATE). When it finds it, it gets the sig (AfxSig_is) and uses the sig and the union MessageMapFunctions (defined in afximpl.h) to call the function, complete with the correct parameters and return type.




"You're obviously a superstar." - Christian Graus about me - 12 Feb '03

"Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04

"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05

Within you lies the power for good - Use it!
GeneralRe: Union member cast and MFC message handling Pin
LiYS12-Aug-05 23:58
LiYS12-Aug-05 23:58 
GeneralRe: Union member cast and MFC message handling Pin
Tim Smith13-Aug-05 5:02
Tim Smith13-Aug-05 5:02 
GeneralRe: Union member cast and MFC message handling Pin
PJ Arends13-Aug-05 6:51
professionalPJ Arends13-Aug-05 6:51 
GeneralIt seems that the MSComm can only transfer 40 bytes each time. Pin
pantao55112-Aug-05 17:37
pantao55112-Aug-05 17:37 
QuestionHow to get all zone in the DNS server? Pin
qtnl12-Aug-05 16:57
qtnl12-Aug-05 16:57 
Questionplease help me:build .c source file with VC++6,error LNK2001? Pin
fbzok12-Aug-05 16:50
fbzok12-Aug-05 16:50 
AnswerRe: please help me:build .c source file with VC++6,error LNK2001? Pin
Jose Lamas Rios12-Aug-05 18:32
Jose Lamas Rios12-Aug-05 18:32 
AnswerRe: please help me:build .c source file with VC++6,error LNK2001? Pin
sunit512-Aug-05 22:04
sunit512-Aug-05 22:04 
AnswerRe: please help me:build .c source file with VC++6,error LNK2001? Pin
fbzok12-Aug-05 22:08
fbzok12-Aug-05 22:08 
GeneralRe: please help me:build .c source file with VC++6,error LNK2001? Pin
Saurabh.Garg12-Aug-05 22:59
Saurabh.Garg12-Aug-05 22:59 
AnswerRe: please help me:build .c source file with VC++6,error LNK2001? Pin
fbzok12-Aug-05 23:18
fbzok12-Aug-05 23:18 
AnswerRe: please help me:build .c source file with VC++6,error LNK2001? Pin
fbzok13-Aug-05 4:30
fbzok13-Aug-05 4:30 
Generalrun single instance of app Pin
elephantstar12-Aug-05 12:17
elephantstar12-Aug-05 12:17 
GeneralWorking dir in Registry Pin
RickyC12-Aug-05 9:12
RickyC12-Aug-05 9:12 
GeneralRe: Working dir in Registry Pin
David Crow12-Aug-05 10:01
David Crow12-Aug-05 10:01 
GeneralRe: Working dir in Registry Pin
RickyC12-Aug-05 10:31
RickyC12-Aug-05 10:31 
General3rd party Menu Check State... Pin
Jumpin' Jeff12-Aug-05 8:31
Jumpin' Jeff12-Aug-05 8:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.