MFC user defined message

Posted on 2006-03-29
Last Modified: 2008-03-17
I'd like to create a user defined message to have a thread pass a message back to the main MFC application.  

My understanding of how to do this is as follows;

1. Register the message:
static const int WMU_RUN_COMPLETE = RegisterWindowMessage("WMU_RUN_COMPLETE");

2. Declare the function that will eventually handle the message;
afx_msg LRESULT OnRunComplete(WPARAM wParam, LPARAM lParam);

3. Add it to the message map;

4. Register the same message name in my thread;
static const int WMU_RUN_COMPLETE = RegisterWindowMessage("WMU_RUN_COMPLETE");

5. Send the message from my thread;
SendMessage(hwnd, MY_WM_RUN_COMPLETE, (WPARAM)0, (LPARAM)0);

I haven't even gotten to steps 4 and 5 yet.  When I compile, I get an undeclared identifier, WMU_RUN_COMPLETE, because of the reference in the message map.

Where am I supposed to put the WMU_RUN_COMPLETE declaration and RegisterWindowMessage?

Note, this is a dialog based application and not a full document view app.

This is the first time I've tried this, so any other comments would be appreciated.

Question by:JohnSantaFe
    LVL 48

    Accepted Solution

    Place the line
    static const int WMU_RUN_COMPLETE = RegisterWindowMessage("WMU_RUN_COMPLETE");

    to h-file and include it to every cpp file where it is used.

    Author Comment


    I was trying to declare it as a public member of the clas : {

    I moved it up out of the class but still in the .h file and that worked.

    Thanks for the tip.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    has12 challenge 13 52
    How to silent print from safari browser 6 97
    Fix45 challenge 15 65
    scoresIncreasing challenge 10 47
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now