Hi All!,
ii would like to know if you can point me an example of Listbox with a popup menu (masm32). What i'm trying to do is to display a popup menu in a multiselect listbox, then, the user can select one or more items and copy the text to the clipboard. Obviously, i just want to display the popup menu when the user clicks just in the listbox.
Can you help me with this?.
Thanks in advanced,
NCR
Subclass a listbox and trap the WM_LBUTTONDOWN message.
Hi hutch!,
would you explain me how to do that? i'm not an expert asm programmer.
Thanks in advanced!,
NCR
Search the Forum for GWL_WNDPROC. You probably want to catch WM_RBUTTONDOWN.
Hi jj2007!,
thanks for the reply. I searched and found this: http://www.masm32.com/board/index.php?topic=15708.0 and this: http://win32assembly.online.fr/tut20.html
I think these articles would be enough.
Anyways, if i have another question, i'll ask :P
Thanks!.
i use WM_RBUTTONUP :bg
TstPop: cmp ecx,WM_RBUTTONUP
jnz WndPr2
;----------------------
;WM_RBUTTONUP
movzx edx,word ptr lParam+2
movzx ecx,word ptr lParam
push edx
push ecx
INVOKE ClientToScreen,hWnd,esp
pop ecx
pop edx
INVOKE TrackPopupMenu,hEditMenu,
TPM_RETURNCMD or TPM_LEFTALIGN or TPM_TOPALIGN or TPM_NOANIMATION,
ecx,edx,0,hWnd,0
;----------------------
;WM_COMMAND
WndPrM: cmp eax,IDM_EDIT_COPY
jz WndPrP
when the user releases the right mouse button, a popup appears that is the same as the Edit popup from the main menu (hEditMenu)
TrackPopupMenu returns (in EAX) the ID number of a selected item, so the code falls through to parse it as a WM_COMMAND
that option was selected by using the TPM_RETURNCMD flag
you can create a different menu and pass the handle to that if the Edit menu isn't what you want
if i wanted to reduce the code, i could push the TrackPopupMenu parameters individually, but it isn't as clear - it would save 4 bytes :P
Hi dedndave!,
thanks for the answer!. i tried that and it seems to work fine, but, i have a problem: the popup menu shows up anywhere in the window but not in the lixtbox. i need to adjust the coordinates before, i guess.
the lParam hiword and loword are client coordinates of the hWnd window
TrackPopupMenu wants screen coordinates
you may have to adjust them according to the location of your listbox in the client area
i guess i would adjust them before the ClientToScreen call
i might mention - if you create a special menu that is not "attached" to a window with SetMenu,
then you are supposed to use DestroyMenu before exiting the application to free the resources
in my code, i use a handle from the main menu, which is destroyed because...
all menus and submenus that are assigned to a window are destroyed for you when the window is destroyed
Hi,
Take a look at my code for the RadAsm favorites addin, it has a listbox with a popup menu...
http://www.masm32.com/board/index.php?topic=14100.msg123844#msg123844
Hi!,
@dedndave: Thanks for the hints!.
@donkey: Thanks for the example, that's exactly what i want to do, i'll take a look at it.
Thank you guys!.
ps. what hutch point me could be a very good exercise!!! (for me, of course :P you don't need it).
in Edgar's example, he creates and destroys the menu each time, i guess
i would probably create it once at init and destroy it once on exit
although - he may have a good reason for doing it that way that isn't obvious to me - he's a pretty sharp guy :U
Hi All!,
i think i got it! is working!.
Thanks a lot for the answers!!!.