Click here to Skip to main content
13,453,957 members (44,153 online)
Click here to Skip to main content
Add your own
alternative version


58 bookmarked
Posted 12 Aug 2004

How to make a Message Only Window

, 12 Aug 2004
Rate this:
Please Sign up or sign in to vote.
An article on how to make a message only window.


An article on making a message only window class and why this is a useful thing to do.


According to Microsoft:

A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.

Simpler: You can send messages (PostMessage and SendMessage) to it. If you have a class which is derived from it, you can have it reacting to messages from other areas of code in a similar fashion to a normal window.

Benefits of using a message only window

  • Free queue for messages.

    What do you mean?

    If your system is message based from some sort of external IO say, and you are in need of a queuing facility, then your application can use PostMessage to post messages to the hidden window. These messages will be queued in the normal Windows message queue.

  • Inter/intra process communication

    What do you mean?

    Another part of your application (or an external application) can handle the arrival of these messages.

How do I make one?

It is pretty easy actually.

In the class that is to deal with the messages, follow this procedure:

  1. Make it inherit from CWnd, even if it means you multiply inherit.
    class CMyMessageOnlyWindowClass : public CWnd
  2. In the constructor or some other useful initialization type function, use the following code (change where needed).
    CString wnd_class_name = ::AfxRegisterWndClass(NULL);
    BOOL created = this->CreateEx(0,wnd_class_name, 
        "CMyMessageOnlyWindowClass",0 ,0 ,0 ,0 ,0 ,HWND_MESSAGE,0);
  3. Either register your own Windows message:
  4. Or use something easier like:
    const UINT MY__MESSAGE = WM_USER+14;
  5. Create your message handling function in your .h and .cpp files.

    .h first

    afx_msg LRESULT DealWithMyRegisteredMsg(WPARAM wParam, LPARAM lParam);


    afx_msg LRESULT DealWithMyMsg(WPARAM wParam, LPARAM lParam);

    Now, the cpp file

    LRESULT CMyMessageOnlyWindowClass::DealWithMyRegisteredMsg(WPARAM wParam, 
                                                                LPARAM lParam)
         AfxMessageBox("Chris is ready for a beer"); 
         return LRESULT(true); 


    LRESULT CMyMessageOnlyWindowClass::DealWithMyMsg(WPARAM wParam, 
                                                          LPARAM lParam)
         AfxMessageBox("Chris is ready for a beer"); 
         return LRESULT(true); 
  6. Add the message map:
    BEGIN_MESSAGE_MAP(CMyMessageOnlyWindowClass, CWnd) 
         // or ON_MESSAGE(BLAH_MESSAGE,DealWithMyRegisteredMsg)
  7. Now, go back to your .h file, and at the very end of your class - after all the functions and variables and so on (but before the “};”), – stick:


    This says “I will be using a message map in my class” (well, we have just defined it).

  8. Now, when you want to post to this window, all you need is the handle to it…or a pointer to it, and you will find it should behave just like a normal window, only you can’t see it etc.

What else do I need to know?

  1. FindWindow: If you want to use FindWindow, you need to pay attention to the MSDN which says… "To find message-only windows, specify HWND_MESSAGE in the hwndParent parameter of the FindWindowEx function. In addition, FindWindowEx searches message-only windows as well as top-level windows if both the hwndParent and hwndChildAfter parameters are NULL."
  2. Multiple Inheritance: When multiply inheriting, the CWnd needs to come first, for example;
    class CMyMessageOnlyWindowClass : public CWnd, public COtherClass
  3. That's about it, remember: you can't view (see) this window!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
Australia Australia
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 3 Pin
pcpro1785-Nov-10 10:38
memberpcpro1785-Nov-10 10:38 
GeneralUse "message" as window class up from Win2000 Pin
owmarr24-Nov-09 10:55
memberowmarr24-Nov-09 10:55 
GeneralRe: Use "message" as window class up from Win2000 Pin
John Gonzalez25-Nov-09 9:25
memberJohn Gonzalez25-Nov-09 9:25 
GeneralRe: Use "message" as window class up from Win2000 Pin
owmarr25-Nov-09 9:43
memberowmarr25-Nov-09 9:43 
GeneralAn ActiveX control Pin
AlexEvans11-Jan-06 16:29
memberAlexEvans11-Jan-06 16:29 
Generalnon-MFC Message-Only window Pin
DanLedford9-Dec-05 6:38
memberDanLedford9-Dec-05 6:38 
Can I use a Message-Only window in a non-MFC app?

I want to use the Windows Messaging APIs for intratask communications between a COM DLL (that is not an MFC DLL) and a Console Application (*.exe, that is also not an MFC exe).

From all that I have seen, it appears the Message-Only windows can only be used by MFC apps.

Can this be done???

Dan L

Dan L
Generalhello is it possible to check the ready state of the normal window and other applications Pin
1lokii28-Dec-04 18:59
member1lokii28-Dec-04 18:59 
GeneralAbout Destruction of Message Only Windows Pin
Victor Ochoa3-Sep-04 9:44
memberVictor Ochoa3-Sep-04 9:44 
GeneralRe: About Destruction of Message Only Windows Pin
bryce3-Sep-04 14:29
memberbryce3-Sep-04 14:29 
GeneralRe: About Destruction of Message Only Windows Pin
Victor Ochoa4-Sep-04 8:40
memberVictor Ochoa4-Sep-04 8:40 
QuestionSubliminal message? Pin
Chris Maunder30-Aug-04 3:27
adminChris Maunder30-Aug-04 3:27 
GeneralYou forgot to mention WINVER Pin
Nathan Holt at CCEI18-Aug-04 12:31
memberNathan Holt at CCEI18-Aug-04 12:31 
GeneralRe: You forgot to mention WINVER Pin
bryce18-Aug-04 13:06
memberbryce18-Aug-04 13:06 
GeneralRe: You forgot to mention WINVER (apology) Pin
Nathan Holt at CCEI18-Aug-04 13:47
memberNathan Holt at CCEI18-Aug-04 13:47 
GeneralWM_USER Query Pin
Tom Brennan_aka_Irish_Wiz14-Aug-04 2:06
memberTom Brennan_aka_Irish_Wiz14-Aug-04 2:06 
GeneralRe: WM_USER Query Pin
Ravi Bhavnani14-Aug-04 5:58
memberRavi Bhavnani14-Aug-04 5:58 
GeneralRe: WM_USER Query Pin
Nathan Holt at CCEI18-Aug-04 4:50
memberNathan Holt at CCEI18-Aug-04 4:50 
Generalquestion Pin
Todd Smith13-Aug-04 7:44
memberTodd Smith13-Aug-04 7:44 
GeneralNice! Pin
Ravi Bhavnani13-Aug-04 3:01
memberRavi Bhavnani13-Aug-04 3:01 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180321.1 | Last Updated 13 Aug 2004
Article Copyright 2004 by bryce
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid