-
January 15th, 2015, 03:59 AM
#1
[RESOLVED] {win32] - how make the context menu corresponding to messages?
i have these code for show the context menu:
Code:
POINT pCursor;
GetCursorPos(&pCursor);
HMENU test=GetSubMenu(GetMenu(HandleWindow),0);
SetForegroundWindow(HandleWindow);
TrackPopupMenu(test, TPM_LEFTBUTTON | TPM_RIGHTALIGN, pCursor.x, pCursor.y, 0, HandleWindow, NULL);
PostMessage(HandleWindow, WM_NULL, 0, 0);
the context menu is showed without a problem. but when i click on menu items, nothing happens... why?
(i use WM_MENUCOMMAND message, because i use the menu notifications)
heres my message loop function(but works fine):
Code:
//Message Loop
WPARAM MessageLoop()
{
MSG msgEvents;
while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
{
if(IsChild(GetForegroundWindow(),msgEvents.hwnd)==TRUE || GetForegroundWindow()==msgEvents.hwnd)
{
if(IsDialogMessage(GetForegroundWindow(), &msgEvents) == TRUE)
{
TranslateMessage(&msgEvents);
DispatchMessage(&msgEvents);
}
}
}
return msgEvents.wParam;
}
anotherthing: the WM_MENUSELECT message works normaly. unless i can, using the WM_MENUSELECT, for detect the mouse click.
-
January 15th, 2015, 04:35 AM
#2
Re: {win32] - how make the context menu corresponding to messages?
Originally Posted by Cambalinho
...
the context menu is showed without a problem. but when i click on menu items, nothing happens... why?
(i use WM_MENUCOMMAND message, because i use the menu notifications)
But how and where do you handle this WM_MENUCOMMAND message? You didn't show it in your OP.
Victor Nijegorodov
-
January 15th, 2015, 04:38 AM
#3
Re: {win32] - how make the context menu corresponding to messages?
Originally Posted by VictorN
But how and where do you handle this WM_MENUCOMMAND message? You didn't show it in your OP.
sorry about that:
Code:
case WM_INITMENUPOPUP:
{
menuhandle=(HMENU)wParam;
return DefWindowProc(HandleWindow, msg, wParam, lParam);
}
break;
case WM_MENUCOMMAND:
{
MENUITEMINFO menuInfo;
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask=MIIM_DATA;
if(GetMenuItemInfo((HMENU)lParam,(UINT) wParam, true, &menuInfo )!=0)
{
Menu *mMenu = (Menu *) menuInfo.dwItemData;
if(mMenu!=NULL)
mMenu->Click();
}
menuhandle=NULL;
}
break;
-
January 15th, 2015, 04:46 AM
#4
Re: {win32] - how make the context menu corresponding to messages?
1. Is the code under case WM_MENUCOMMAND: executed?
2. What is the return value of GetMenuItemInfo? TRUE or FALSE?
3. What is Menu? What is the value of mMenu? Isn't it NULL?
4. What does the do? Is it executed?
IOW, did you debug your code or, as usual, you are trying to let the Forum do your job?
Victor Nijegorodov
-
January 15th, 2015, 04:48 AM
#5
Re: {win32] - how make the context menu corresponding to messages?
Originally Posted by VictorN
1. Is the code under case WM_MENUCOMMAND: executed?
2. What is the return value of GetMenuItemInfo? TRUE or FALSE?
3. What is Menu? What is the value of mMenu? Isn't it NULL?
4. What does the do? Is it executed?
IOW, did you debug your code or, as usual, you are trying to let the Forum do your job?
if i click on menu item, on menu bar, the Click lambda is executed, the problem is only on menu context
-
January 15th, 2015, 04:58 AM
#6
Re: {win32] - how make the context menu corresponding to messages?
Originally Posted by Cambalinho
if i click on menu item, on menu bar, the Click lambda is executed, the problem is only on menu context
I put four questions trying to help you.
And you did not answer any.
So what help do you consider?
Victor Nijegorodov
-
January 15th, 2015, 05:02 AM
#7
Re: {win32] - how make the context menu corresponding to messages?
i tested now, the WM_MENUCOMMAND, on menu context, isn't executed
-
January 15th, 2015, 05:04 AM
#8
Re: {win32] - how make the context menu corresponding to messages?
tested: the WM_COMMAND is executed. why if the menu item style is notification?
-
January 15th, 2015, 05:11 AM
#9
Re: {win32] - how make the context menu corresponding to messages?
anotherthing form msdn: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
"
Menus
If an application enables a menu separator, the system sends a WM_COMMAND message with the low-word of the wParam parameter set to zero when the user selects the separator.
If a menu is defined with a MENUINFO.dwStyle value of MNS_NOTIFYBYPOS, WM_MENUCOMMAND is sent instead of WM_COMMAND."
-
January 15th, 2015, 05:11 AM
#10
Re: {win32] - how make the context menu corresponding to messages?
Originally Posted by Cambalinho
tested: the WM_COMMAND is executed. why if the menu item style is notification?
What is "notification"? Do you mean MNS_NOTIFYBYPOS style? Where and how do you set it for the menu?
BTW, what is the reason to handle WM_MENUCOMMAND rather than WM_COMMAND message?
Victor Nijegorodov
-
January 15th, 2015, 05:20 AM
#11
Re: {win32] - how make the context menu corresponding to messages?
when i create the menu items:
Code:
MENUINFO mnInfo;
mnInfo.cbSize=sizeof(MENUINFO);
mnInfo.fMask=MIM_STYLE;
if(systmenu==false)
GetMenuInfo(GetMenu(MainHWND),&mnInfo);
else
GetMenuInfo(GetSystemMenu(MainHWND,false),&mnInfo);
mnInfo.cbSize=sizeof(MENUINFO);
mnInfo.fMask=MIM_STYLE;
mnInfo.dwStyle=MNS_NOTIFYBYPOS;
if(systmenu==false)
SetMenuInfo(GetMenu(MainHWND),&mnInfo);
else
SetMenuInfo(GetSystemMenu(MainHWND,false),&mnInfo);
but you give me the help that i need
thanks for all
Code:
case WM_COMMAND:
{
if(HIWORD(wParam)==0)
{
if (GetMenuState((HMENU)menuhandle,(UINT)LOWORD(wParam),MF_BYCOMMAND)!=0xFFFFFFFF )
{
MENUITEMINFO menuInfo;
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask=MIIM_DATA;
GetMenuItemInfo(menuhandle,(UINT) LOWORD(wParam), FALSE, &menuInfo );
Menu *mMenu = (Menu *) menuInfo.dwItemData;
if (mMenu!=NULL)
{
mMenu->Click();
}
}
}
SendMessage((HWND)lParam , WM_COMMAND, wParam, lParam);
return DefWindowProc(HandleWindow, msg, wParam, lParam);
}
break;
the WM_COMMAND, seems, don't give me the HMENU item, but i have it with WM_INITMENUPOPUP message. and now works fine. but i continue confused why these happens
-
January 15th, 2015, 05:26 AM
#12
Re: {win32] - how make the context menu corresponding to messages?
Originally Posted by Cambalinho
when i create the menu items:
...
the WM_COMMAND, seems, don't give me the HMENU item, but i have it with WM_INITMENUPOPUP message. and now works fine. but i continue confused why these happens
I never used/handled WM_MENUCOMMAND, so can only guess.
What you you would add MIM_APPLYTOSUBMENUS flag to the menu mask?
Code:
MENUINFO mnInfo;
mnInfo.cbSize=sizeof(MENUINFO);
mnInfo.fMask=MIM_STYLE | MIM_APPLYTOSUBMENUS;
Victor Nijegorodov
-
January 15th, 2015, 05:40 AM
#13
Re: {win32] - how make the context menu corresponding to messages?
Originally Posted by VictorN
I never used/handled WM_MENUCOMMAND, so can only guess.
What you you would add MIM_APPLYTOSUBMENUS flag to the menu mask?
Code:
MENUINFO mnInfo;
mnInfo.cbSize=sizeof(MENUINFO);
mnInfo.fMask=MIM_STYLE | MIM_APPLYTOSUBMENUS;
i have another diferent error too.. but you have 100% right. thanks for all
now works fine
-
January 15th, 2015, 05:48 AM
#14
Re: {win32] - how make the context menu corresponding to messages?
and the other error was fixed too
thanks for all
-
January 15th, 2015, 05:51 AM
#15
Re: [RESOLVED] {win32] - how make the context menu corresponding to messages?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|