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

First of all, is this the right place to post this? I would've thought that the MASM forum would be appropriate, but the description says "Please post technical questions in the general forum", so here goes:

I got an error trying to use the MENUITEMINFO structure. While the MSDN documentation shows 12 members, the MASM include file only has 11 (it's missing the last item, HBITMAP hbmpItem). Is this an error? should I just go ahead and fix my copy of the file?
Assembly language programming should be fun. That's why I do it.

dedndave

 :t  good find

Hutch is a little slow getting around to things, sometimes
it's probably on his "to do" list

http://www.masmforum.com/board/index.php?topic=660.0

hutch--

Microsoft keep adding bits to structures so an item that was correct can be missing an addition made later. Usually structures that change over time use the SIZEOF or similar to specify which version they are using.

dedndave


NoCforMe

Quote from: dedndave on March 23, 2015, 11:05:37 AM
it does have a cbSize member

Right, so does that mean that if you use an earlier (i.e., smaller) structure that it'll know to truncate it at the end? Not sure, since I was getting other errors before I fixed the structure.

Anyhoo, I patched my local copy. You might want to update the master copy someday ...
Assembly language programming should be fun. That's why I do it.

NoCforMe

Quote from: dedndave on March 23, 2015, 10:58:12 AM
:t  good find

Hutch is a little slow getting around to things, sometimes
it's probably on his "to do" list

http://www.masmforum.com/board/index.php?topic=660.0

Wow, 2005: a "little slow"?

Isn't there a corps of volunteers somewhere to do this stuff?
Assembly language programming should be fun. That's why I do it.

dedndave

well, can't release a new masm32 package every time someone finds a flaw
of course, you can modify your own INC file
but, that makes you incompatible with other forum members

so - i usually create my own structure definition - and hopefully it gets fixed in a later rev
_MENUITEMINFO STRUCT
or something similar

hutch--

NoCforMe,

Dave's solution is the right one but don't let me stop you from creating an up to date set of includes for Windows. These things are a genuine joy to maintain and if you get it slightly wrong it explodes in your face.

jj2007

Quote from: NoCforMe on March 23, 2015, 10:44:47 AMI got an error trying to use the MENUITEMINFO structure.

What kind of error? If the size member is set, Windows shouldn't complain.
Re 2005: There was not a single reply to this post, so it probably went unnoticed. Go for the "genuine joy" ;-)

NoCforMe

Quote from: jj2007 on March 23, 2015, 09:24:26 PM
Quote from: NoCforMe on March 23, 2015, 10:44:47 AMI got an error trying to use the MENUITEMINFO structure.

What kind of error? If the size member is set, Windows shouldn't complain.

Windows didn't complain; MASM did (too many initializers for a structure).

