系统栏添加右键菜单:
1, 在resource中添加Menu,取名Main menu,然后添加菜单项,比如“Show Main Window”,其 ID 为 ID_MAINMENU_HIDEDIALOG,在类CDialog中添加menu变量 CMenu m_menu; 添加响应函数afx_msg void OnMainHide();
2, 在BEGIN_MESSAGE_MAP(), END_MESSAGE_MAP()中间添加消息处理映射 ON_COMMAND(ID_MAINMENU_HIDEDIALOG, &CFacedetection_demo2Dlg::OnMainHide)
3, 在在Dialog类的初始化函数OnInitDialog()中加载目录:
m_Menu.LoadMenu(IDR_MENU1);
4, 添加系统栏图标的右键响应菜单:
else if(lParam == WM_RBUTTONDOWN)
{
LPPOINT lpoint = new tagPOINT; // Get the point
::GetCursorPos(lpoint);
SetForegroundWindow(); // 创建置顶窗口
m_menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTALIGN,
lpoint->x, lpoint->y, this);
//创建弹出提示框
PostMessage(WM_MENU, 0, 0); // 发送响应消息
delete lpoint;
}
5, 添加消息处理函数void CMyCPL2Dlg::OnMainHide():
void CMyCPL2Dlg::OnMainShow()
{
ModifyStyleEx(0, WS_EX_TOPMOST);
ModifyStyleEx(WS_EX_TOOLWINDOW, WS_EX_APPWINDOW);
ShowWindow(SW_SHOW);
}