LRESULT CALLBACK GetMsgProc(int nCode,WPARAM wParam,LPARAM lParam )
{
 if (HC_ACTION == nCode)
 {
  char _module[256];
  GetModuleFileName(NULL, _module, sizeof(_module)); //获取模块路径
  if (strstr(_module, "\\notepad.exe"))  //检查有没notepad.exe 
  {
   LPMSG lpMsg = (LPMSG)lParam;//获取消息
   HMENU hMainMenu= GetMenu(lpMsg->hwnd); //获取当前窗口的菜单句柄 
   if (hMainMenu != NULL)//如果有菜单
   {
    int iCount=GetMenuItemCount(hMainMenu);//获取菜单的item数
    for (int i = 0; i < iCount; i ++)
    {
     TCHAR szText[255] = "";
     GetMenuString(hMainMenu, i, szText, sizeof(szText), MF_BYPOSITION);//获取菜单项的名字
     if (!strcmp(szText, "诚信邮"))//看一下是不是诚信邮
     {
      break;
     }
    }
    if (i >= iCount)//如果没诚信邮菜单就加载菜单
    {
     HMENU hMenu = LoadMenu(GetModuleHandle("hookhook"), MAKEINTRESOURCE(IDR_HOOK_MENU));//加载菜单
     HMENU hPopupMenu = GetSubMenu(hMenu, 0);//只要第一个菜单
     AppendMenu(hMainMenu, MF_POPUP, (UINT)hPopupMenu, "诚信邮");//添加在主菜单中添加菜单
     //DrawMenuBar(lpMsg->hwnd);
    }
   }
   
  }
 }
 
 return CallNextHookEx(hHook, nCode, wParam, lParam);
}

 

void setHook()
{
 hHook = SetWindowsHookEx ( WH_GETMESSAGE, GetMsgProc, GetModuleHandle("hookhook"), 0);
}