Heh; I ended up abandoning this project anyhow (I learned it's too big a pain in the ass to try to construct menus programmatically rather than as a linked resource.)
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on March 24, 2015, 12:29:46 PM(I learned it's too big a pain in the ass to try to construct menus programmatically rather than as a linked resource.)

Depends on your libraries ;-)

GuiParas equ "Hello jj2007", x650, y20, w200, h200, sWS_CAPTION OR WS_POPUPWINDOW, cblack, b00FFFFD0h
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm
Event Menu
  Switch MenuID
  Case IDM0
      MsgBox 0, "Open", "Hi", MB_OK
  Case IDM1
      MsgBox 0, "Save", "Hi", MB_OK
  Default
      MsgBox 0, Str$("Menu #%i", MenuID), "Hi", MB_OK
  Endsw
GuiEnd

dedndave

i don't know that you need the functions that use that structure to create menus
this is a proc i use at initialization to create context menus
not much different from menu bar type menus

IDM_??? are menu id constants (equates)
sz???? are menu strings

;***********************************************************************************************

CreateContextMenus PROC

    push    ebx
    push    esi
    INVOKE  CreateMenu
    xchg    eax,ebx

;hmenuHiRes

    INVOKE  CreatePopupMenu
    xchg    eax,esi
    mov     hmenuContext,ebx
    INVOKE  AppendMenu,ebx,MF_POPUP,esi,NULL
    mov     hmenuHiRes,esi
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HRSETREF1,offset szMenuHR01
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HRSETREF2,offset szMenuHR02
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HRSETREF3,offset szMenuHR03
    INVOKE  AppendMenu,esi,MF_SEPARATOR,NULL,NULL
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HRADDSWLOW,offset szMenuHR04
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HRDELMARK,offset szMenuHR05
    INVOKE  AppendMenu,esi,MF_SEPARATOR,NULL,NULL
    INVOKE  AppendMenu,esi,MF_STRING or MF_GRAYED,IDM_HRENHANCE,offset szMenuHR06
    INVOKE  AppendMenu,esi,MF_SEPARATOR,NULL,NULL
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HIDECURS,offset szMenuHR08

;hmenuVblank

    INVOKE  CreatePopupMenu
    xchg    eax,esi
    INVOKE  AppendMenu,ebx,MF_POPUP,esi,NULL
    mov     hmenuVblank,esi
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HIDECURS,offset szMenuVP06

;hmenuVesoph

    INVOKE  CreatePopupMenu
    xchg    eax,esi
    INVOKE  AppendMenu,ebx,MF_POPUP,esi,NULL
    mov     hmenuVesoph,esi
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_VEGRPHAUX,offset szMenuVP01
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_VEGRPHREF1,offset szMenuVP02
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_VEGRPHREF2,offset szMenuVP03
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_VEGRPHREF3,offset szMenuVP04
    INVOKE  AppendMenu,esi,MF_SEPARATOR,NULL,NULL
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HIDECURS,offset szMenuVP06
    mov     eax,IDM_VEGRPHAUX
    INVOKE  CheckMenuRadioItem,esi,eax,IDM_VEGRPHREF3,eax,MF_BYCOMMAND

;hmenuVgraph

    INVOKE  CreatePopupMenu
    xchg    eax,esi
    INVOKE  AppendMenu,ebx,MF_POPUP,esi,NULL
    mov     hmenuVgraph,esi
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_VGGRPHAUX,offset szMenuVP01
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_VGGRPHREF1,offset szMenuVP02
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_VGGRPHREF2,offset szMenuVP03
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_VGGRPHREF3,offset szMenuVP04
    INVOKE  AppendMenu,esi,MF_SEPARATOR,NULL,NULL
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HIDECURS,offset szMenuVP06
    mov     eax,IDM_VGGRPHAUX
    INVOKE  CheckMenuRadioItem,esi,eax,IDM_VGGRPHREF3,eax,MF_BYCOMMAND

;hmenuHblank

    INVOKE  CreatePopupMenu
    xchg    eax,esi
    INVOKE  AppendMenu,ebx,MF_POPUP,esi,NULL
    mov     hmenuHblank,esi
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HIDECURS,offset szMenuHP11

;hmenuHupper

    INVOKE  CreatePopupMenu
    xchg    eax,esi
    INVOKE  AppendMenu,ebx,MF_POPUP,esi,NULL
    mov     hmenuHupper,esi
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHUSUP,offset szMenuHP01
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHUES,offset szMenuHP02
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHUINF,offset szMenuHP03
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHPIP,offset szMenuHP04
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHLSUP,offset szMenuHP05
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHLES,offset szMenuHP06
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHLINF,offset szMenuHP07
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHAUX1,offset szMenuHP08
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHAUX2,offset szMenuHP09
    INVOKE  AppendMenu,esi,MF_SEPARATOR,NULL,NULL
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HIDECURS,offset szMenuHP11
    INVOKE  CheckMenuRadioItem,esi,IDM_HGRPHUSUP,IDM_HGRPHAUX2,IDM_HGRPHAUX1,MF_BYCOMMAND

;hmenuHlower

    INVOKE  CreatePopupMenu
    xchg    eax,esi
    INVOKE  AppendMenu,ebx,MF_POPUP,esi,NULL
    mov     hmenuHlower,esi
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHUSUP,offset szMenuHP01
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHUES,offset szMenuHP02
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHUINF,offset szMenuHP03
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHPIP,offset szMenuHP04
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHLSUP,offset szMenuHP05
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHLES,offset szMenuHP06
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHLINF,offset szMenuHP07
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHAUX1,offset szMenuHP08
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HGRPHAUX2,offset szMenuHP09
    INVOKE  AppendMenu,esi,MF_SEPARATOR,NULL,NULL
    INVOKE  AppendMenu,esi,MF_STRING or MF_ENABLED,IDM_HIDECURS,offset szMenuHP11
    INVOKE  CheckMenuRadioItem,esi,IDM_HGRPHUSUP,IDM_HGRPHAUX2,IDM_HGRPHAUX2,MF_BYCOMMAND
    pop     esi
    pop     ebx
    ret

CreateContextMenus ENDP

;***********************************************************************************************


it's actually the same thing the OS does if you create it in resource   :P

NoCforMe

Um, no, not the same thing as regular old menu-bar menus. But yep, context menus are real easy to create.

To create (bar) menus you have to go through a lot of nonsense with InsertMenuItem() (that's the function that uses the structure being discussed here), with what seems like a kajillion flags and type descriptors and whatnot that have to be set. Not worth it; I can just make a copy of a resource file for another project, change some names, add the resource compile and link steps in my batch file and off I go.

Too bad I'm not a MasmBasic user ...
Assembly language programming should be fun. That's why I do it.

dedndave

i think you only need to use InsertMenuItem if you are doing an owner-drawn menu
if you like, i can post an example

dedndave

i will add this....

i once thought there was an advantage to writing menus in code - and, in some cases, there is
when you write a menu in the resource, all the strings are stored as UNICODE
that makes the EXE a little larger

as time goes on, i am realizing that any "real" app should start out as UNICODE, anyways - lol
if it's worth publishing, it's worth supporting multiple languages

and - here's the lesson learned....
it's a lot easier to start out writing an app with UNICODE windows
than it is to write it with ANSI windows, then go back and change it to UNICODE   :P

all that kind of negates any advantage in reducing EXE size