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.
Label/Title inside Popup Menu
Label/Title inside Popup Menu
Windows 10 Pro x64
PureBasic 6.20 x64
PureBasic 6.20 x64
Re: Label/Title inside Popup Menu
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
Hi tatanas,
one way to go is using the #MFS_DEFAULT style on the menuitem.
Or you can do it with one of RASHADs codes like this.
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.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Label/Title inside Popup Menu
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.
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.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Label/Title inside Popup Menu
Is there a way to have an Item (Title), in Bold, Disabled as well with CreatePopupImageMenu ?Axolotl wrote: Thu Feb 01, 2024 4:43 pm one way to go is using the #MFS_DEFAULT style on the menuitem.
Re: Label/Title inside Popup Menu
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.
I was going to ask the same question as ChrisR.
I guess if it's not possible, ownerdraw will be the way.
Windows 10 Pro x64
PureBasic 6.20 x64
PureBasic 6.20 x64
Re: Label/Title inside Popup Menu
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:
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()
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Label/Title inside Popup Menu
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
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
Your workaround is pretty nice.
It could be a nice project for Thorsten1867 and his "Ex" modules
It could be a nice project for Thorsten1867 and his "Ex" modules

Windows 10 Pro x64
PureBasic 6.20 x64
PureBasic 6.20 x64