ATL 工程下添加右击菜单

首先在dllmain.cpp中添加如下声明

HINSTANCE g_hInstance;
 g_hInstance = hInstance;

源码如下:

 CPoint point;
 ::GetCursorPos(&point);
 HMENU hMenu;
 hMenu = ::LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU_SC));
 HMENU hSubMenu;
 hSubMenu = ::GetSubMenu(hMenu,0);
 //EnableMenuItem(hSubMenu, ID_PEILIAO_MENU, MF_BYCOMMAND|MF_GRAYED);
 //EnableMenuItem(hSubMenu, ID__FENLEI_MENU, MF_BYCOMMAND|MF_GRAYED);
 //EnableMenuItem(hSubMenu, ID__TEXING_MENU, MF_BYCOMMAND|MF_GRAYED);
 //EnableMenuItem(hSubMenu, ID__CHENLIE_MENU, MF_BYCOMMAND|MF_GRAYED);
 //EnableMenuItem(hSubMenu, ID__TISHI_MENU, MF_BYCOMMAND|MF_GRAYED);
 int nCmd=::TrackPopupMenu(hSubMenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RETURNCMD, point.x, point.y, 0, m_hWnd, NULL);

 if (nCmd == ID_PEIZHIG)
 {
  int nodeId(i);
  CComBSTR bstrObjName=_T("原料配制间");
  Fire_OnHCEvent(bstrObjName,0);
 }
 else if (nCmd == ID_FENLEIG)
 {
  int nodeId(i);
  CComBSTR bstrObjName=_T("品种分类间");
  Fire_OnHCEvent(bstrObjName,0);
 }
 else if (nCmd == ID_TEXINGG)
 {
  int nodeId(i);
  CComBSTR bstrObjName=_T("织品特性间");
  Fire_OnHCEvent(bstrObjName,0);
 }
 else if (nCmd == ID_CHENLIEG)
 {
  int nodeId(i);
  CComBSTR bstrObjName=_T("织品陈列间");
  Fire_OnHCEvent(bstrObjName,0);
 }
 else if (nCmd == ID_TISHIG)
 {
  int nodeId(i);
  CComBSTR bstrObjName=_T("温馨提示间");
  Fire_OnHCEvent(bstrObjName,0);
 }

 

你可能感兴趣的:(菜单)