Page 1 of 1
Label/Title inside Popup Menu
Posted: Thu Feb 01, 2024 10:15 am
by tatanas
Hi,
Do you know a way to create some Title inside a Popup Menu ?
The best would be a non selectable title that could be personnalized (font, size, color).
I would like this kind of Menu :
Cars (title)
______ (menubar)
Ferrari (menuitem)
Mercedes
Ford
______
Color (title)
______
Red (menuitem)
Blue
Grey
Thanks for your time.
Re: Label/Title inside Popup Menu
Posted: Thu Feb 01, 2024 10:39 am
by Caronte3D
I don't know, but you can make your own popup with a simple window and put whatever you want inside.
Re: Label/Title inside Popup Menu
Posted: Thu Feb 01, 2024 4:43 pm
by Axolotl
Hi tatanas,
one way to go is using the #MFS_DEFAULT style on the menuitem.
Code: Select all
EnableExplicit
#Window = 0
#Menu = 0
Procedure OpenMainWindow()
Protected menustyle.MenuItemInfo
If OpenWindow(#Window, 8, 8, 560, 240, "Test ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreatePopupMenu(#Menu)
MenuItem(1, "Cars") ; Title
MenuBar()
MenuItem(2, "Ferrari")
MenuItem(3, "Mercedes")
MenuItem(4, "Ford")
MenuBar()
MenuItem(5, "Color") ; Title
MenuBar()
MenuItem(6, "Red")
MenuItem(7, "Blue")
MenuItem(8, "Grey")
MenuBar()
MenuItem(9, "Close")
;
; Cars (title)
; ______ (menubar)
; Ferrari (menuitem)
; Mercedes
; Ford
; ______
; Color (title)
; ______
; Red (menuitem)
; Blue
; Grey
;
; set Title items Bold
menustyle\cbSize = SizeOf(menustyle)
menustyle\fMask = #MIIM_STATE ;|#MIIM_STRING
menustyle\fState = #MFS_DEFAULT
SetMenuItemInfo_(MenuID(#Menu), 1, #False, menustyle) ; make it bold
SetMenuItemInfo_(MenuID(#Menu), 5, #False, menustyle) ; make it bold
; and disable Title items
DisableMenuItem(#Menu, 1, #True) ; no events
DisableMenuItem(#Menu, 5, #True) ; no events
EndIf
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
If OpenMainWindow()
Repeat
Select WaitWindowEvent()
Case #PB_Event_LeftClick
DisplayPopupMenu(#Menu, WindowID(#Window))
Case #PB_Event_Menu
Debug " MenuItem #" + EventMenu()
If EventMenu() = 9 ; Close
PostEvent(#PB_Event_CloseWindow)
EndIf
Case #PB_Event_CloseWindow
CloseWindow(#Window)
End
EndSelect
ForEver
EndIf
Or you can do it with one of RASHADs codes like
this.
Re: Label/Title inside Popup Menu
Posted: Thu Feb 01, 2024 4:47 pm
by Axolotl
Hi, me again,
another way to do this is to ownerdraw the menu items like
here.
It needs to be adapted to your needs.
Happy coding and stay healthy.
Re: Label/Title inside Popup Menu
Posted: Thu Feb 01, 2024 6:03 pm
by ChrisR
Axolotl wrote: Thu Feb 01, 2024 4:43 pm
one way to go is using the #MFS_DEFAULT style on the menuitem.
Is there a way to have an Item (Title), in Bold, Disabled as well with CreatePopupImageMenu ?
Re: Label/Title inside Popup Menu
Posted: Fri Feb 02, 2024 8:18 am
by tatanas
Thank you Axolotl.
I was going to ask the same question as ChrisR.
I guess if it's not possible, ownerdraw will be the way.
Re: Label/Title inside Popup Menu
Posted: Fri Feb 02, 2024 1:25 pm
by Axolotl
Sorry for my delayed answer.
In addition to having a unique identifier, each menu item in a menu bar or menu has a unique position value.
try this:
Code: Select all
Procedure main()
Protected MII.MENUITEMINFO
If OpenWindow(0, 10, 10, 200, 100, "Menu Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateMenu(0, WindowID(0)) ; hier beginnt das Erstellen des MenĂ¼s...
MenuTitle("File")
MenuItem(1, "Open" +Chr(9)+"Ctrl+O")
MenuItem(2, "Save" +Chr(9)+"Ctrl+S")
MenuItem(3, "Save as"+Chr(9)+"Ctrl+A")
MenuItem(4, "Close" +Chr(9)+"Ctrl+C")
MenuTitle("Edit")
MenuItem(10, "Test 10")
MenuItem(11, "Test 11")
MenuItem(12, "Test 12")
MenuTitle("Project")
MenuItem(20, "Test 20")
MenuItem(21, "Test 21")
MenuItem(22, "Test 22")
EndIf
; set Title items Bold
MII\cbSize = SizeOf(MII)
MII\fMask = #MIIM_STATE
MII\fState = #MFS_DEFAULT
SetMenuItemInfo_(MenuID(0), 0, #True, MII) ; make Title it bold
; SetMenuItemInfo_(MenuID(0), 1, #True, MII) ; make Title it bold
SetMenuItemInfo_(MenuID(0), 2, #True, MII) ; make Title it bold
;// #True --> use position instead of ID
MII\fState = #MFS_DEFAULT | #MFS_DISABLED ;
SetMenuItemInfo_(MenuID(0), 3, #False, MII) ; make Item it bold and disabled
MII\fState = #MFS_DEFAULT
SetMenuItemInfo_(MenuID(0), 4, #False, MII) ; make Item it bold
;// #False --> use ID instead of position
DrawMenuBar_(WindowID(0)) ; we have to draw it now
; main loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Debug "Menu #" + EventMenu()
If EventMenu() = 4
PostEvent(#PB_Event_CloseWindow) ; or break will do the trick as well.....
EndIf
EndSelect
ForEver
EndIf
Debug "bye."
EndProcedure
main()
Re: Label/Title inside Popup Menu
Posted: Fri Feb 02, 2024 4:15 pm
by ChrisR
Thanks for the nice Menu example
What I needed was the same as your 1st code, Set Title items Bold, Disabled, but for CreatePopupImageMenu() rather than CreatePopupMenu()
A workaround is to use CreatePopupMenu(#Menu) rather than the CreatePopupImageMenu(), then add the image with SetMenuItemBitmaps for each menu items
Code: Select all
EnableExplicit
#Window = 0
#Menu = 0
#MenuImage = 0
#MenuImageTitle = 1
LoadImage(#MenuImageTitle, #PB_Compiler_Home + "Examples\Sources\Data\Drive.bmp")
LoadImage(#MenuImage, #PB_Compiler_Home + "Examples\Sources\Data\File.bmp")
Macro _MenuItem(MenuItemID, Text, IDImage)
MenuItem(MenuItemID, Text)
SetMenuItemBitmaps_(MenuID(#Menu), MenuItemID, #MF_BYCOMMAND, IDImage, 0)
EndMacro
Procedure OpenMainWindow()
Protected menustyle.MenuItemInfo
If OpenWindow(#Window, 8, 8, 560, 240, "Test ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; Set Title items Bold, Disabled does not work with CreatePopupImageMenu(#Menu)
; Workaround, use CreatePopupMenu(#Menu) and for each items use SetMenuItemBitmaps Api to associates an image
If CreatePopupMenu(#Menu)
_MenuItem(1, "Cars", ImageID(#MenuImageTitle))
MenuBar()
_MenuItem(2, "Ferrari", ImageID(#MenuImage))
_MenuItem(3, "Mercedes", ImageID(#MenuImage))
_MenuItem(4, "Ford", ImageID(#MenuImage))
MenuBar()
_MenuItem(5, "Color", ImageID(#MenuImageTitle))
MenuBar()
_MenuItem(6, "Red", ImageID(#MenuImage))
_MenuItem(7, "Blue", ImageID(#MenuImage))
_MenuItem(8, "Grey", ImageID(#MenuImage))
MenuBar()
_MenuItem(9, "Close", ImageID(#MenuImage))
; set Title items Bold and disable it
menustyle\cbSize = SizeOf(menustyle)
menustyle\fMask = #MIIM_STATE ;|#MIIM_STRING
menustyle\fState = #MFS_DEFAULT | #MFS_DISABLED
SetMenuItemInfo_(MenuID(#Menu), 1, #False, menustyle) ; make it bold, disable
SetMenuItemInfo_(MenuID(#Menu), 5, #False, menustyle) ; make it bold, disable
EndIf
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
If OpenMainWindow()
Repeat
Select WaitWindowEvent()
Case #PB_Event_LeftClick
DisplayPopupMenu(#Menu, WindowID(#Window))
Case #PB_Event_Menu
Debug " MenuItem #" + EventMenu()
If EventMenu() = 9 ; Close
PostEvent(#PB_Event_CloseWindow)
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
Re: Label/Title inside Popup Menu
Posted: Mon Feb 05, 2024 8:22 am
by tatanas
Your workaround is pretty nice.
It could be a nice project for Thorsten1867 and his "Ex" modules
