Hi Blade_Bao,
This stuff with
ID_WINDOW_NEW
was just an example how to use
UPDATE_COMMAND_UI
. :)
My hope was that you will use this example and implement your own
UPDATE_COMMAND_UI
handlers for your needs. But if you need an example with:
press [File]->[open], then [edit]->[cut] & [edit]->[copy] will be disabled
you will get such an example. :)
By default the VS IDE wizard will generate you a project where the
File/New and
File/Open commands are handled by the parent of your application class (in your case by
CWinAppEx
).
So lets assume that your application class is
CTestApp
(this is an example name, you have to change this name with the name of your application class). You have to find the:
ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
lines in the message map of your application class, and replace this lines with:
ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CTestApp::OnFileOpen)
After that add the
BOOL m_bEnabled;
member to your application class and init this member as
TRUE
in the constructor.
Add the
afx_msg void OnFileOpen();
in you application class (int he header file) and provide implementation for this handler. The implementation could be something like:
void CTestApp::OnFileOpen()
{
m_bEnabled = FALSE;
CWinAppEx::OnFileOpen();
}
Now you can add the
UPDATE_COMMAND_UI
handlers for
Copy and
Cut to the message map of your application class:
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, &CTestApp::OnUpdateEditCopy)
ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, &CTestApp::OnUpdateEditCut)
In you application class header add:
afx_msg void OnUpdateEditCopy(CCmdUI *pCmdUI);
afx_msg void OnUpdateEditCut(CCmdUI *pCmdUI);
And provide implementations for this handlers:
void CTestApp::OnUpdateEditCopy(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bEnabled);
}
void CTestApp::OnUpdateEditCut(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bEnabled);
}
And now, after clicking the
File/Open you will notice that your
Copy and
Cut menu items will be disabled. Also you should know that in the above scenario there is no mechanism to enable this menu items once they are disabled.
You can generate the
UPDATE_COMMAND_UI
handlers by using your IDE. Please investigate the examples that I provided for you and try to solve your problem by using them. :)
Regards,
Nuri Ismail