Click to See Complete Forum and Search --> : Menu Hook Problem


Ten
June 11th, 2005, 07:15 PM
Hi,

i add a menu in a window using a hook:

Example : File - Edit - My_Menu

hMenu = GetMenu(hDlg);
AppendMenu(hMenu, MF_STRING, IDM_PLUS, "My_Menu");

Ok, now i want to add a submenu in 'My_Menu':

hMenu = GetSubMenu(hMenu, 2);

But the Position '2' does not exist cause it's a hooking.

And the question is : How to get a handle to My_Menu without have its Position.

Thanks.

SuperKoko
June 12th, 2005, 02:57 AM
Your program does not work, because you add a string with AppendMenu, but you should add a popup menu, if you want to add sub items:

HMENU hSubMenu=CreatePopupMenu();
// you can add items to hSubMenu here
AppendMenu(hMenu,MF_STRING,MF_POPUP,"My_Menu");
// Now hSubMenu == GetSubMenu(hMenu, 2)

Ten
June 12th, 2005, 07:40 AM
Thanks! Problem Solved!


hMenu = GetMenu(hDlg);
hSubMenu = CreatePopupMenu();

AppendMenu(hSubMenu, MF_STRING, IDM_HELP, "&Help");

AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Plus");


Ah and...

I want to replace some menu actions (here, item 158)

In my hook function:


LRESULT CALLBACK HookMenuMessage(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode == HC_ACTION)
{
MSG * pMSG = (MSG*)lParam;
switch(pMSG->message)
{
case WM_COMMAND:
switch(LOWORD(pMSG->wParam))
{
case IDM_HELP:
MessageBox(0, "Yes ?", "...", 0);
return TRUE;
case 158:
MessageBox(0, "Function Removed", "...", 0);
goto out:
break;
default:
return FALSE;
}
}
}

return CallNextHookEx(hhk, nCode, wParam, lParam);
out: return 0;
}


But does not work :(, i have the MessageBox and the action of the item.