CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Posts
    79

    Basic messaging question

    InInitInstance I send a message to send a message to ManFrame
    but ManFrame never get the message. It looks like this,

    AfxGetMainWnd()->SendMessage(UM_CREATE_THREAD, 0, 0);

    In MainFrame.h I have added afx_msg void OnCreateThread();
    , like below

    protected:
    //{{AFX_MSG(CMainFrame)
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnFilePrint();
    afx_msg void OnFilePrintPreview();
    //}}AFX_MSG
    afx_msg void OnCreateThread();
    DECLARE_MESSAGE_MAP()


    In MainFrame.cpp I have added ON_COMMAND(UM_CREATE_THREAD, OnCreateThread) like below

    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ON_WM_CREATE()
    ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
    //}}AFX_MSG_MAP
    ON_COMMAND(UM_CREATE_THREAD, OnCreateThread)
    END_MESSAGE_MAP()

    Also in MainFrame.cpp I have added

    void CMainFrame::OnCreateThread()
    {
    AfxMessageBox("Got the message");
    }

    But I never get the "Got the message" printed on the screen.
    What is it I'm missing. Probably this is very basic but I would be very happy for an answer.

  2. #2
    Join Date
    Jan 2004
    Posts
    59
    ON_COMMAND is used for WM_COMMAND messages. You are using a user defined message. Change ON_COMMAND to ON_MESSAGE.

  3. #3
    Join Date
    Jul 2003
    Posts
    79
    Thank you very much.

  4. #4
    Join Date
    Jan 2004
    Posts
    59
    I am assuming that worked, and you're welcome.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured