Je dois avouer ce code est un peu fouilli, mais bon si ça peut aider

#TitleBarMenu_RESTORE = 61728
#TitleBarMenu_MOVE = 61456
#TitleBarMenu_SIZE = 61440
#TitleBarMenu_MINIMIZE = 61472
#TitleBarMenu_MAXIMIZE = 61488
#TitleBarMenu_EXIT = 61536
#PB_Event_TitleBarMenu = 274
Global MenuTitle
ProcedureDLL TitleBarMenuID(Window)
If IsWindow (Window)
ProcedureReturn GetSystemMenu_ ( WindowID (window), #False )
EndIf
EndProcedure
ProcedureDLL CountTitleBarMenuItem(Window, HMenu = #PB_Ignore )
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
ProcedureReturn GetMenuItemCount_ (HMenu)
EndProcedure
ProcedureDLL AddTitleBarMenuItem(Window, MenuItem , Text.s, Flags = 0, HMenu = #PB_Ignore ) ; Spécifier HMenu s'il s'agit d'un sous menu
If IsWindow (Window)
If MenuTitle = 0 : MenuTitle = 1 : EndIf
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
ProcedureReturn AppendMenu_ (HMenu, #MF_STRING | Flags, MenuItem , Text)
EndIf
EndProcedure
ProcedureDLL AddTitleBarMenuItemIcon(Window, MenuItem , Texte.s, ImageUnchecked, ImageChecked = #PB_Ignore , Flags = 0, HMenu = #PB_Ignore )
If IsWindow (Window)
If MenuTitle = 0 : MenuTitle = 1 : EndIf
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
If ImageChecked = #PB_Ignore : ImageChecked = ImageUnchecked : EndIf
ProcedureReturn AppendMenu_ (HMenu, #MF_STRING | Flags, MenuItem , Texte) And SetMenuItemBitmaps_ (HMenu, MenuItem , #MF_BYCOMMAND , ImageID (ImageUnchecked), ImageID (ImageChecked))
EndIf
EndProcedure
ProcedureDLL AddTitleBarSeparator(Window, MenuItem , HMenu = #PB_Ignore )
If IsWindow (Window)
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
ProcedureReturn AppendMenu_ (HMenu, #MF_SEPARATOR , MenuItem , 0)
EndIf
EndProcedure
ProcedureDLL SetTitleBarMenuItemIcon(Window, MenuItem , ImageUnchecked, ImageChecked = #PB_Ignore , HMenu = #PB_Ignore )
If IsWindow (Window)
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
If ImageChecked = #PB_Ignore : ImageChecked = ImageUnchecked : EndIf
If MenuTitle
If CountTitleBarMenuItem(Window) > 0
For a = 0 To CountTitleBarMenuItem(Window)-1
If MenuItem = GetMenuItemID_ (HMenu, a)
ProcedureReturn SetMenuItemBitmaps_ (HMenu, MenuItem , #MF_BYCOMMAND , ImageID (ImageUnchecked), ImageID (ImageChecked))
EndIf
Next
EndIf
EndIf
EndIf
EndProcedure
ProcedureDLL InsertTitleBarMenuItem(Window, Position, MenuItem , text.s, Flags = 0, HMenu = #PB_Ignore )
If IsWindow (Window)
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
ProcedureReturn InsertMenu_ (HMenu, Position, #MF_BYCOMMAND | Flags, MenuItem , Text.s)
EndIf
EndProcedure
ProcedureDLL DeleteTitleBarMenuItem(Window, MenuItem , HMenu = #PB_Ignore )
If IsWindow (Window)
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
ProcedureReturn RemoveMenu_ (HMenu, MenuItem , #MF_BYCOMMAND )
EndIf
EndProcedure
ProcedureDLL DisableTitleBarMenuItem(Window, MenuItem , State, HMenu = #PB_Ignore )
If IsWindow (Window)
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
If state = 1
ProcedureReturn EnableMenuItem_ (HMenu, MenuItem , #MF_DISABLED | #MF_GRAYED )
Else
ProcedureReturn EnableMenuItem_ (HMenu, MenuItem , #MF_ENABLED )
EndIf
EndIf
EndProcedure
ProcedureDLL EventTitleBarMenu()
ProcedureReturn EventwParam ()
EndProcedure
ProcedureDLL CreateTitleBarSubMenu(Window, Title.s, Flags = 0, HMenu = #PB_Ignore ) ; Retourne le HMenu
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
hSubMenu = CreateMenu_ ()
AppendMenu_ (HMenu, #MF_POPUP | Flags, hSubMenu,Title)
ProcedureReturn hSubMenu
EndProcedure
ProcedureDLL SetTitleBarMenuItemState(Window, MenuItem , State, HMenu = #PB_Ignore )
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
If State = 1 : State = #MF_CHECKED : Else : State = #MF_UNCHECKED : EndIf
ProcedureReturn CheckMenuItem_ (HMenu, MenuItem , State)
EndProcedure
ProcedureDLL GetTitleBarMenuItemState(Window, MenuItem , HMenu = #PB_Ignore )
If HMenu = #PB_Ignore : HMenu = TitleBarMenuID(Window) : EndIf
ProcedureReturn GetMenuState_ (HMenu, MenuItem , #MF_BYCOMMAND )
EndProcedure
CreateImage (0, 16, 16)
StartDrawing ( ImageOutput (0))
Box (0, 0, 16, 16, $0000FF)
Box (3, 3, 8, 8, $FF0000)
StopDrawing ()
CreateImage (1, 16, 16)
StartDrawing ( ImageOutput (1))
Box (0, 0, 16, 16, $FF0000)
Box (3, 3, 8, 8, $0000FF)
StopDrawing ()
CreateImage (2, 16, 16)
StartDrawing ( ImageOutput (2))
Box (0, 0, 16, 16, $00FF00)
Box (3, 3, 8, 8, $00FFFF)
StopDrawing ()
win = OpenWindow ( #PB_Any , 0, 0, 200, 200, "test" , #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget )
If win And CreateGadgetList ( WindowID (win))
AddTitleBarMenuItem(win, 2, "TEST" )
HMenu = CreateTitleBarSubMenu(win, "Menu" )
AddTitleBarSeparator(win, 8 )
AddTitleBarMenuItem(win, 1, "Menu" , #MF_CHECKED )
AddTitleBarMenuItem(win, 3, "Sous menu" , 0, HMenu)
AddTitleBarMenuItemIcon(win, 4, "SousMenu Icone" , 0, 2, 0, HMenu)
AddTitleBarMenuItem(win, 5, "Item" , #MF_MENUBARBREAK , HMenu)
HMenu2 = CreateTitleBarSubMenu(win, "SousMenu2" , 0, HMenu)
AddTitleBarMenuItem(win, 9, "TEST" , 0, HMenu2)
AddTitleBarMenuItem(win, 6, "Item" , #MF_MENUBARBREAK )
AddTitleBarMenuItem(win, 7, "Supprimer le menu" )
AddTitleBarMenuItem(win, #TitleBarMenu_EXIT , "Quitter" + Chr (9)+ "ALT+F4" , #MF_MENUBREAK )
SetTitleBarMenuItemIcon(win, #TitleBarMenu_EXIT , 1)
CreateMenu (0, WindowID (win))
MenuTitle ( "Fichier" )
MenuItem (1, "test" )
Repeat
Select WaitWindowEvent ()
Case #PB_Event_Gadget
Select EventGadget ()
;Case
EndSelect
Case #PB_Event_Menu
Select EventMenu ()
Case 1
Debug "MENU : TEST"
EndSelect
Case #PB_Event_TitleBarMenu
Select EventTitleBarMenu()
Case 1
If GetTitleBarMenuItemState(Win, 1) & #MF_CHECKED : s = 0 : Else : s = 1 : EndIf
SetTitleBarMenuItemState(Win, 1, s)
Case 4
If GetTitleBarMenuItemState(Win, 4) & #MF_CHECKED : s = 0 : Else : s = 1 : EndIf
SetTitleBarMenuItemState(Win, 4, s)
Case 2
Debug "TEST"
If GetTitleBarMenuItemState(Win, 1) & #MF_HILITE : s = #MF_UNHILITE : Else : s = #MF_HILITE : EndIf
HiliteMenuItem_ ( WindowID (Win), TitleBarMenuID(Win), 2, s)
Case 3
Debug "SOUS MENU"
Case #TitleBarMenu_EXIT
Debug "EXIT"
Case 6
DisableTitleBarMenuItem(win, 6, 1)
Default
Debug "MENU " + Str (EventTitleBarMenu())
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf