标  题: How do I 'attach' a menu to a window's creation/d
发信人: Pacific (无情~~~Nolove), 信区: VisualC
发信站: BBS 水木清华站 (Fri Oct 16 17:47:12 1998)


------------------------------------------------------------                     
  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);                                       

--
        老鸟有交待,中鸟要等待,菜鸟要忍耐。
        老鸟级功夫:吹牛、聊天、玩MUD 、发呆。
        中鸟级功夫:睡觉、灌水、玩游戏、NT&VC。
        菜鸟级功夫:学习、泡妞、玩篮球、And so on

        My E-Mail: Nolove@263.net

--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: yazhou.bbs@bbs.net.t]
※ 修改:.fzx 于 Aug  9 16:44:14 修改本文.[FROM: heart.hit.edu.cn]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:205.463毫秒