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);
}