Search code examples
mfcwindows-ce

What is the difference between ON_WM_CTLCOLOR_REFLECT() and ON_WM_CTLCOLOR() in VS2008?


The question is like this: I write a windows application in VS2005, building success. Then I transfer it to VS2008, when I build the program, there will be an error messsage shows: error C4867: 'CGroupBox::CtlColor': function call missing argument list; use '&CGroupBox::CtlColor' to create a pointer to member the message map is as follows:

BEGIN_MESSAGE_MAP(CGroupBox, CButton)
//{{AFX_MSG_MAP(CGroupBox)
ON_WM_PAINT()
ON_WM_CTLCOLOR_REFLECT()
//ON_WM_CTLCOLOR()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP

END_MESSAGE_MAP()

the function is is as follows:

HBRUSH CGroupBox::CtlColor(CDC* pDC, UINT nCtlColor) 
{
GetParent()->Invalidate();
return NULL;
}

but if I change to the ON_WM_CTLCOLOR() ,I can get a successful build.


Solution

  • The error message is because the signature of the message handler doesn't match the signature you're using. Look up the signatures for ON_WM_CTLCOLOR_REFLECT() and ON_WM_CTLCOLOR() on MSDN to get the correct ones.

    As to the question in your title, some controls normally send their notification messages to their parent. Which is inconvenient, because every time you re-use that control, you need to change its parent window. Therefore MFC has 'reflection' support, which is basically a way of saying 'when you receive a notification from a child control, first try bouncing it back to that control to see if that control knows how to deal with it itself.'

    Read the details on https://web.archive.org/web/20101229015404/http://msdn.microsoft.com/en-us/library/eeah46xd(v=vs.80).aspx .