Merci pour les liens que je connaissais déjà et que j'avais testé.
Ça ne correspond pas exactement a ce que je recherche mais je garde quand même pour étudier de plus près.
Après plusieurs essais, j'en conclus que certaines astuces fonctionnent si on utilise CreateMenu() pour les menus.
Si on utilise CreateImageMenu(), ça ne fonctionne plus.
Il semble qu'il ne soit pas possible de mettre un item de menu en gras avec CreateImageMenu()
a) désactiver un titre de menu.
b) mettre en gras le titre d'un menu.
c) mettre en gras un item de menu ou plusieurs. (Uniquement avec CreateMenu())
Code : Tout sélectionner
;;; Sources Microsoft
;;; -----------------
;;; https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-modifymenua
;;; https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setmenuiteminfoa
;;; https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-menuiteminfoa
;;;
;;; Sources Purebasic
;;; -----------------
;;; Change "System Menu Item" to Bold Style + Change S
;;; https://www.purebasic.fr/english/viewtopic.php?p=257170
;;;
;;; Disabled item in combobox???
;;; https://www.purebasic.fr/english/viewtopic.php?p=299156
;;;
;;; PopupMenu and bold items
;;; https://www.purebasic.fr/english/viewtopic.php?t=12589
;;;
EnableExplicit
Enumeration Window
#WinApp
EndEnumeration
Enumeration Menus
#MenuApp
#MenuPop
#MenuTray
EndEnumeration
Enumeration MenusID
#MenuApp00
#MenuApp01
#MenuApp02
#MenuApp03
EndEnumeration
Enumeration MenusPop
#MenuPop0
#MenuPop1
#MenuPop2
#MenuPop3
EndEnumeration
Enumeration FormMenu
#Item00=0
#Item01
#Item02
#Item03
#Item04
;
#Item10=10
#Item11
#Item12
#Item13
;
#Item20=20
#Item21
#Item22
#Item23
EndEnumeration
Enumeration Gadgets
#GadgetCanvas
#GadgetCombo
#GadgetButton
#GadgetBtnQuit
#GadgetBtnSys
EndEnumeration
#bgcolor = 14474460 ; bgcolor = RGB(220,220,220)
#fgcolor = 0 ; fcolor = RGB(0,0,0)
Define X, Y, W, H, Event, index, indexMenu, indexGadget, indexGadgetType, foo$
Define SystemMenu
Global bold.MENUITEMINFO
bold\cbSize=SizeOf(bold)
; Members to retrieve or set.
bold\fMask =#MIIM_STATE ; Retrieves or sets the fState member.
bold\fState=#MFS_DEFAULT ; Menu item state. This member can be one or more of these values:
; #MFS_CHECKED Checks the menu item.
; #MFS_UNCHECKED Unchecks the menu item.
; #MFS_DEFAULT Specifies that the menu item is the default.
; #MFS_DEFAULT A menu can contain only one Default menu item, which is displayed in bold.
; #MFS_ENABLED Enables the menu item so that it can be selected. This is the default state.
; #MFS_DISABLED Disables the menu item and grays it so that it cannot be selected.
; #MFS_DISABLED This is equivalent To MFS_GRAYED.
; #MFS_GRAYED Disables the menu item and grays it so that it cannot be selected.
; #MFS_GRAYED This is equivalent To MFS_DISABLED.
; #MFS_HILITE Highlights the menu item.
; #MFS_UNHILITE Removes the highlight from the menu item. This is the default state.
Global disabled.MENUITEMINFO
disabled\cbSize=SizeOf(disabled)
disabled\fMask=#MIIM_STATE
disabled\fState=#MFS_DISABLED
Global enabled.MENUITEMINFO
enabled\cbSize=SizeOf(enabled)
enabled\fMask=#MIIM_STATE
enabled\fState=#MFS_ENABLED
#WinAppWidth =600
#WinAppHeight=300
#buttonOk$="Tester avec CreateMenu() && CreatePopupMenu()"
#buttonKo$="Tester avec CreateImageMenu() && CreatePopupImageMenu()"
#buttonSysOn$ = "Désactiver Alt+F4"
#buttonSysOff$ = "Activer Alt+F4"
;#CBS_UPPERCASE = $2000
Procedure afficher_menu()
If IsMenu(#MenuApp)
FreeMenu(#MenuApp)
EndIf
If IsMenu(#MenuPop)
FreeMenu(#MenuPop)
EndIf
If CreateMenu(#MenuApp,WindowID(#WinApp))
MenuTitle("Menu00") ; <-- #MenuApp00
MenuItem(#Item00,"Titre Menu00 en Gras")
MenuBar()
MenuItem(#Item01,"Item01")
MenuItem(#Item02,"Item02")
MenuItem(#Item03,"Item03")
MenuBar()
MenuItem(#Item04,"Fermer")
MenuTitle("Menu01") ; <-- #MenuApp01
MenuItem(#Item10,"Titre Menu10 en Gras")
MenuBar()
MenuItem(#Item11,"Item11")
MenuItem(#Item12,"Item12")
MenuItem(#Item13,"Item13")
MenuTitle("Menu02") ; <-- #MenuApp02
MenuItem(#Item20,"Titre Menu20 en Gras")
MenuBar()
MenuItem(#Item21,"Item21")
MenuItem(#Item22,"Item22")
MenuItem(#Item23,"Item23")
MenuTitle("Menu03") ; <-- #MenuApp03
SetMenuDefaultItem_(MenuID(#MenuApp),#MenuApp03,#True)
ModifyMenu_(MenuID(#MenuApp),#MenuApp03,#MF_BYPOSITION,#MenuApp03,"Menu03")
DrawMenuBar_(WindowID(#WinApp))
EnableMenuItem_(GetMenu_(WindowID(#WinApp)),#MenuApp03,#MF_BYPOSITION|#MF_GRAYED)
SetMenuItemInfo_(MenuID(#MenuApp),#Item00,#False,bold)
SetMenuItemInfo_(MenuID(#MenuApp),#Item10,#False,bold)
SetMenuItemInfo_(MenuID(#MenuApp),#Item20,#False,bold)
DisableMenuItem(#MenuApp, #Item00, #True)
DisableMenuItem(#MenuApp, #Item10, #True)
DisableMenuItem(#MenuApp, #Item20, #True)
If CreatePopupMenu(#MenuPop);, #PB_Menu_ModernLook)
MenuItem(#MenuPop0 , "Menu Popup en Gras")
MenuBar()
MenuItem(#MenuPop1 , "Popup1")
MenuItem(#MenuPop2 , "Popup2")
MenuItem(#MenuPop3 , "Popup3")
EndIf
SetMenuItemInfo_(MenuID(#MenuPop),#MenuPop0,#True,bold)
DisableMenuItem(#MenuPop, #MenuPop0, #True)
EndIf
EndProcedure
Procedure afficher_menu_image()
If IsMenu(#MenuApp)
FreeMenu(#MenuApp)
EndIf
If IsMenu(#MenuPop)
FreeMenu(#MenuPop)
EndIf
If CreateImageMenu(#MenuApp,WindowID(#WinApp))
MenuTitle("Menu00") ; <-- #MenuApp00
MenuItem(#Item00,"Titre Menu00")
MenuBar()
MenuItem(#Item01,"Item01")
MenuItem(#Item02,"Item02")
MenuItem(#Item03,"Item03")
MenuBar()
MenuItem(#Item04,"Fermer")
MenuTitle("Menu01") ; <-- #MenuApp01
MenuItem(#Item10,"Titre Menu10")
MenuBar()
MenuItem(#Item11,"Item11")
MenuItem(#Item12,"Item12")
MenuItem(#Item13,"Item13")
MenuTitle("Menu02") ; <-- #MenuApp02
MenuItem(#Item20,"Titre Menu20")
MenuBar()
MenuItem(#Item21,"Item21")
MenuItem(#Item22,"Item22")
MenuItem(#Item23,"Item23")
MenuTitle("Menu03") ; <-- #MenuApp03
SetMenuDefaultItem_(MenuID(#MenuApp),#MenuApp03,#True)
ModifyMenu_(MenuID(#MenuApp),#MenuApp03,#MF_BYPOSITION,#MenuApp03,"Menu03")
DrawMenuBar_(WindowID(#WinApp))
EnableMenuItem_(GetMenu_(WindowID(#WinApp)),#MenuApp03,#MF_BYPOSITION|#MF_GRAYED)
SetMenuItemInfo_(MenuID(#MenuApp),#Item00,#False,bold)
SetMenuItemInfo_(MenuID(#MenuApp),#Item10,#False,bold)
SetMenuItemInfo_(MenuID(#MenuApp),#Item20,#False,bold)
DisableMenuItem(#MenuApp, #Item00, #True)
DisableMenuItem(#MenuApp, #Item10, #True)
DisableMenuItem(#MenuApp, #Item20, #True)
If CreatePopupImageMenu(#MenuPop, #PB_Menu_ModernLook)
MenuItem(#MenuPop0 , "Menu Popup")
MenuBar()
MenuItem(#MenuPop1 , "Popup1")
MenuItem(#MenuPop2 , "Popup2")
MenuItem(#MenuPop3 , "Popup3")
EndIf
SetMenuItemInfo_(MenuID(#MenuPop),#MenuPop0,#True,bold)
DisableMenuItem(#MenuPop, #MenuPop0, #True)
EndIf
EndProcedure
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
Protected *lpdis.DRAWITEMSTRUCT
Protected *Text=AllocateMemory(128)
Protected wc.WNDCLASSEX\cbSize = SizeOf(WNDCLASSEX)
GetClassInfoEx_(GetModuleHandle_(0), @"ComboBox", @wc)
Protected CBCB = wc\lpfnWndProc
Select uMsg
Case #WM_DRAWITEM
*lpdis.DRAWITEMSTRUCT = lParam : SetBkMode_(*lpdis\hDC, #TRANSPARENT)
If *lpdis\CtlType = #ODT_COMBOBOX
If *lpdis\itemState & #ODS_SELECTED
If CallWindowProc_(CBCB, *lpdis\hwndItem, #CB_GETITEMDATA, *lpdis\itemID, 0);SendMessage_()
*lpdis\CtlType = GetSysColorBrush_(#COLOR_BTNFACE)
Else
*lpdis\CtlType = GetSysColorBrush_(#COLOR_HIGHLIGHT)
EndIf
Else
*lpdis\CtlType = GetSysColorBrush_(#COLOR_WINDOW)
EndIf
FillRect_(*lpdis\hDC, *lpdis\rcItem, *lpdis\CtlType) : *lpdis\rcItem\left+4
CallWindowProc_(CBCB, *lpdis\hwndItem, #CB_GETLBTEXT, *lpdis\itemID, *Text);SendMessage_()
If CallWindowProc_(CBCB, *lpdis\hwndItem, #CB_GETITEMDATA, *lpdis\itemID, 0);SendMessage_()
SetTextColor_(*lpdis\hDC, #Gray);GetSysColor_(#COLOR_GRAYTEXT)
EndIf
DrawText_(*lpdis\hDC, *Text, -1, *lpdis\rcItem, #DT_NOCLIP|#DT_VCENTER|#DT_SINGLELINE)
SetTextColor_(*lpdis\hDC, GetSysColor_(#COLOR_WINDOWTEXT))
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(#WinApp,0,0,#WinAppWidth,#WinAppHeight,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowColor(#WinApp, #bgcolor)
;; Désactiver le menu système Fermer Alt+F4
SystemMenu = GetSystemMenu_(WindowID(#WinApp), #False)
SetMenuItemInfo_(SystemMenu,6,#True,disabled)
afficher_menu()
SetMenuTitleText(#MenuApp, #MenuApp03, Space(20)+ReplaceString(#buttonOk$,"Tester","Menu",#PB_String_NoCase))
X=0:Y=0:W=#WinAppWidth:H=#WinAppHeight-MenuHeight()
;; le canvas permet de gérer les évements sur tout l'écran
;; utilisé pour permettre le menu Popup avec le clic droit de la souris
CanvasGadget(#GadgetCanvas, X, Y, W, H, #PB_Canvas_Container)
StartDrawing(CanvasOutput(#GadgetCanvas))
;; on rempli le fond du canvas avec la couleur #bgcolor
FillArea(0, 0, -1,#bgcolor)
StopDrawing()
X=10:Y=10:W=#WinAppWidth-(X*2):H=22
;; Ajouter les flags #CBS_OWNERDRAWFIXED|#CBS_HASSTRINGS aux flags du ComboBox
If ComboBoxGadget(#GadgetCombo, X, Y, W, H,#CBS_OWNERDRAWFIXED|#CBS_HASSTRINGS)
SetGadgetColor(#GadgetCombo, #PB_Gadget_BackColor , #bgcolor)
SetGadgetColor(#GadgetCombo, #PB_Gadget_FrontColor, #fgcolor)
AddGadgetItem(#GadgetCombo, -1,"> Sélectionnez une commande")
AddGadgetItem(#GadgetCombo, -1,"ipconfig")
AddGadgetItem(#GadgetCombo, -1,"ipconfig /all")
AddGadgetItem(#GadgetCombo, -1,"ipconfig /displaydns")
AddGadgetItem(#GadgetCombo, -1,"ipconfig /flushdns")
AddGadgetItem(#GadgetCombo, -1,"ipconfig /registerdns *")
AddGadgetItem(#GadgetCombo, -1,"ipconfig /release")
AddGadgetItem(#GadgetCombo, -1,"ipconfig /renew")
SetGadgetState(#GadgetCombo, 0)
EndIf
;; Désactiver le premier item de la ComboBox
SendMessage_(GadgetID(#GadgetCombo), #CB_SETITEMDATA, 0, #True);DISABLE ITEM
;; Gestion des évenements du ComboBox
SetWindowCallback(@WinCallback(), 0)
W=400:H=24
X=(#WinAppWidth-(W))/2
Y=((#WinAppHeight-MenuHeight())-(H/2))/2
ButtonGadget(#GadgetButton, X, Y, W, H, #buttonKo$)
W=100:H=24
X=(#WinAppWidth-(W))/2
Y=Y+H+20
ButtonGadget(#GadgetBtnQuit, X, Y, W, H, "Fermer")
W=150:H=24
X=(#WinAppWidth-(W))/2
Y=Y+H+20
ButtonGadget(#GadgetBtnSys, X, Y, W, H, #buttonSysOff$)
CloseGadgetList()
Repeat
Event = WaitWindowEvent(20)
If Event = #PB_Event_CloseWindow : Break : EndIf
Select Event
Case #PB_Event_Menu
indexMenu = EventMenu()
Select indexMenu
Case #Item04
Break
Case #Item00 To #Item23
Debug "Item = "+indexMenu
EndSelect
Case #PB_Event_Gadget
indexGadget = EventGadget()
indexGadgetType = EventType()
Select indexGadget
Case #GadgetCombo
If indexGadgetType = #PB_EventType_Change
index = GetGadgetState(#GadgetCombo)
If index = 0 ; On ne tiens pas compte du premier item
Continue
EndIf
foo$ = GetGadgetItemText(#GadgetCombo, index)
Debug Str(index)+" : "+foo$
EndIf
Case #GadgetButton
If GetGadgetText(#GadgetButton)=#buttonKo$
SetGadgetText(#GadgetButton,#buttonOk$)
afficher_menu_image()
SetMenuTitleText(#MenuApp, #MenuApp03, Space(20)+ReplaceString(#buttonKo$,"Tester","Menu",#PB_String_NoCase))
Else
SetGadgetText(#GadgetButton,#buttonKo$)
afficher_menu()
SetMenuTitleText(#MenuApp, #MenuApp03, Space(20)+ReplaceString(#buttonOk$,"Tester","Menu",#PB_String_NoCase))
EndIf
Case #GadgetBtnSys
SystemMenu = GetSystemMenu_(WindowID(#WinApp), #False)
If GetGadgetText(#GadgetBtnSys)=#buttonSysOff$
SetGadgetText(#GadgetBtnSys,#buttonSysOn$)
SetMenuItemInfo_(SystemMenu,6,#True,enabled)
;Debug "If"
Else
SetGadgetText(#GadgetBtnSys,#buttonSysOff$)
SetMenuItemInfo_(SystemMenu,6,#True,disabled)
;Debug "Else"
EndIf
Case #GadgetBtnQuit
Break
EndSelect
Select indexGadgetType
Case #PB_EventType_RightClick
DisplayPopupMenu(#MenuPop, WindowID(#WinApp))
EndSelect
EndSelect
ForEver
EndIf
Je continue a chercher et je modifierais le code en fonction de mes avancées.