ColonelPanic

MFC Message Only CWnd subclass

Apr 23rd, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. class MessageSink : public CWnd
  2. {
  3. public:
  4.     MessageSink() : windowClassName(::AfxRegisterWndClass(NULL))
  5.     {
  6.     }
  7.  
  8.     virtual ~MessageSink()
  9.     {
  10.         if(GetSafeHwnd())
  11.         {
  12.             ::DestroyWindow(GetSafeHwnd());
  13.         }
  14.     }
  15.  
  16.     BOOL Create()
  17.     {
  18.         return CreateEx(
  19.             NULL,
  20.             windowClassName,
  21.             TEXT("Message Only Window"),
  22.             0,
  23.             0, 0, 0, 0,
  24.             HWND_MESSAGE,
  25.             NULL,
  26.             /* user data */ NULL);
  27.     }
  28.  
  29. protected:
  30.     DECLARE_MESSAGE_MAP()
  31.  
  32. private:
  33.     afx_msg LRESULT OnGoesNowhereDoesNothing(WPARAM, LPARAM)
  34.     {
  35.         ::AfxMessageBox(TEXT(__FUNCTION__));
  36.         return 0;
  37.     }
  38.  
  39.     afx_msg void OnDestroy()
  40.     {
  41.         ::AfxMessageBox(TEXT(__FUNCTION__));
  42.     }
  43.  
  44.     CString windowClassName;
  45. };
  46.  
  47. BEGIN_MESSAGE_MAP(MessageSink, CWnd)
  48.     ON_MESSAGE(WM_USER + 1, OnGoesNowhereDoesNothing)
  49.     ON_WM_DESTROY()
  50. END_MESSAGE_MAP()
Advertisement
Add Comment
Please, Sign In to add comment