Author Topic: Popup Menu  (Read 3261 times)

clamicun

  • Member
  • ***
  • Posts: 347
Popup Menu
« on: April 09, 2019, 12:16:59 AM »
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

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: Popup Menu
« Reply #1 on: April 09, 2019, 01:04:44 AM »
Just repeat the steps:
Code: [Select]
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

  • Member
  • ***
  • Posts: 347
Re: Popup Menu
« Reply #2 on: April 09, 2019, 06:22:37 AM »
jj,
thank a lot.
I got it.
There is no difference between CreateMenu and CreatePopupMenu ?

clamicun

  • Member
  • ***
  • Posts: 347
Re: Popup Menu
« Reply #3 on: April 09, 2019, 06:37:03 AM »
One last question.
In most popupmenu/dropdownmenus - resourcemenus as well  I see  &Open &Save ...
It functions without as well.
What is & good for ?

jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: Popup Menu
« Reply #4 on: April 09, 2019, 12:32:51 PM »
The ampersand in e.g. "Save &as" says "user can use the A key to choose that menu item".

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Popup Menu
« Reply #5 on: April 09, 2019, 03:40:33 PM »
May the source be with you

Vortex

  • Member
  • *****
  • Posts: 2030
Re: Popup Menu
« Reply #6 on: April 10, 2019, 03:15:35 AM »
There is no difference between CreateMenu and CreatePopupMenu ?

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

Quote
CreateMenu 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

  • Member
  • ***
  • Posts: 347
Re: Popup Menu
« Reply #7 on: April 10, 2019, 10:19:41 PM »
Article : What's the difference between CreateMenu and CreatePopupMenu?

Yes, good explanation by Raymond

clamicun

  • Member
  • ***
  • Posts: 347
Re: Popup Menu
« Reply #8 on: April 11, 2019, 11:37:29 PM »
Hallelujah,
finally I have the bitmaps in the menubar.
Only thing I am still trying to change is the color of the menubar ? 

jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: Popup Menu
« Reply #9 on: April 11, 2019, 11:40:33 PM »
Congrats :t

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

clamicun

  • Member
  • ***
  • Posts: 347
Re: Popup Menu
« Reply #10 on: April 12, 2019, 02:33:02 AM »
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

  • Member
  • ***
  • Posts: 347
Re: Popup Menu
« Reply #11 on: April 14, 2019, 12:40:26 AM »
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

  • Member
  • ***
  • Posts: 476
Re: Popup Menu
« Reply #12 on: April 14, 2019, 12:58:58 AM »
Is mbi.cbSize set to sizeof(mbi) ?

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

EDIT: sizeof = 32
Code: [Select]
MENUBARINFO STRUCT
 cbSize DWORD ?
 rcBar RECT <>
 hMenu PTR ?
 hwndMenu PTR ?
 fBarFocused DWORD ?
; fFocused DWORD ?
MENUBARINFO ENDS
« Last Edit: April 14, 2019, 03:48:29 AM by TimoVJL »
May the source be with you

clamicun

  • Member
  • ***
  • Posts: 347
Re: Popup Menu
« Reply #13 on: April 14, 2019, 02:01:48 AM »
sure it is.

I see "the structure" in windows.inc might be wrong.
I sure dont't know how to fix that
« Last Edit: April 14, 2019, 03:50:43 AM by clamicun »

AW

  • Member
  • *****
  • Posts: 2434
  • Let's Make ASM Great Again!
Re: Popup Menu
« Reply #14 on: April 14, 2019, 04:41:24 AM »
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.