flat assembler
Message board for the users of flat assembler.
Index
> Windows > MNS_NOTIFYBYPOS how set ? |
| Author |
|
|
Roman 02 Nov 2025, 07:04
fasmw 1.73
I created menu Code: section '.rsrc' resource data readable directory RT_MENU,menus resource menus,IDR_MAINMENU,LANG_ENGLISH+SUBLANG_DEFAULT,mainMenu menu mainMenu ;{ menuitem '&File',0,MFR_POPUP ;{ menuitem '&New',IDM_NEW menuitem '&Open',IDM_OPEN menuseparator menuitem 'Save',IDM_SAVE,MFR_END menuitem 'exit',IDM_exit,MFR_END I want get in wndproc WM_MENUCOMMAND when popup menu '&File' items. How set menu MNS_NOTIFYBYPOS style ? whitout this style not work WM_MENUCOMMAND. https://i.sstatic.net/TJsgU.gif |
|||
|
|
Walter 03 Nov 2025, 18:12
There is SetMenuItemInfo
MIM_STYLE dwStyle and MNS_NOTIFYBYPOS would be set in a MENUINFO structure before the call. |
|||
|
|
Roman 04 Nov 2025, 08:30
Walter when I must call SetMenuItemInfo ?
And how I get my menu from resource section? For SetMenuItemInfo need handle menu. How get handle my menu in my case? Using WM_CREATE in wndproc? Calendos no. Thanks. |
|||
|
|
macomics 04 Nov 2025, 15:48
|
|||
|
|
Roman 04 Nov 2025, 17:34
I found this
Code: hMenu=GetMenu(hwnd); if (hMenu!=NULL) { int iCount; iCount=GetMenuItemCount(hMenu); cout << "Menu Item - " << iCount << endl; } I do this in WM_CREATE and I get 2 elements menu! But GetMenuInfo return empty MENUINFO struct. Code: .if [msg] = WM_CREATE invoke GetMenu,[hWnd] mov [@hmenu],eax invoke GetMenuItemCount,eax mov [MenuItemCount],eax prInt eax ;show 2 elements menu mov dword [Status22],7*4 ;size MENUINFO invoke GetMenuInfo,[@hmenu],Status22 ;return eax=1. MSDN say error if eax=0 invoke GetLastError ;return eax=0 prInt dword [Status22+4] ;empty return 0 .endif .if [msg] = WM_MENUCOMMAND ;must be flag menu style MNS_NOTIFYBYPOS invoke GetMenuStringA,[lParam],0,outTxt,100,MF_BYPOSITION Msg outTxt return 0 .endif |
|||
|
|
Walter 05 Nov 2025, 21:52
Roman,
Try this example and see if this index approach is similar to what you need. SetMenuItemInfo should have been SetMenuInfo. Code: ;********************* ;* WmMenuCommand.asm * ;********************* format PE GUI 4.0 entry start include 'win32a.inc' struct MENUINFO cbSize dd ? fMask dd ? dwStyle dd ? cyMax dd ? hbrBack dd ? dwContextHelpID dd ? dwMenuData dd ? ends MIM_APPLYTOSUBMENUS = 0x80000000 MIM_STYLE = 0x00000010 MNS_NOTIFYBYPOS = 0x08000000 IDR_MENU = 100 IDM_FILE_NEW = 101 IDM_FILE_OPEN = 102 IDM_FILE_EXIT = 103 POS_FILE_NEW = 0 POS_FILE_OPEN = 1 POS_FILE_EXIT = 3 section '.text' code readable executable start: invoke GetModuleHandle,0 mov [wc.hInstance],eax invoke LoadIcon,eax,IDI_APPLICATION mov [wc.hIcon],eax invoke LoadCursor,0,IDC_ARROW mov [wc.hCursor],eax invoke RegisterClass,wc test eax,eax jz error invoke LoadMenu,[wc.hInstance],IDR_MENU mov [hMenu],eax invoke CreateWindowEx,0,strClass,strTitle,WS_VISIBLE+WS_OVERLAPPEDWINDOW,\ 144,128,256,256,\ NULL,[hMenu],[wc.hInstance],NULL mov [hWindow],eax test eax,eax jz error ; LoadMenu saved this after getting it from resource. ; invoke GetMenu,[hWindow] ; mov [hMenu],eax mov [mi.cbSize],sizeof.MENUINFO mov [mi.fMask],MIM_STYLE mov [mi.dwStyle],MNS_NOTIFYBYPOS invoke SetMenuInfo,[hMenu],mi msg_loop: invoke GetMessage,msg,NULL,0,0 cmp eax,1 jb end_loop jne msg_loop invoke TranslateMessage,msg invoke DispatchMessage,msg jmp msg_loop error: invoke MessageBox,NULL,strError,NULL,MB_ICONERROR+MB_OK end_loop: invoke ExitProcess,[msg.wParam] proc WindowProc hwnd,wmsg,wparam,lparam push ebx esi edi mov eax,[wmsg] cmp eax,WM_COMMAND je .wmcommand cmp eax,WM_MENUCOMMAND je .wmmenucommand cmp eax,WM_DESTROY je .wmdestroy .defwndproc: invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] jmp .finish .wmcommand: mov eax,[wparam] and eax,0FFFFh cmp eax,IDM_FILE_NEW je .m1 cmp eax,IDM_FILE_OPEN je .m2 cmp eax,IDM_FILE_EXIT je .wmdestroy jmp .defwndproc .m1: invoke MessageBox,NULL,strWM1,strTitle,MB_OK jmp .finish .m2: invoke MessageBox,NULL,strWM1,strTitle,MB_OK jmp .finish .wmmenucommand: invoke MessageBox,NULL,strWM2,strTitle,MB_OK ; wParam is zero-based index of item selected. ; Seperators get indexes too. cinvoke wsprintf,strIndex,strFormat,[wparam] invoke MessageBox,NULL,strIndex,strTitle,MB_OK mov eax,[wparam] cmp eax,POS_FILE_EXIT je .wmdestroy jmp .defwndproc jmp .finish .wmdestroy: invoke PostQuitMessage,0 xor eax,eax .finish: pop edi esi ebx ret endp section '.data' data readable writeable strWM1 db 'Got WM_COMMAND message.',0 strWM2 db 'Got WM_MENUCOMMAND message.',0 strTitle db 'WmMenuCommand',0 strError db 'Startup failed.',0 strClass db 'WmMenuCommand',0 wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,strClass hMenu dd ? hWindow dd ? msg MSG mi MENUINFO strFormat db '%d',0 strIndex rb 16 section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ GetModuleHandle,'GetModuleHandleA',\ ExitProcess,'ExitProcess' import user,\ RegisterClass,'RegisterClassA',\ CreateWindowEx,'CreateWindowExA',\ SetMenuInfo,'SetMenuInfo',\ DefWindowProc,'DefWindowProcA',\ GetMenu,'GetMenu',\ GetMessage,'GetMessageA',\ TranslateMessage,'TranslateMessage',\ DispatchMessage,'DispatchMessageA',\ LoadCursor,'LoadCursorA',\ LoadIcon,'LoadIconA',\ LoadMenu,'LoadMenuA',\ MessageBox,'MessageBoxA',\ wsprintf,'wsprintfA',\ PostQuitMessage,'PostQuitMessage' section '.rsrc' resource data readable directory RT_MENU,menus resource menus,\ IDR_MENU,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu menu main_menu menuitem '&File',0,MFR_POPUP + MFR_END menuitem '&New',IDM_FILE_NEW menuitem '&Open...',IDM_FILE_OPEN menuseparator menuitem 'E&xit',IDM_FILE_EXIT,MFR_END |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.