Author Topic: Error in windows.inc (MENUITEMINFO)?  (Read 5411 times)

NoCforMe

  • Member
  • **
  • Posts: 72
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #15 on: March 25, 2015, 05:07:17 AM »
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.

jj2007

  • Member
  • *****
  • Posts: 7752
  • Assembler is fun ;-)
    • MasmBasic
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #16 on: March 25, 2015, 05:41:39 AM »
Standard template:
Code: [Select]
  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

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #17 on: March 25, 2015, 05:51:40 AM »
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

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #19 on: March 25, 2015, 06:47:40 AM »
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
« Last Edit: March 25, 2015, 03:30:54 PM by dedndave »

jj2007

  • Member
  • *****
  • Posts: 7752
  • Assembler is fun ;-)
    • MasmBasic
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #20 on: March 25, 2015, 08:45:22 AM »
One more:
Code: [Select]
  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

  • Member
  • **
  • Posts: 72
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #21 on: March 27, 2015, 04:28:50 PM »
OK, I'm totally confused. I tried this, taking Dave's suggestion to use InsertMenu():
Code: [Select]
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?

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #22 on: March 27, 2015, 05:03:03 PM »
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

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #23 on: March 27, 2015, 06:29:57 PM »
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

  • Member
  • **
  • Posts: 72
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #24 on: March 28, 2015, 06:37:56 AM »
That works like a charm. And it's actually easier than creating a menu resource.

I'll use this from now on.

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: Error in windows.inc (MENUITEMINFO)?
« Reply #25 on: March 28, 2015, 12:50:41 PM »
 :t