Programming 版 (精华区)
作 家: compus (蓝天) on board 'programming'
题 目: 如何给窗口加上菜单(不限于Frame)
来 源: 哈尔滨紫丁香站
日 期: Sun Aug 10 12:50:47 1997
出 处: compus.bbs@bbs.net.tsinghua.edu.cn
------------------------------------------------------------
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.
--
※ 来源:·哈尔滨紫丁香站 bbs1.hit.edu.cn·[FROM: compus.bbs@bbs.net.t]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.886毫秒