Hi! I'm trying to get a popup menu in a listview when clicked right mouse button, but I can't get it working. I want to load it from resource, not to dynamically create it. I've read donkey's posts on this question, but it doesn't work!



/siddhartha
Posted on 2004-06-03 05:54:45 by siddhartha
try posting your code.
Posted on 2004-06-03 06:36:57 by smurf
I got it! That's the code I use:

.elseif eax==WM_NOTIFY
.if wParam == lv
mov edx,lParam
mov eax,.NMHDR.code
.if eax == NM_RCLICK
invoke GetCursorPos,addr pt
invoke LoadMenu,,IDR_MENU
mov ,eax
invoke GetSubMenu,,0 ; 0 = first submenu
mov ,eax
invoke TrackPopupMenuEx, , TPM_RETURNCMD, , , , NULL
.endif
.endif


But I wonder if there's a shorter way to do this...


/siddhartha
Posted on 2004-06-04 07:26:02 by siddhartha
Don't really know how this can be made shorter as i rarely use this kind of code. However, i just wanted to point out som necessary code you leftout; freeing used resources is a must. Placing handles to things wich are going to be repeaditely used in the inital code and freed when program is ended, is the best way to go. Ofcourse, someone else might have a different view about this.



...
...
[COLOR=green];/( should be placed outside routine, since then you dont have
;/( to load and destroy menu each time the menu is used.[/COLOR]
invoke LoadMenu,[hInstance],IDR_MENU
mov [hMenu],eax
[COLOR=green];/( placed outside reduces need to execute api each time menu is called.[/COLOR]
invoke GetSubMenu, [hMenu], 0 ; 0 = first submenu
mov hPopup, eax
...
...
.elseif eax==WM_NOTIFY
.if wParam == lv
mov edx,lParam
.if [edx].NMHDR.code == NM_RCLICK
invoke GetCursorPos, addr pt
invoke TrackPopupMenuEx, hPopup, TPM_RETURNCMD, [pt.x], [pt.y], [hWnd], NULL
.endif
.endif
...
...
[COLOR=green];/( Dont forget to release resources used when using LoadMenu.[/COLOR]
inv DestroyMenu, hMenu
...
...
Posted on 2004-06-04 07:50:26 by fisk
Thanks for the tip. I didn't know that if the code is outside the routine I won't have to destroy the menu every time. Thanks!


/siddhartha
Posted on 2004-06-04 10:00:41 by siddhartha
Everything is OK with one little exception - I can't get the menu items working when clicked. I'm putting my code inside the WM_COMMAND message, but it doesn't seem to work... I can't understand what I'm doing wrong! Plese, help!



/siddhartha
Posted on 2004-06-04 10:34:31 by siddhartha

Everything is OK with one little exception - I can't get the menu items working when clicked. I'm putting my code inside the WM_COMMAND message, but it doesn't seem to work... I can't understand what I'm doing wrong! Plese, help!



/siddhartha



So, any suggestions? Please!


/siddhartha
Posted on 2004-06-06 19:12:51 by siddhartha
What code are you putting inside the WM_COMMAND message? you need to check wParam (low-order word) for the MENU-ID wich you have defined in the menu resource. But you dont need to use the WM_COMMAND notification either. You can get the MENU-ID directly from the TrackPopupMenuEx function, without waiting for that notification.



...
.elseif eax==WM_NOTIFY
.if wParam == lv
mov edx,lParam
.if [edx].NMHDR.code == NM_RCLICK
invoke GetCursorPos, addr pt
[COLOR=green];// If you look here I have added TPM_NONOTIFY,
;// when used it wont send a WM_COMMAND message.[/color]
invoke TrackPopupMenuEx, hPopup, TPM_RETURNCMD or [COLOR=red]TPM_NONOTIFY[/COLOR] , [pt.x], [pt.y], [hWnd], 0
[COLOR=green];// If a menu item was selected the MENU-ID is returned in EAX
;// if nothing was selected it returns 0 in EAX[/COLOR]
.endif
.endif
...
Posted on 2004-06-07 03:35:57 by fisk
Thanks, fisk! If I put the code after TrackPopupMenuEx, it works. But if it is inside WM_COMMAND, it doesn't. I just check if eax==IDM_ADD and do something if so, but it doesn't work... But anyway, thanks!


/siddhartha
Posted on 2004-06-09 20:06:56 by siddhartha
Did you check the low-order word of wParam? if you check the entire content of wParam it wouldnt work as it contains more information. If you already are checking the low-order word, then you shuld post the code here to see what your writing. Even if you solved the problem by using the other method described above, you should get this to work as it is used in other situations aswell. Where that other method isnt available.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/menus/menureference/menumessages/wm_command.asp


wParam
The high-order word specifies the notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero.

The low-order word specifies the identifier of the menu item, control, or accelerator




...
mov eax, wParam
and eax, 0FFFFh
.if eax==IDM_ADD

.endif
...
Posted on 2004-06-10 03:11:37 by fisk
Yes, I'm checking for this, but it still doesn't work... I wonder if the problem is coming from the menu structure or something...



/siddhartha
Posted on 2004-06-10 07:49:49 by siddhartha
Maybe you should try and view the value in wParam sent to WM_COMMAND. Maybe the constant(EQU) value is wrongly defined? use vkims debug library eg. "PrintDec eax". Atleast this way you will se all values sent.
Posted on 2004-06-10 07:53:03 by fisk
I don't think it's defined wrong, because after TrackPopupMenuEx it works with the same identifier. I'll try to debug it as you said! Thanks for your help!


/siddhartha
Posted on 2004-06-10 08:15:03 by siddhartha