hey,
i've been trying to create those context menus, the ones that popup when u right click inside the window...i am getting the message WM_CONTEXTMENU...but when i invoke TrackPopupMenuEx...sumthing weird happens....basically i tell it to create the context menu at the position 100,100...and sumthing DOES show up there, but its a really thin rectangle...not a proper menu...when u keep the mouse pointer over the upper half of that rectangle...the submenu opens up...its all quite weird, can sum1 pls. tell me whats wrong...here's the source code of the file: (win32.asm)
.386
.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
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
.data
className db 'myClass',0
winName db 'My Window',0
myMnu db 'myMnu',0
.data?
hInstance DWORD ?
hWnd DWORD ?
.code
START:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke WinMain,hInstance,NULL,NULL,SW_SHOWMAXIMIZED ; call the main function
invoke ExitProcess,eax
WinMain proc hInst:DWORD,hPrev:DWORD,lpCmdLn:DWORD,nCmdSh:DWORD
LOCAL wd:WNDCLASS
LOCAL ms:MSG
LOCAL hmn:HMENU
mov wd.style,CS_HREDRAW OR CS_VREDRAW
mov wd.lpfnWndProc,offset WndProc
mov wd.cbClsExtra,NULL
mov wd.cbWndExtra,NULL
push hInst
pop wd.hInstance
invoke LoadIcon,NULL,IDI_APPLICATION
mov wd.hIcon,eax
invoke LoadCursor,NULL,IDC_CROSS
mov wd.hCursor,eax
mov wd.hbrBackground,COLOR_WINDOW+1
mov wd.lpszMenuName,NULL
mov wd.lpszClassName,offset className
invoke LoadMenu,hInstance,offset myMnu
mov hmn,eax
invoke RegisterClass,addr wd
invoke CreateWindowEx,WS_EX_WINDOWEDGE,offset className,offset winName,WS_BORDER OR WS_CAPTION OR WS_OVERLAPPED OR WS_VISIBLE,\
CW_USEDEFAULT,NULL,400,300,NULL,NULL,hInst,NULL
mov hWnd,eax
invoke ShowWindow,hWnd,SW_MAXIMIZE
invoke UpdateWindow,hWnd
MESS_LOOP:
invoke GetMessage,addr ms,NULL,0,0
cmp eax,0
je END_LOOP
invoke DispatchMessage,addr ms
jmp MESS_LOOP
END_LOOP:
mov eax,ms.wParam
ret
WinMain endp
WndProc proc hnd:DWORD,uint:DWORD,wpar:DWORD,lpar:DWORD
LOCAL hmn:HMENU
LOCAL xpos:WORD
LOCAL ypos:WORD
cmp uint,WM_DESTROY
je quit_proc
cmp uint,WM_CONTEXTMENU ;user right-clicked inside window..if yes, we load the menu
jne defProc
invoke LoadMenu,hInstance,offset myMnu
mov hmn,eax
mov eax,lpar
mov xpos,ax
shr eax,16
mov ypos,ax
invoke TrackPopupMenu,hmn,TPM_LEFTALIGN OR TPM_RIGHTBUTTON,100,100,0,hnd,NULL
ret
defProc:
invoke DefWindowProc,hnd,uint,wpar,lpar
ret
quit_proc:
invoke PostQuitMessage,NULL
xor eax,eax
ret
WndProc endp
end START
i've been trying to create those context menus, the ones that popup when u right click inside the window...i am getting the message WM_CONTEXTMENU...but when i invoke TrackPopupMenuEx...sumthing weird happens....basically i tell it to create the context menu at the position 100,100...and sumthing DOES show up there, but its a really thin rectangle...not a proper menu...when u keep the mouse pointer over the upper half of that rectangle...the submenu opens up...its all quite weird, can sum1 pls. tell me whats wrong...here's the source code of the file: (win32.asm)
.386
.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
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
.data
className db 'myClass',0
winName db 'My Window',0
myMnu db 'myMnu',0
.data?
hInstance DWORD ?
hWnd DWORD ?
.code
START:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke WinMain,hInstance,NULL,NULL,SW_SHOWMAXIMIZED ; call the main function
invoke ExitProcess,eax
WinMain proc hInst:DWORD,hPrev:DWORD,lpCmdLn:DWORD,nCmdSh:DWORD
LOCAL wd:WNDCLASS
LOCAL ms:MSG
LOCAL hmn:HMENU
mov wd.style,CS_HREDRAW OR CS_VREDRAW
mov wd.lpfnWndProc,offset WndProc
mov wd.cbClsExtra,NULL
mov wd.cbWndExtra,NULL
push hInst
pop wd.hInstance
invoke LoadIcon,NULL,IDI_APPLICATION
mov wd.hIcon,eax
invoke LoadCursor,NULL,IDC_CROSS
mov wd.hCursor,eax
mov wd.hbrBackground,COLOR_WINDOW+1
mov wd.lpszMenuName,NULL
mov wd.lpszClassName,offset className
invoke LoadMenu,hInstance,offset myMnu
mov hmn,eax
invoke RegisterClass,addr wd
invoke CreateWindowEx,WS_EX_WINDOWEDGE,offset className,offset winName,WS_BORDER OR WS_CAPTION OR WS_OVERLAPPED OR WS_VISIBLE,\
CW_USEDEFAULT,NULL,400,300,NULL,NULL,hInst,NULL
mov hWnd,eax
invoke ShowWindow,hWnd,SW_MAXIMIZE
invoke UpdateWindow,hWnd
MESS_LOOP:
invoke GetMessage,addr ms,NULL,0,0
cmp eax,0
je END_LOOP
invoke DispatchMessage,addr ms
jmp MESS_LOOP
END_LOOP:
mov eax,ms.wParam
ret
WinMain endp
WndProc proc hnd:DWORD,uint:DWORD,wpar:DWORD,lpar:DWORD
LOCAL hmn:HMENU
LOCAL xpos:WORD
LOCAL ypos:WORD
cmp uint,WM_DESTROY
je quit_proc
cmp uint,WM_CONTEXTMENU ;user right-clicked inside window..if yes, we load the menu
jne defProc
invoke LoadMenu,hInstance,offset myMnu
mov hmn,eax
mov eax,lpar
mov xpos,ax
shr eax,16
mov ypos,ax
invoke TrackPopupMenu,hmn,TPM_LEFTALIGN OR TPM_RIGHTBUTTON,100,100,0,hnd,NULL
ret
defProc:
invoke DefWindowProc,hnd,uint,wpar,lpar
ret
quit_proc:
invoke PostQuitMessage,NULL
xor eax,eax
ret
WndProc endp
end START
This might work ;)
invoke LoadMenu,hInstance,offset myMnu
[COLOR=red]invoke GetSubMenu, eax, 0[/COLOR]
mov hmn,eax
i think that mite work (i'll try it now) cos i remember reading sumthing abt loading a submenu for TrackPopupMenuEx in the API doc
thanks :D
thanks :D