Overridden CWinApp::OnFileOpen() handler
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Overridden CWinApp::OnFileOpen() handler

  1. #1
    sunnysky Guest

    Overridden CWinApp::OnFileOpen() handler

    Hello,

    I am working on an existing project and noticed some interesting phenomenon. I then created a small project and reproduced this behavior.

    When I created a new project, the system provided a default message handler for the file open menu item like this:
    ...
    ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
    ...

    Then I added an message handler in CMainFrame class:
    ...
    ON_COMMAND(ID_FILE_OPEN, &CMainFrame::OnFileOpen)
    ...
    void CMainFrame::OnFileOpen()
    {
    ::AfxMessageBox(_T("Hello Open"));
    }

    Now when I click the menu item "File"->"Open", the new added handler in CMainFrame is called.

    My question is: How does CWinApp::OnFileOpen() get overridden? How does the framework know CMainFrame::OnFileOpen() should be called in stead of CWinApp::OnFileOpen()?

    Another question is: Does MFC support multiple handlers for one message? How do we avoid conflicting behaviors?

    Thanks,
    Brian

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,131

    Re: Overridden CWinApp::OnFileOpen() handler

    There's a sequence MFC routes commands. I'm not going to post it off the top of my head because I don't want to get it wrong, but the main window is the first to get the command. If it doesn't handle it, it will try the view, doc and app. Since your mainframe is higher in the sequence, it got first crack at it.

  3. #3
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,479

    Re: Overridden CWinApp::OnFileOpen() handler

    Victor Nijegorodov

  4. #4
    sunnysky Guest

    Re: Overridden CWinApp::OnFileOpen() handler

    Thanks. These information are very helpful.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center