00000018.txt
来自「水木清华BBS站的讨论区精华集锦」· 文本 代码 · 共 65 行
TXT
65 行
--===BBS水木清华站∶精华区===--
-===BBS水木清华站∶精华区===-
------------------------------------------------------------
How do I 'attach' a menu to a window's creation/destruction?
-----------------------------------------------------------
{Note the original question talked about dialogs, but you can interpolate
this
code to any kind of window that you want to have change the menu.}
One of the ways to do this is as follows**
1. Declare a variable CMenu pNewMenu in one of the dialog class.
2. Handle the WM_INITDIALOG and WM_CLOSE messages in the
dialog class as follows.
BOOL CMydlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Load the IDR_MYFRAME menu
pNewMenu = new CMenu;
pNewMenu->LoadMenu(IDR_MYFRAME);
// Set the mainframe menu to mainframe.
((CMainFrame *)AfxGetMainWnd())->SetMenu(pNewMenu);
return TRUE;
}
And
void CMydlg::OnClose()
{
// Detach the previous HMenu handle from the object.
pNewMenu->Detach();
pNewMenu->LoadMenu(IDR_MAINFRAME);
// Restore the mainframe menu.
((CMainFrame *)AfxGetMainWnd())->SetMenu(pNewMenu);
CDialog::OnClose();
}
4. If there are other methods of closing the dialog (example- By clicking
a
button in the Dialog), then The code given above in OnClose handler, must
be
put in the button click handler.
-===BBS水木清华站∶精华区===-
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?