2008. 12. 10. 08:27

How to use a user-defined message

  1. 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

  2. In your document-class, create a member-variable to hold a pointer to the window you want to process the message.
     
  3. CView *m_pView;
    // This variable must be initialized in your view-class.
  4. 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);
  5. 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();
  6. In the processing view source file, add the following in the message map:
     
  7. ON_REGISTERED_MESSAGE(msgFileChange, OnFileChange)
  8. 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