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
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.
Re: Overridden CWinApp::OnFileOpen() handler
Re: Overridden CWinApp::OnFileOpen() handler
Thanks. These information are very helpful.