导读:
LRESULT CTrayIcon::OnTrayNotification(WPARAM wID, LPARAM lEvent)
{
if (wID!=m_nid.uID (lEvent!=WM_RBUTTONUP &&lEvent!=WM_LBUTTONDBLCLK))
return 0;
CMenu menu;//装载上下文菜单;
if (!menu.LoadMenu(m_nid.uID))
return 0;
CMenu* pSubMenu = menu.GetSubMenu(0);
if (!pSubMenu)
return 0;
if (lEvent==WM_RBUTTONUP) {//设置第一个菜单项为默认菜单项目
::SetMenuDefaultItem(pSubMenu->m_hMenu, 0, TRUE);
//将当前菜单作为上下文菜单;
CPoint mouse;
GetCursorPos(&mouse);
::SetForegroundWindow(m_nid.hWnd);
::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0,m_nid.hWnd, NULL);
} else // double click: execute first menu item
::SendMessage(m_nid.hWnd, WM_COMMAND, pSubMenu->GetMenuItemID(0), 0);
return 1;
}
/ MainFrm.h : interface of the CMainFrame class
#if !defi
LRESULT CTrayIcon::OnTrayNotification(WPARAM wID, LPARAM lEvent)
{
if (wID!=m_nid.uID (lEvent!=WM_RBUTTONUP &&lEvent!=WM_LBUTTONDBLCLK))
return 0;
CMenu menu;//装载上下文菜单;
if (!menu.LoadMenu(m_nid.uID))
return 0;
CMenu* pSubMenu = menu.GetSubMenu(0);
if (!pSubMenu)
return 0;
if (lEvent==WM_RBUTTONUP) {//设置第一个菜单项为默认菜单项目
::SetMenuDefaultItem(pSubMenu->m_hMenu, 0, TRUE);
//将当前菜单作为上下文菜单;
CPoint mouse;
GetCursorPos(&mouse);
::SetForegroundWindow(m_nid.hWnd);
::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0,m_nid.hWnd, NULL);
} else // double click: execute first menu item
::SendMessage(m_nid.hWnd, WM_COMMAND, pSubMenu->GetMenuItemID(0), 0);
return 1;
}
/ MainFrm.h : interface of the CMainFrame class
#if !defi