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 ?
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
jj,
thank a lot.
I got it.
There is no difference between CreateMenu and CreatePopupMenu ?
One last question.
In most popupmenu/dropdownmenus - resourcemenus as well I see &Open &Save ...
It functions without as well.
What is & good for ?
The ampersand in e.g. "Save &as" says "user can use the A key to choose that menu item".
Menu Access Keys (https://docs.microsoft.com/fi-fi/windows/desktop/menurc/about-menus#menu-access-keys)
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
Article : What's the difference between CreateMenu and CreatePopupMenu?
Yes, good explanation by Raymond
Hallelujah,
finally I have the bitmaps in the menubar.
Only thing I am still trying to change is the color of the menubar ?
Congrats :t
So you basically wanted a toolbar that opens popups. That was not so clear from the beginning ;-)
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.
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
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
sure it is.
I see "the structure" in windows.inc might be wrong.
I sure dont't know how to fix that
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.
AW,
thanks. Had the same (similar) ideia.
_MENUBARINFO STRUCT
cbSize DWORD ?
rcBar RECT <>
hMenu DWORD ?
hwndMenu DWORD ?
fBarFocused WORD ?
fFocused WORD ?
_MENUBARINFO ENDS
At least GetMenuBarInfo returns 1
AW,
yes, your structure seems to work.
But I do not understand the values returned by rcBar
mbar.rcBar.left"
mbar.rcBar.right
...
...
They definitely dont correspond to my menu, created with CreateMenu
invoke GetMenuBarInfo.hwnd
MS says: "A handle to the window (menu bar) whose information is to be retrieved."
That is the handle of the mainwindow which contains the menu or to the menubar ?
I understand your code is secret and you can't publish it but I have no idea what you are doing.
AW,
???
Why my code is secret ?
I wrote this a couple of times by now:
invoke GetMenuBarInfo,handle_win, OBJID_MENU,0,addr -mbi
(Last time I asked this: handle_win is the handle of the mainwindow of the application or ?)
I check the values
_mbi.rcBar.right
_mbi.rcBar.bottom
Weird values.
They very likely should be:
right = mainwindow width
bottom = ca. 25p (menubar with text)
If the function returns false then use GetLastError to know the exact reason for the error. ;)
AW,
???
I wrote that already. With your modified structure the function GetMenuBarInfo returns 1.
I am talking about the values of _mbi.rcBar.
If you don't show your code, all I can do is wish you a good luck, you may even find the bug by yourself. :t
Thank you very much. You're really stubborn ... show code ... it's a normal window ... In WM_CREATE I create a menu and popupmenu. Everything is business as usual and works fine ... What would you like to see ? ... I am just trying to get all sorts of info about the menubar, cause I would like to change the color of it. Right now it's "GetMenuBarInfo" I am playing with and simply do not understand the values of _mbi.rcBar. right, bottom, left ... btw. the code is in my file.zip
By now I read about 15 articles on GetMenuBarInfo.
I swear noone mentioned that the values returned by mbi.rcBar. ...
correspond to screendimensions.
Clamicum:
You have not posted files using structure.
Sometimes I forgot to make (before to getinfo):mov mbi.cbsize, sizeof _MENUBARINFO
In the 15 articles have to say: A handle to the menu bar whose information is to be retrieved! (ebx in MinWin)
HSE,
I was talking on the strange results in mbi.RcBar. xxx
They are not strange at all if you know, that they correspond to Screendimensions
Work perfect but is owner Window handle: invoke GetMenuBarInfo, hWnd, OBJID_MENU,0, addr mbi
No chance to colorize the menubar
??
Quote from: clamicun on April 20, 2019, 08:14:14 PM
No chance to colorize the menubar
Why don't you go for The Real Thing - a
toolbar?
jj,
The Real Thing ... What actually is the differenz between toolbar and menubar ?
btw.
7-zip: Die Datei ToolbarDemoJpg.zip kann nicht geöffnet werden. Ist kein Archiv.
Not important if it is just a picture
Quote from: clamicun on April 20, 2019, 08:14:14 PM
No chance to colorize the menubar
??
No problem I think, but you have to subclass menubar.
Funny thing is that everything seems to be ok.
invoke SetMenuInfo returns 1.
Is it the SolidBrush ?
background color is a menu feature. HMENU hMenu = GetSystemMenu(hWnd, 0);
MENUINFO mi;
mi.cbSize = sizeof(MENUINFO);
mi.fMask = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
mi.hbrBack = GetStockObject(GRAY_BRUSH);
SetMenuInfo(hMenu, &mi);
toolbar / rebar can act as menubar, An old internet explorer is a good example.
Also TLPEView (http://masm32.com/board/index.php?topic=7435.msg81276#msg81276) use normal toolbar for menu, and at least jj knows how it works.
That is "C" not assembly!
TimoVJL,
mov mi.fMask,MIM_BACKGROUND or MIM_APPLYTOSUBMENUS
invoke GetStockObject,GRAY_BRUSH
mov mi.hbrBack,eax
paints the submenu gray but the menubar is still white.
No problem I think, but you have to subclass menubar.
? What does that mean ?
Quote from: clamicun on April 21, 2019, 04:01:40 AM
? What does that mean ?
Not worry, apparently doesn't work.
Nobody has an idea ?. It must be possible to colorize a menubar
:(
Search for "TBSTYLE_CUSTOMERASE", or go straight to SOF (https://stackoverflow.com/questions/26941925/how-to-change-toolbar-control-color).
jj, thank you and happy easter !
Use the TBSTYLE_CUSTOMERASE style on the control:
Generates NM_CUSTOMDRAW notification codes when the toolbar processes WM_ERASEBKGND messages.
Then you handle the NM_CUSTOMDRAW notification and when you get the CDDS_PREERASE event, draw your own background and return CDRF_SKIPDEFAULT.
That definitely makes lots of sense to me. Starting with what control.
The menu is created with CreateMenu and CreatePopupMenu.
Toolbar have options TBSTYLE_FLAT and TBSTYLE_TRANSPARENT, for no background erasing.
TimoVJL,
This produces a perfekt dropdownmenu.
mov ebx, rv(CreateMenu) ; create the main menu
mov esi, rv(CreatePopupMenu) ; create the first sub-menu
invoke AppendMenu, esi, MF_STRING, 101, chr$("&Open") ; fill it
invoke AppendMenu,esi,MF_SEPARATOR,0,0
invoke AppendMenu, esi, MF_STRING, 102, chr$("&Save") ; with various
invoke AppendMenu,esi,MF_SEPARATOR,0,0
invoke AppendMenu, esi, MF_STRING, 103, chr$("Save&As") ; options
invoke AppendMenu,esi,MF_SEPARATOR,0,0
invoke AppendMenu, esi, MF_STRING, 105, chr$("&Exit")
invoke AppendMenu, ebx,MF_POPUP,esi,chr$("&File") ; add sub-menu to the main menu
invoke SetMenu, hWnd, ebx ; attach menu to main window
All I want is colorizing the menubar.
Where to insert "Toolbar Control and Button Styles" ?
Quote from: clamicun on April 22, 2019, 02:20:50 AMWhere to insert "Toolbar Control and Button Styles" ?
Menus and toolbars are very different animals...
invoke CreateWindowEx, 0, Chr$("ToolbarWindow32"), 0,
WS_CHILD or WS_VISIBLE or CCS_ADJUSTABLE or TBSTYLE_FLAT or TBSTYLE_AUTOSIZE or TBSTYLE_CUSTOMERASE,
0, 0, 99, 99, hWin, eax, esi, NULL ; TbStartID-1, allows to get handle
...
mov imgList, rv(ImageList_Create, eax, eax, ILC_MASK or ILC_COLOR24, maxfiles, 0) ; inspired by deutsche Site (https://www.c-plusplus.net/forum/48288-full)TB_ADDBUTTONS ... TB_SETIMAGELIST ... etc, the whole module is over 500 lines and somewhat complicated, can't post it here. Check if it should look like the attached exe.
Quote from: clamicun on April 22, 2019, 02:20:50 AM
All I want is colorizing the menubar.
I found that menubar is drawing calling
apfnSimpleCall. Then is a 1985 Windows function. For sure, at that time, developers think that modifications in SystemColors were enough.
Like JJ and Timo pointed, toolbar control provide all needed to replace menubar.
Menus and toolbars are very different animals...
Ja, Jochen,
In Deinem SimpleEditor "File Language" ist die Menubar (menubar ?), die Bitmaps sind in der Toolbar (toolbar ?).
Irgendwie rede ich permanent an jedem vorbei oder jeder redet an mir vorbei.
In meinem Beispiel - Post vor Deinem - rede ich von Dropdownmenu.
Das Beispiel ist Dein MiniWin Beispiel.
Alles, was ich möchte, ist die Menubar in einer anderen Farbe als weiss.
Wenn es nicht geht, geht es nicht (kann ich mir nicht vorstellen).
Viel Möglichkeiten gibt es in SetMenuInfo ja nicht, bis auf:
mov mi.fMask,
mov mi.dwStyle,
Nochmals fröhliche Ostereier.
Ich lass Dich jetzt auch ganz bestimmt in Ruhe
Hallo Mic,
Colouring the menu bar is not foreseen in Windows afaik. I vaguely remember to have read somewhere that "menus are windows", so they might have a WndProc and a WM_ERASEBGND message, but Google is not my friend tonight :(
Good luck and Happy Easter :icon14:
Hi clamicun
I'm not sure what you want to do. I send you a demo where I used the the "Owner Draw" method to customize the menu drawing.
In this particular example, I painted the "Help" main menu item with the COLOR_GRADIENTACTIVECAPTION system color.
If this is what you want, I can provide you the source to adapt it to your project :P
Regards, Biterider
Quote from: jj2007 on April 22, 2019, 07:09:33 AM
I vaguely remember to have read somewhere that "menus are windows", so they might have a WndProc and a WM_ERASEBGND message
What you might have read was "Menu of windows" not "Menu are windows". A little word that changes the whole case.
This does not mean it can't be painted. All you need is a brush. :t
Quote from: Biterider on April 22, 2019, 03:50:41 PMI send you a demo where I used the the "Owner Draw" method to customize the menu drawing.
Impressive :t
jj,
thanks a lot.
Finally a satisfactory answer. This explains the many unsuccessful attempts in several programming languages.
Have a good one
Mic
mov mi.fMask,MIM_BACKGROUND or MIM_APPLYTOSUBMENUS
and the result was yellow.
But you wanted something else ?
TimoVJL,
that is exactly what I want. Not necessarily the dropdownmenu (MIM_APPLYTOSUBMENUS)
but the menubar.
How did you do that ?
Whatever I do, only the dropdownmenu gets the color of the brush
I was using a Windows Classic theme, so it's a theme problem with menu.
EDIT: SetWindowTheme(hWnd, L"", L"");
EDIT: sUXT db "UxTheme.dll",0
sFunc db "SetWindowTheme",0
swNull dw 0
Wnd dd ?
.code
start:
INVOKE LoadLibraryA, ADDR sUXT
.if eax
INVOKE GetProcAddress, eax, ADDR sFunc
.if eax
push OFFSET swNull
push OFFSET swNull
push [Wnd]
call eax
.endif
.endif
Quote from: TimoVJL on April 22, 2019, 09:56:47 PM
I was using a Windows Classic theme
I "discover" yesterday that Menu SystemColors don't work with Aero theme I have :biggrin:
Hi
Passing a brush to the SetMenuInfo API, it is perfectly possible to draw on the complete MenuBar and there is no need to change the windows theme settings.
Tested on Win 10 & Win7.
Regards, Biterider
Just random luck: the menubar have colors if you disable visual themes in binary compatibility properties :t
Hi Biterider,
??? 7-Zip
OwnerDraw.zip
Die Datei kann nicht geöffnet werden
Can't open file
Ist kein Archiv
It isn't an arquive
Hi Clamicun
OwnerDraw.zip is a jpg file renamed to .zip, so that the forum SW can display it.
Regards, Biterider
Hi
I'm playing with this implementation to let the MenuBar flash asynchroniously to get the users attention.
I modified the code to trigger the flashing when a new MDI client window is created or the help or about dialog are shown. 8)
Regards, Biterider
jj,
what is this ?
http://vbnet.mvps.org/index.html?code/menu/menucolour.htm
Biterider,
ok.
Pity, I hoped it would be source
Quote from: clamicun on April 23, 2019, 07:05:59 PM
what is this ?
Probably what you were looking for :biggrin:
Attention, it might not work with Aero themes on.
sUXT db "C:\windows\system32\UxTheme.dll",0
sFunc db "SetWindowTheme",0
swNull dw 0
.code
start:
INVOKE LoadLibrary, ADDR sUXT
.if eax
INVOKE GetProcAddress, eax, ADDR sFunc
.if eax
push OFFSET swNull
push OFFSET swNull
call eax
.endif
.endif
TimoVJL,
Unfortunately not.
The dropdownmenu is colored, but not the menubar
Quote from: jj2007 on April 23, 2019, 08:49:28 PM
Attention, it might not work with Aero themes on.
Disabling "visual themes" in properties of .exe file you obtain a classic window with Aero theme around!
@Clamicum:
This is exactly your second .exe file:
Hi clamicun
I send you the most important files with which you can look into the MenuBar functionality.
XMenu is the most important file. In particular, look into FlashMenuBar method.
Regards, Biterider
PS: the source code is 32/64 bit!
This is a colored menubar with a hatched background. No need for themes.
It is easy to do, so I believe you are talking about something different.
(https://www.dropbox.com/s/ptn3yunwpxm1khy/ownerdrawn.jpg?dl=1)
AW,
thats exactly what I am talking about but on my 2 computers (win7 and win 10) it doesn't work with SetMenuInfo. (MIM_BACKGROUND + MIM_APPLYTOSUBMENUS).
Only the dropdownmenu (in your picture "Exit" gets colored
No themes means: it works in Windows 2000 as well.
(https://www.dropbox.com/s/paiirtemcnm4tzq/ownerdrawn2.jpg?dl=1)
In summary:
1) In WM_CREATE you make the background with SetMenuInfo and mask MIM_BACKGROUND (no MIM_APPLYTOSUBMENUS)
2) In WM_MEASUREITEM you define the itemWidth and itemHeight in the MEASUREITEMSTRUCT passed in the LPARAM
3) In WM_DRAWITEM you have the DRAWITEMSTRUCT passed in the LPARAM. From it you know what is the rectangle to paint.
Work in progress ;-)
SetToolbarColour RgbCol(200, 255, 200)
AW,
In summary:
1) In WM_CREATE you make the background with SetMenuInfo and mask MIM_BACKGROUND (no MIM_APPLYTOSUBMENUS)
2) In WM_MEASUREITEM you define the itemWidth and itemHeight in the MEASUREITEMSTRUCT passed in the LPARAM
3) In WM_DRAWITEM you have the DRAWITEMSTRUCT passed in the LPARAM. From it you know what is the rectangle to paint.
This refers to userdrawn menus. Works with others too? My example is not userdrawn
You might want to use that techique for menu with bitmaps ;)
A C example using that.
With Menubar OwnerDrawn is the way to go.
But best is Toolbar with or without dockbar.
(https://www.dropbox.com/s/dy01kz3axgtlnot/ownerdrawn3.gif?dl=1)
that's nice :icon14: