Click here to Skip to main content
11,924,800 members (57,600 online)
Rate this:
Please Sign up or sign in to vote.
See more: VC8.0 C++
How can we create our own MESSAGE in MFC?

I Googled but i didn't get any concrete idea on this and also the steps to create the same. So kindly please guide me to understand and create own message in MFC.
Thanks Smile | :)
Posted 31-May-11 12:49pm
Manfred R. Bihy 31-May-11 18:02pm
Please reconsider you question. Title talks about a message handler whereas you question itself talks about a creating your own message. "Unclear" is putting it kindly.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

you can use any UINT value as a messege value. But it should be unique from already existing values. So generally what we does to create a user defined message is

#define MY_CUSTOM_MSG WM_APP + 1

you can sent/post the message using the sendmessage or postmessage function.

And you can add an event handler for this message inside the messagemap as follows.


It is important that you define the OnMyMessage as follows

LRESULT OnMyMessage (WPARAM wParam, LPARAM lParam);

Please note that this kind of message is local to your process, if you want to sent message from one process to another, then you have to create the mesasge using RegisterWindowMessage[^] function. The message map entry for this type of message is ON_REGISTERED_MESSAGE.
Chandru080 1-Jun-11 0:17am
Well Explained. my 5
Naveen 1-Jun-11 0:24am
Joined a new company and in here all the external mails and social networking sites are blocked. So back in codeproject and MSDN for time pass :)
SP 24 1-Jun-11 1:22am
+ 5 :)
Chandru080 1-Jun-11 1:08am
Good.. and All the best in your new environment :)
And its worth to be here in code project :)
Albert Holguin 1-Jun-11 16:20pm
There's a few things that aren't quite true in your explanation... but its sufficient for OP... my 4
Naveen 1-Jun-11 22:04pm
Could you please elaborate?
Albert Holguin 1-Jun-11 22:10pm
well "you can use any UINT value as a message value", not true, has to be above WM_APP, hence the offset, values below that are reserved for WM_ messages... "should be unique from already existing values", not true, it has to be unique for the specific message catcher, not for the application...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151125.3 | Last Updated 1 Jun 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100