VC++ 2008 (在系统菜单中添加菜单)

1.创建一个基于对话框的工程:AddMenuToSysMenu

2.在resouce.h中定义

#define IDI_PECULIARMENU                1201

3. OnInitDialog中添加如下代码:

     CMenu* m_pMenu = GetSystemMenu(FALSE);

     CString sysMenu = _T("系统菜单");

     m_pMenu->AppendMenu(MF_STRING, IDI_PECULIARMENU,sysMenu);

4.在OnSysCommand中添加如下代码相应自己的消息

void CTest001Dlg::OnSysCommand(UINT nID, LPARAM lParam)

{

     if ((nID & 0xFFF0) == IDM_ABOUTBOX)

     {

         CAboutDlg dlgAbout;

         dlgAbout.DoModal();

     }

     else if(nID == IDI_PECULIARMENU){

         MessageBox(_T("系统菜单"),_T("提示"),MB_OK|MB_ICONINFORMATION);

     }else{

         CDialog::OnSysCommand(nID, lParam);

     }

}


Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: