Monday, 19 September 2011

Message only window (MFC)

As expected: message only window cannot post messages to its "parent". CWnd::PostMessage() invoked on HWND_MESSAGE crashes with access violation:

class CMsgOnlyWnd : public CWnd
{
   ...
public:
   Initialize();
   SendMsgToParent();
   ...
}

CMsgOnlyWnd::Initialize()
{
   ...
   CreateEx(0, ::AfxRegisterWndClass(NULL), "MsgOnlyWnd", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, NULL);
   ...
}

CMsgOnlyWnd::SendMsgToParent()
{
   GetParent()->PostMessage(...);
}

Links and references:
Message-Only Windows (MSDN)
How to make a Message Only Window
How to create a hidden window in C++
Post a Comment