Hi all !
Please tell me how to add 1 menuitem in a popup menu.
I need your help.
Posted on 2002-05-04 14:34:29 by crazy gun


call CreatePopupMenu
mov hMenu, eax

invoke AppendMenu, hMenu, MF_STRING, MNU_PLAYFILES, addr szMenuPlayFiles
invoke AppendMenu, hMenu, MF_STRING, MNU_PLAYDIR, addr szMenuPlayDir
invoke AppendMenu, hMenu, MF_SEPARATOR, 0, 0
invoke AppendMenu, hMenu, MF_STRING, MNU_EXIT, addr szMenuExit

invoke TrackPopupMenu, hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hWin, 0



You can also use a RC file. But I prefer the API way :)

BTW, please don't post such questions in the Algo & Source forum.
Posted on 2002-05-04 14:42:56 by bazik
Thankx. I'm sorry, i don't know where to post this thread.
Posted on 2002-05-04 14:48:09 by crazy gun
Please send me an example program to : cuong_hh@yahoo.com.
Thankx.
Posted on 2002-05-04 14:51:34 by crazy gun
crazy gun,
please take a look here: Doing other peoples (home)work
Posted on 2002-05-04 14:58:47 by bazik
hi crazy gun welcome to the board,

here is a simple example. i used iczelions tutorial #3 source code and modified bazik's code somewhat to show you an example. the menu has no functionality so you will need to implement that. you seem to be pretty new have you checked out iczelions tutoirals yet? you can cut and paste into the editor your using to assemble with.
.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

ID_1 equ 2000
ID_2 equ 2001
ID_3 equ 2002

.data
ClassName db "SimpleWinClass",0
AppName db "Our First Window",0
Item1 db "This is item 1",0
Item2 db "This is item 2",0
Item3 db "This is item 3",0

.data?
hInstance dd ?
CommandLine dd ?
hMenu dd ?
pt POINT <?>

.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
invoke ExitProcess, eax

WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
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, OFFSET ClassName
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,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
hInst,NULL
mov hwnd, eax
invoke ShowWindow, hwnd, SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg, NULL, 0, 0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_DESTROY
invoke PostQuitMessage, NULL

.elseif uMsg==WM_CREATE
INVOKE CreateWindowEx, 0,
ADDR ClassName,
0,
WS_VISIBLE + WS_CHILD,
0,0,300,300,
hWnd,NULL,
hInstance,
0

call CreatePopupMenu
mov hMenu, eax

invoke AppendMenu, hMenu, MF_STRING, ID_1, addr Item1
invoke AppendMenu, hMenu, MF_STRING, ID_2, addr Item2
invoke AppendMenu, hMenu, MF_SEPARATOR, 0, 0
invoke AppendMenu, hMenu, MF_STRING, ID_3, addr Item3

.elseif uMsg == WM_RBUTTONDOWN
invoke GetCursorPos,addr pt
invoke TrackPopupMenu, hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, 0
.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.endif
xor eax,eax
ret
WndProc endp
end start
Posted on 2002-05-04 15:49:04 by smurf