2008. 12. 10. 08:27
How to use a user-defined message
2008. 12. 10. 08:27 in 3. Implementation/MFC
- Create a user-defined message with
::RegisterWindowMessage
like this:
const UINT msgFileChange = ::RegisterWindowMessage("FILECHANGE");Put this in the application's header file so that you can use this everywhere in your application
- In your document-class, create a member-variable to hold a pointer to the window you want to process the message.
CView *m_pView; // This variable must be initialized in your view-class.
- In the method called by the thread, post the message to the processing window.
// You can pass wparam, lparam if you wish m_pView->PostMessage(msgFileChange); - In the processing view header file, add the following in the message map functions:
// when you pass wparam, lparam add parameters to this function afx_msg void OnFileChange(); - In the processing view source file, add the following in the message map:
ON_REGISTERED_MESSAGE(msgFileChange, OnFileChange)
- Add the source code for
OnFileChange
in the processing view source file.
void CProcessView::OnFileChange() { CMyDocument *pDoc = GetDocument(); pDoc->UpdateAllViews(); }
From : http://www.codeproject.com/KB/files/filechange.aspx