News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Error in windows.inc (MENUITEMINFO)?

Started by NoCforMe, March 23, 2015, 10:44:47 AM

Previous topic - Next topic

NoCforMe

Quote from: dedndave on March 24, 2015, 09:24:03 PM
i think you only need to use InsertMenuItem if you are doing an owner-drawn menu
if you like, i can post an example
Thanks, but why would I want an owner-draw menu? I just want a simple, regular ol' menu, like File (Open, Save, Close), Edit (Copy, Paste), etc. Can you post a (simple) example of how to do this? Again, no bitmaps, nothing fancy.

It looks to me from the MSDN docs (and I could be wrong) that one needs to first CreateMenu(), then use InsertMenuItem() for each item one wants.
Assembly language programming should be fun. That's why I do it.

jj2007

Standard template:
  CASE WM_CREATE
mov esi, rv(CreateMenu) ; create the main menu
mov edi, rv(CreateMenu) ; create a sub-menu
invoke AppendMenu, esi, MF_POPUP, edi, chr$("&File") ; add it to the main menu
invoke AppendMenu, edi, MF_STRING, 101, chr$("&Dir") ; and add
invoke AppendMenu, edi, MF_STRING, 102, chr$("&Save") ; two items
invoke SetMenu, hWnd, esi ; attach menu to main window

dedndave

i use CreatePopupMenu to create sub-menus
i only use CreateMenu one time - for the main menu handle
other than that, Jochen has the right idea


dedndave

#19
this example demonstrates a few things

first, it has a sub-sub-menu - you may want one

second, the sub-menu handles are saved in global data
this is optional
at some point, you may want to modify a menu - the handle is nice to have
(check marks, disable items, etc)

finally, it demonstrates another of several ways to attach a menu to a window
you can put the HMENU in the WNDCLASSEX structure
you can pass the HMENU to the CreateWindowEx call (this example uses this method)
or, you can use SetMenu, as Jochen mentioned

i also added appropriate code for File-Exit and Help-About (and, i added a seperator to the file menu)
all other items give you a message box with the ID number

jj2007

One more:
  CASE WM_CREATE ; this message serves to initialise your application
mov esi, rv(CreateMenu) ; create the main menu
mov edi, rv(CreatePopupMenu) ; create a sub-menu
invoke AppendMenu, esi, MF_POPUP, edi, chr$("&File") ; add it to the main menu
mov ebx, rv(CreatePopupMenu) ; create a sub-menu
invoke AppendMenu, ebx, MF_STRING, 121, chr$("&asm") ; fill it
invoke AppendMenu, ebx, MF_STRING, 122, chr$("&inc") ; with various
invoke AppendMenu, ebx, MF_STRING, 123, chr$("&rc") ; options
invoke AppendMenu, edi, MF_POPUP, ebx, chr$("&Dir") ; and add it to the main menu as "Dir"
invoke AppendMenu, edi, MF_STRING, 102, chr$("&Save") ; one more main item
invoke SetMenu, hWnd, esi ; attach menu to main window


NoCforMe

OK, I'm totally confused. I tried this, taking Dave's suggestion to use InsertMenu():

CALL CreateMenu
MOV hMenu, EAX
INVOKE InsertMenu, hMenu, -1, MF_BYPOSITION, 1111, OFFSET FileStr
INVOKE InsertMenu, hMenu, -1, MF_BYPOSITION, 1112, OFFSET EditStr
INVOKE InsertMenu, hMenu, 1, MF_BYPOSITION, 1113, OFFSET OpenStr
INVOKE SetMenu, hWin, hMenu

but no matter what I do, I can  only create more menu headings (i.e., more things on the menu bar), not any items within any menu.  (With this code, I get 3 menu headings--File, Open and Edit.)

How, for instance, do I add that "Open" item to the File menu?
Assembly language programming should be fun. That's why I do it.

dedndave

Dave's suggestion is NOT to use InsertMenuItem

did you download my example in Reply #19
oh, guess not - lol

EDIT: try using AppendMenu

https://msdn.microsoft.com/en-us/library/windows/desktop/ms647616%28v=vs.85%29.aspx

dedndave

probably our fault for not being clear enough.....


use CreateMenu to create the main menu

use CreatePopupMenu to create sub-menus (File, Edit, View, Help, etc)

use AppendMenu to add items to a menu or sub-menu
items may include sub-menus, clickable items, non-clickable seperators
use the appropriate flags

so, for example

CreateMenu - create the main menu (hmenuMain, let's call it)
CreatePopupMenu - to create a sub-menu (hmenuFile)
AppendMenu is then used to add hmenuFile to hmenuMain (MF_POPUP flag)

after that, you use AppendMenu to add items to that sub-menu
most items will be "MF_STRING or'ed with MF_ENABLED"
as it happens, both MF_STRING and MF_ENABLED are the defaults, so their values are 0

use MF_SEPERATOR for a seperator

once you get the hang of it, you can use checked and/or radio-checked items

NoCforMe

That works like a charm. And it's actually easier than creating a menu resource.

I'll use this from now on.
Assembly language programming should be fun. That's why I do it.

dedndave