Dave's Brain

Browse - Programming Tips - How do I send a custom message to myself using MFC ?

Date: 2014jul22
Framework: MFC
Language: C/C++
OS: Windows

Q.  How do I send a custom message to myself using MFC ?

A.
In your .h file:

// Define your message as some offset from WM_APP enum { WM_MYMESSSAGE = WM_APP + 1 }; // With the other afx_msg's: afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
In your .cpp file:
// Add it so the message map using ON_MESSAGE() BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MYMESSAGE, OnMyMessage) END_MESSAGE_MAP() // Finally your function LRESULT CMyDialog::OnMyMessage(WPARAM wParam, LPARAM lParam) { // Do whatever you want now return 0; } // To send the message use: PostMessage(WM_MYMESSAGE);

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.