News:

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

Popup Menu problem

Started by ossama, December 27, 2007, 11:25:34 AM

Previous topic - Next topic

ossama

hi, :bg
i wanted to show a popup menu when i click the left button of the mouse,
but it is not showing correctly,
can you help me.
the project is attached with this message.
the code is as the following:

.686
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

include macros.asm

.data
szAppName db "Simple Window",0
hInstance dd ?
h_menu dd ?

.code
start:
invoke GetModuleHandle, NULL
mov    hInstance,eax

invoke LoadMenu,hInstance,sz("simple_popup")
mov h_menu,eax

call WinMain

invoke DestroyMenu,h_menu

invoke ExitProcess, eax

WinMain proc
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize, SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra, NULL
mov   wc.cbWndExtra, NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground, COLOR_WINDOW+1
mov   wc.lpszMenuName, NULL
mov   wc.lpszClassName,sz("ossama32")
invoke LoadIcon, NULL, IDI_APPLICATION
mov   wc.hIcon, eax
mov   wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov   wc.hCursor, eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,sz("ossama32"),ADDR szAppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL
mov   hwnd, eax
invoke ShowWindow, hwnd, SW_SHOWNORMAL
invoke UpdateWindow, hwnd
@@:
invoke GetMessage, ADDR msg, NULL, 0, 0
cmp eax,0
je @F
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp @B
@@:
return 0
WinMain endp

WndProc proc hWnd:HWND,message:UINT, wParam:WPARAM, lParam:LPARAM
local pt:POINT

.if message==WM_LBUTTONUP
invoke GetCursorPos,addr pt
invoke TrackPopupMenu,h_menu,TPM_LEFTALIGN+TPM_LEFTBUTTON,pt.x,pt.y,0,hWnd,0
.elseif message==WM_DESTROY
invoke PostQuitMessage, NULL
.else
invoke DefWindowProc, hWnd,message, wParam, lParam
ret
.endif
return 0
WndProc endp
end start


thank you in advance
regards OSSAMA

[attachment deleted by admin]

six_L

.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, hMenu, TPM_LEFTALIGN, eax, ebx, 0, hWnd, 0
regards

ossama


ossama

six_L,
this is my program with your suggestion:


.686
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

include macros.asm

.data
szAppName db "Simple Window",0
hInstance dd ?
h_menu dd ?

.code
start:
invoke GetModuleHandle, NULL
mov    hInstance,eax

invoke LoadMenu,hInstance,sz("simple_popup")
mov h_menu,eax

call WinMain

invoke DestroyMenu,h_menu

invoke ExitProcess, eax

WinMain proc
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize, SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra, NULL
mov   wc.cbWndExtra, NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground, COLOR_WINDOW+1
mov   wc.lpszMenuName, NULL
mov   wc.lpszClassName,sz("ossama32")
invoke LoadIcon, NULL, IDI_APPLICATION
mov   wc.hIcon, eax
mov   wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov   wc.hCursor, eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,sz("ossama32"),ADDR szAppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL
mov   hwnd, eax
invoke ShowWindow, hwnd, SW_SHOWNORMAL
invoke UpdateWindow, hwnd
@@:
invoke GetMessage, ADDR msg, NULL, 0, 0
cmp eax,0
je @F
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp @B
@@:
return 0
WinMain endp

WndProc proc hWnd:HWND,message:UINT, wParam:WPARAM, lParam:LPARAM
local pt:POINT

.if message==WM_CONTEXTMENU ;has user right clicked mouse?
mov eax, lParam ;if so, show the popup menu
and eax, 0ffffh
mov edx, lParam
shr edx, 16
invoke TrackPopupMenu,h_menu, TPM_LEFTALIGN, eax, edx, 0, hWnd, 0
.elseif message==WM_DESTROY
invoke PostQuitMessage, NULL
.else
invoke DefWindowProc, hWnd,message, wParam, lParam
ret
.endif
return 0
WndProc endp

six_L

Quoteinvoke   CreatePopupMenu
      mov   hMenu, eax     
      invoke   AppendMenu, hMenu, MF_STRING, IDC_START, CTXT("Start")
regards

ossama

i am using resources to create the popup menu,and i am using LoadMenu to load that menu,
is the problem in this?

akyprian

Hi,

This is the resource:

simple_popup MENU
{
   POPUP "SomePopUpName"
   {
      MENUITEM "&Item1", 1
      MENUITEM "&Item2", 2
   }
}

and this is the code change:

Invoke LoadMenu,hInstance,sz("simple_popup")
Invoke GetSubMenu,EAX,0
mov h_menu,eax

Regards,

Antonis

ossama

akyprian,it works,
in fact i was using this trick and i forgot it,
but why my first code does not work? it seems that evering thing is logic  ::)

akyprian

It is not a trick. It is the way it should work.

Your code does not work because simple_popup is NOT a popupmenu. The TrackPopupMenu API function needs a handle to a PopUp menu.

Regards

ossama