
主题 |
1. 系统菜单下面添加自定义菜单 2. 3. 4. 5. |
AppendMenu |
The AppendMenu function appends a new item to the end of the
specified menu bar, drop-down menu, submenu, or shortcut menu. You can use this function to specify the content, appearance, and behavior of the menu item. Note The AppendMenu function has been superseded by the
InsertMenuItem function. You can still use AppendMenu, however, if you do not need any of the extended features of InsertMenuItem. BOOL AppendMenu(
HMENU hMenu,
// handle to menu UINT uFlags,
// menu-item options UINT_PTR uIDNewItem, // identifier, menu, or submenu
LPCTSTR lpNewItem // menu-item content
);
|
ID |
Value |
Description |
1. |
MF_BITMAP |
位图 |
2. |
MF_DISABLED |
不可用 |
3. |
MF_ENABLED |
可用 |
4. |
MF_GRAYED |
灰色 |
5. |
MF_MENUBARBREAK |
|
6. |
MF_MENUBREAK |
|
7. |
MF_OWNERDRAW |
|
8. |
MF_POPUP |
|
9. |
MF_SEPARATOR |
分隔符号 |
10. |
MF_STRING |
字符串 |
11. |
MF_CHECKED |
勾上 |
12. |
MF_UNCHECKED |
取消勾上 |
代码::系统菜单下面添加自定义菜单 |
1.在Resource.h里面 #define ID_MENU1 0x1500
2.在::OnInitDialog() 下面添加代码
// TODO: Add extra initialization here
CMenu* pMenu = GetSystemMenu(FALSE);
CString menu1="新菜单";
pMenu->AppendMenu(MF_SEPARATOR);
pMenu->AppendMenu(MF_STRING, ID_MENU1, menu1);
3.在::OnSysCommand(UINT nID, LPARAM lParam) 下面添加响应单击 这个菜单的代码
void CProject02Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) ==
IDM_ABOUTBOX) {
CAboutDlg dlgAbout; dlgAbout.DoModal(); }
else if
(nID==ID_MENU1) {
MessageBox("YES"); }
else
{
CDialog::OnSysCommand(nID, lParam); }
} 效果图: |
ID |
nID |
备注:OnSysCommand |
1. |
SC_CLOSE |
Close |
2. |
SC_MAXIMIZE |
(or |
3. |
SC_MINIMIZE |
(or |
4. |
SC_MOVE |
Move |
5. |
SC_RESTORE |
Restore |
6. |
SC_SIZE |
Size |
7. |
SC_NEXTWINDOW |
Move |
8. |
SC_PREVWINDOW |
Move |
9. |
SC_KEYMENU |
Retrieve |
10. |
SC_MOUSEMENU |
Retrieve |
11. |
SC_HOTKEY |
Activate |
12. |
The |
|
13. |
SC_SCREENSAVE |
Executes |
14. |
SC_TASKLIST |
Execute |
15. |
SC_VSCROLL |
Scroll |
16. |
SC_HSCROLL |
Scroll |
