Hello!
If i want to insert a menu, that is in a resource, in a main-window, i had to write the name of the menu to wc.lpszMenuName. It is very good explained in Iczelion's tutorial 8.
But i want to take the main window from the resource, too. The window is created with "DialogBoxParam" in the code. So i wrote the popup-menu to the resource. But nothing happened. I think, that i must say in the description of the main window, that it should have a menu. Or do i have to say it in the source code?
Can somebody help me?
Guenther
you can use the LoadMenu function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms647990%28v=VS.85%29.aspx
that will give you a handle to the menu
then use SetMenu
http://msdn.microsoft.com/en-us/library/windows/desktop/ms647995%28v=VS.85%29.aspx
to assign that menu handle to a window
in ASM, we usually use control ID numbers, rather than names for menus
Thanks!
Another option is LoadMenuIndirect but LoadMenu is more easy and practical to use.
without LoadMenu/LoadMenuIndirect:
DIALOG(EX) Resource -> optional-statements -> MENU menuname (one of the options for the dialog box) :)
Hallo!
There is also a way to insert a menu in the sourcecode without a resource:
http://andremueller.gmxhome.de/winmenu.html#menuesalles
Best regards,
Guenther
yes - i do something like that, but in a loop with a table of menu items
it is about half the size of creating the menu in resource - at least, if ANSI text is used
if the text is UNICODE, there probably isn't much advantage
Guenther,
You can create and display a menu using Windows API function calls but its a lot more work to do it that way. Storing a menu in a resource script is easier to understand and easier to maintain and modify.
No rocket science needed...
CASE WM_CREATE
; ....
mov hMenu, rv(CreateMenu) ; create the main menu
mov hM1, rv(CreateMenu) ; plus three
mov hM2, rv(CreateMenu) ; sub menus
mov ghM3, rv(CreateMenu)
invoke AppendMenu, hMenu, MF_POPUP, hM1, Chr$("&File")
invoke AppendMenu, hM1, MF_STRING, IdMenuNew, Chr$("&New",9,"Ctrl+N")
invoke AppendMenu, hM1, MF_STRING, IdMenuSave, Chr$("&Save",9,"Ctrl+S")
invoke AppendMenu, hMenu, MF_POPUP, hM2, Chr$("&Edit")
invoke AppendMenu, hM2, MF_STRING, IdMenuCopy, Chr$("&Copy",9,"Ctrl+C")
invoke AppendMenu, hMenu, MF_POPUP, ghM3, Chr$("&Language")
invoke AppendMenu, ghM3, MF_STRING, IdMenuEN, Chr$("&English")
invoke AppendMenu, ghM3, MF_STRING, IdMenuRU, Chr$("&Russian")
invoke AppendMenu, ghM3, MF_STRING, IdMenuAR, Chr$("&Arabic")
invoke AppendMenu, ghM3, MF_STRING, IdMenuCH, Chr$("&Chinese")
invoke SetMenu, hWnd, hMenu ; attach menu to main window
:bg it's still more fun to make a loop...
Sweet - I was just thinking of adding a menu to my project.