VC右键菜单消息响应处理

 LRESULT CXXXDlg::TrayNotify(WPARAM wp,LPARAM lp)
{
 UINT uID = (UINT) wp;
 UINT uMouseMsg = (UINT) lp;
 
 if(uMouseMsg == WM_RBUTTONUP)
 {
  CPoint curPoint;
  GetCursorPos(&curPoint);
  CMenu Menu,*pSubMenu = NULL;
  if(!Menu.LoadMenu(IDR_MENU_TRAYICON))
  {
   return FALSE;
  }
  pSubMenu = Menu.GetSubMenu(0);
  if(pSubMenu == NULL)
  {
   Menu.DestroyMenu();
   return FALSE;
  }
  SetForegroundWindow ();// 将窗口设为前台窗口
  if(!TrackPopupMenu(pSubMenu->GetSafeHmenu(),TPM_LEFTALIGN | TPM_RIGHTBUTTON,curPoint.x,curPoint.y,0,AfxGetMainWnd()->GetSafeHwnd(),NULL))
  {
   ::PostMessage(m_hWnd, WM_NULL, 0, 0);
   Menu.DestroyMenu();
   return FALSE;
  }
  ::PostMessage(m_hWnd, WM_NULL, 0, 0);//  注意此处
  Menu.DestroyMenu();
  
  return TRUE;
 }
 else if(uMouseMsg == WM_LBUTTONDBLCLK)
 {}
 else if (uMouseMsg == WM_LBUTTONUP)
 {}
 return TRUE;
}

你可能感兴趣的:(VC右键菜单消息响应处理)