News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Right Click Menu

Started by Marko, January 26, 2006, 11:06:41 AM

Previous topic - Next topic

Marko

i am proceding in my study of win32 assembly, after taked as my Lab book the tutorial of Iczelion(nice work  :cheekygreen:) i came up to the menu part. For now it 's all ok and very clear,  after some try i have this question, How can i crate a menu that show up when i right click on the mouse? As a C programmer i use CMenu wrapper of mfc and in vb trhere is a simple method Popupmenu but how to do this i asm?

tnx in advance
Marko


Marko


Marko

Starting from that point i tried to go ahead. Let' say that i don't want create a menu on the fly but i have created some in my resource file so ...


.data
hBMP     dd 0
DlgName  db "Maindialog",0
msgTitle db "You Selected...",0
MenuName db "TheMenu",0  ;<---------------------


; The text for the menu items..and we're also using them to print which item
; we selected from the popup menu

Menu1    db "Item One", 0
Menu2    db "Item Two", 0
.
.
.
.



.data?
hInstance dd   ?
mnuhWnd   HWND ?
hWin     HWND ?
hTrackMenu HMENU ?  ;<---------------

.code
;______________________________________________________________________________

start:         ; using a DialogBox as our window..works with CreateWindowEx too
   invoke GetModuleHandle,NULL
   mov hInstance,eax
   invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,addr DlgProc,NULL
   invoke ExitProcess,0
;______________________________________________________________________________

DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

   .if uMsg==WM_INITDIALOG
      mov eax, hWnd          ; keep our window handle for later
      mov hWin, eax
      ;invoke CreatePopupMenu ; Create a PopupMenu structure
      ;mov mnuhWnd, eax       ; and save it's pointer

      ;lazy code below to add items to the menu used when right clicking
      ;invoke AppendMenu, mnuhWnd, MF_STRING, IDM_ONE, addr Menu1
      .
      .
      .

invoke LoadMenu, hInstance, OFFSET MenuName
mov mnuhWnd, eax

invoke GetSubMenu, mnuhWnd,0
mov hTrackMenu, eax

   .ELSEIF uMsg==WM_CONTEXTMENU   ;has user right clicked mouse?
      mov eax, lParam             ;if so, show the popup menu
      and eax, 0ffffh
      mov ebx, lParam
      shr ebx, 16
      ;invoke TrackPopupMenu, mnuhWnd, TPM_LEFTALIGN, eax, ebx, 0, hWnd, 0
invoke TrackPopupMenu, hTrackMenu, TPM_LEFTALIGN, eax, ebx, 0, hWnd, 0
       .
       .
       .


Obviosly this doesn't work. LoadMenu miserable fails to load the menu, it perhaps the dialog windows do not have any menu associated with that. If so how can i load a resource from the resource script? Or i am walking a wrong path?

tnx in advance
Marko

Tedd

I tried to get a popup menu to work from a resource and it failed miserably, and after trying for a while I gave up.
An alternative approach is to create the menu (using a few AppendMenu calls) on creation, and save the menu-handle. Then simply use this handle in the call to TrackPopupMenu. (It's not really such an overhead when you consider that the menu is created in the same way when you load the resource anyway.)
No snowflake in an avalanche feels responsible.

Marko

Finally i get it work. The above code was right the problem was with something mess in the resource file :dance: