The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Guenther on January 06, 2012, 10:23:23 PM

Title: Creation of a menu
Post by: Guenther on January 06, 2012, 10:23:23 PM
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
Title: Re: Creation of a menu
Post by: dedndave on January 06, 2012, 10:54:53 PM
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
Title: Re: Creation of a menu
Post by: Guenther on January 06, 2012, 11:29:56 PM
Thanks!
Title: Re: Creation of a menu
Post by: Vortex on January 07, 2012, 10:38:13 AM
Another option is LoadMenuIndirect but LoadMenu is more easy and practical to use.
Title: Re: Creation of a menu
Post by: kero on January 12, 2012, 01:44:05 PM
without LoadMenu/LoadMenuIndirect:

DIALOG(EX) Resource -> optional-statements -> MENU menuname (one of the options for the dialog box)  :)
Title: Re: Creation of a menu
Post by: Guenther on January 23, 2012, 02:49:53 PM
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
Title: Re: Creation of a menu
Post by: dedndave on January 23, 2012, 03:24:40 PM
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
Title: Re: Creation of a menu
Post by: hutch-- on January 23, 2012, 03:34:03 PM
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.
Title: Re: Creation of a menu
Post by: jj2007 on January 23, 2012, 04:27:14 PM
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

Title: Re: Creation of a menu
Post by: dedndave on January 23, 2012, 04:33:33 PM
 :bg  it's still more fun to make a loop...
Title: Re: Creation of a menu
Post by: DRX on January 24, 2012, 05:35:15 AM
Sweet - I was just thinking of adding a menu to my project.