News:

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

Main Menu

Popup Menu

Started by clamicun, April 09, 2019, 12:16:59 AM

Previous topic - Next topic

clamicun

This is an old example from jj - Oct. 2013 - simplewin
Create a menu and submenu without a resource file

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$("&New")   ; and add submenu
invoke AppendMenu, edi, MF_STRING, 102, chr$("&Save")   
invoke AppendMenu, edi, MF_STRING, 103, chr$("&Save as")
invoke AppendMenu, edi, MF_STRING, 104, chr$("&Exit")   

invoke SetMenu, hWnd, esi      ; attach menu to main window

I can write:
invoke AppendMenu, esi, MF_POPUP, edi, chr$("&File")       ; add it to the main menu
invoke AppendMenu, esi, MF_POPUP, edi, chr$("&Extras")  ; add it to the main menu
and have File and Extras in the menubar.

Both show the same dropdownmenu
New
Save
Save as
Exit

How to get different Strings in Extras ?

jj2007

Just repeat the steps:
mov ebx, rv(CreateMenu) ; create the main menu

mov esi, rv(CreatePopupMenu) ; create a sub-menu
invoke AppendMenu, esi, MF_STRING, 121, chr$("&Open") ; fill it
invoke AppendMenu, esi, MF_STRING, 122, chr$("&Save") ; with various
invoke AppendMenu, esi, MF_STRING, 123, chr$("Save&As") ; options
invoke AppendMenu, ebx, MF_POPUP, esi, chr$("&File") ; add it to the main menu

mov esi, rv(CreatePopupMenu) ; create a sub-menu
invoke AppendMenu, esi, MF_STRING, 121, chr$("&Copy") ; fill it
invoke AppendMenu, esi, MF_STRING, 122, chr$("&Paste") ; with various
invoke AppendMenu, esi, MF_STRING, 123, chr$("&Cut") ; options
invoke AppendMenu, ebx, MF_POPUP, esi, chr$("E&xtras") ; add it to the main menu
invoke SetMenu, hWnd, ebx ; attach menu to main window

clamicun

jj,
thank a lot.
I got it.
There is no difference between CreateMenu and CreatePopupMenu ?

clamicun

One last question.
In most popupmenu/dropdownmenus - resourcemenus as well  I see  &Open &Save ...
It functions without as well.
What is & good for ?

jj2007

The ampersand in e.g. "Save &as" says "user can use the A key to choose that menu item".

TimoVJL

May the source be with you

Vortex

Quote from: clamicun on April 09, 2019, 06:22:37 AM
There is no difference between CreateMenu and CreatePopupMenu ?

Article : What's the difference between CreateMenu and CreatePopupMenu?

QuoteCreateMenu creates a horizontal menu bar, suitable for attaching to a top-level window. This is the sort of menu that says "File, Edit", and so on.
CreatePopupMenu creates a vertical popup menu, suitable for use as a submenu of another menu (either a horizontal menu bar or another popup menu) or as the root of a context menu.
If you get the two confused, you can get strange menu behavior. Windows on rare occasions detects that you confused the two and converts as appropriate, but I wouldn't count on Windows successfully reading your mind.

https://devblogs.microsoft.com/oldnewthing/20031230-00/?p=41273

clamicun

Article : What's the difference between CreateMenu and CreatePopupMenu?

Yes, good explanation by Raymond

clamicun

Hallelujah,
finally I have the bitmaps in the menubar.
Only thing I am still trying to change is the color of the menubar ? 

jj2007

Congrats :t

So you basically wanted a toolbar that opens popups. That was not so clear from the beginning ;-)

clamicun

jj,
yes, but with bitmaps in the menubar because it looks "better" in my project.
Any idea how to change the color of the menubar ?
Seems to be white by default.

Create a brush and
INVOKE FillRect,handle of the  menu ... ?

There is an example in goasm.

clamicun

Can someone show an example for:

invoke GetMenuBarInfo,handle_win, OBJID_MENU,0,addr mbi

Whatever I try, the return is error 87 - wrong parameter

TimoVJL

#12
Is mbi.cbSize set to sizeof(mbi) ?

EDIT: http://masm32.com/board/index.php?topic=3176.0

EDIT: sizeof = 32MENUBARINFO STRUCT
cbSize DWORD ?
rcBar RECT <>
hMenu PTR ?
hwndMenu PTR ?
fBarFocused DWORD ?
; fFocused DWORD ?
MENUBARINFO ENDS
May the source be with you

clamicun

#13
sure it is.

I see "the structure" in windows.inc might be wrong.
I sure dont't know how to fix that

aw27

The structure is wrong in Windows.inc

Try:

(untested)

BFIELD RECORD fBarFocused:1,fFocused:1, Other:30

_MENUBARINFO struct
  cbSize DWORD sizeof _MENUBARINFO
  rcBar RECT <0>
  hMenu HMENU 0
  hwndMenu HWND 0
  bitf BFIELD <0>
_MENUBARINFO ends


.data
mbar _MENUBARINFO <>

There is a macro somewhere to retrieve bit fields, if needed. But it can be done without macro.