发信人: mendy.bbs@bbs.nju.edu.cn (孟迪), 信区: cnprogram
标  题: VC FAQ(7)
发信站: nju_bbs (Sun Apr 19 13:50:19 1998)
转信站: Lilac!ustcnews!nju_bbs

2m发信人:m TMN (派生类)
2m信  区:m RAD
2m标  题:m VC FAQ(7)
2m发信站:m '3m紫金飞鸿m' (Wed Apr  8 08:15:20 1998) , 5m站内信件m

[返回首页] [分类讨论区] [全部讨论区]

------------------------------------------------------------ 
  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. 
  

                         [返回首页] [分类讨论区] [全部讨论区]

--
m;31m※ 来源:·紫金飞鸿 bbs.njupt.edu.cn·[FROM: pc05.info.njupt]m

--
※ 来源:.南大小百合信息交换站 bbs.nju.edu.cn.[FROM: a507yjh.nju.edu]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.808毫秒