-
April 1st, 2014, 09:34 AM
#1
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
-
April 1st, 2014, 09:43 AM
#2
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.
-
April 1st, 2014, 10:01 AM
#3
Re: Overridden CWinApp::OnFileOpen() handler
Victor Nijegorodov
-
April 2nd, 2014, 09:10 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|