, but here is a code doing what you asked.
Change line 64 to change the color of the menu bar background.
Code: Select all
Structure myMenuItem
hFont.i
text$
EndStructure
Structure MENUBARINFO Align #PB_Structure_AlignC
cbSize.l
rcBar.RECT
hMenu.i
hwndMenu.i
fBarFocused.b
fFocused.b
fUnused.b
Padding_1.b
EndStructure
Structure MENUINFO Align #PB_Structure_AlignC
cbSize.l ; Size of the structure (in bytes).
fMask.l ; Mask specifying which members are being set or retrieved.
dwStyle.l ; Style of the menu.
cyMax.l ; Maximum height of the menu, in pixels.
hbrBack.i ; Handle to the brush used to paint the menu background.
dwContextHelpID.l ; Context help ID for the menu.
dwMenuData.i ; Custom data associated with the menu.
EndStructure
;...Array of Menu item info
Global Dim menuItems.myMenuItem(2, 3)
Procedure myWindowCallback(hwnd, msg, wParam, lParam)
Protected x, y, w, h
Protected sz.SIZE
Shared menuParent$
result = #PB_ProcessPureBasicEvents
If GetProp_(hWnd, "ISWndInitialized") = 0 And IsWindow(EventWindow()) And WindowID(EventWindow()) = hWnd
;
; While the command 'WindowEvent()' or 'WaitWindowEvent()' have not been
; executed, the value of 'EventWindow()' is not valid.
; Therefore, by testing 'IsWindow(EventWindow())', we have the opportunity to know
; the precise moment when the main loop of the program begins. This moment is
; the good one to make some check or to initialize something.
;
If GetMenu_(hWnd)
; For the main menu of the window, PureBasic send the #WM_INITMENU message when
; the menu is created by CreateMenu(). At this moment, our callback procedure is
; generally not installed, so, it never receive the #WM_INITMENU for this menu.
; The following will resend this message at the moment the program enters into
; the main loop and begin to call 'WindowEvent()'.
;
SetProp_(hWnd, "ISWndInitialized", 1)
SendMessage_(hWnd, #WM_INITMENU, GetMenu_(hWnd), 0)
EndIf
EndIf
Select msg
Case #WM_INITMENU
hMenu = wParam
#MIM_BACKGROUND = $2
Protected menuInfo.MENUINFO
hBrush = CreateSolidBrush_($FF0000)
menuInfo\cbSize = SizeOf(MENUINFO)
menuInfo\hbrBack = hBrush
menuInfo\fMask = #MIM_BACKGROUND
SetMenuInfo_(hMenu, @menuInfo)
DrawMenuBar_(hWnd)
Case #WM_DRAWITEM
;...Draw our menu items here
If wParam = 0
*dis.DRAWITEMSTRUCT = lParam
If *dis\CtlType = #ODT_MENU
*pMenuItem.myMenuItem = *dis\itemData
hOldFont = SelectObject_(*dis\hdc, *pMenuItem\hFont)
; SetBkColor_(*dis\hdc, #Black)
; SetTextColor_(*dis\hdc,#White)
; DrawTextEx_(*dis\hdc, *pMenuItem\text$, Len(*pMenuItem\text$), *dis\rcItem, #DT_LEFT | #DT_NOCLIP, 0)
; SelectObject_(*dis\hdc, hOldFont)
If *dis\itemID = 0 ; 1er élément du menu
Brush = CreateSolidBrush_(#Red)
Else
; second
Brush = CreateSolidBrush_($E0A030)
EndIf
; Brush = CreateSolidBrush_(#Red)
SetTextColor_(*dis\hDC, #White)
FillRect_(*dis\hDC, *dis\rcItem, Brush)
SetBkMode_(*dis\hDC, #TRANSPARENT)
*dis\rcItem\Left + 2
DrawTextEx_(*dis\hDC, *pMenuItem\text$, -1, *dis\rcItem, #DT_EXPANDTABS | #DT_SINGLELINE | #DT_CENTER | #DT_VCENTER | #DT_NOCLIP, 0)
DeleteObject_(Brush)
EndIf
EndIf
ProcedureReturn #True
;- . ---> #WM_MEASUREITEM
Case #WM_MEASUREITEM
*mi.MEASUREITEMSTRUCT = lParam
If *mi\CtlType = #ODT_MENU
If *mi\itemdata
hDC = GetDC_(hWnd)
If hDC
SavedDC = SaveDC_(hDC)
EndIf
;*mi\itemID is the position of the menu item, 0 and 1 due to the use of
; ModifyMenu_ and #MF_BYPOSITION
; using the font to calculate the item size
SelectObject_(hDC, menuItems(*mi\itemID, 0)\hFont)
Protected Count = CountString(menuItems(*mi\itemID, 0)\text$, "&")
If Count = 0
menuItems(*mi\itemID, 0)\text$ + "&"
EndIf
; get text size according hfont
GetTextExtentPoint32_(hDC, menuItems(*mi\itemID, 0)\text$, Len(menuItems(*mi\itemID, 0)\text$), @sz)
*mi\itemWidth = sz\cx ; largeur de l'élément
*mi\itemHeight = sz\cy ; hauteur de l'élément
If SavedDC
RestoreDC_(hDC, SavedDC)
EndIf
ReleaseDC_(hWnd, hDC)
ProcedureReturn 1
EndIf
EndIf
EndSelect
ProcedureReturn result
EndProcedure
;-
;- . ---> OpenWindow
OpenWindow(0, 10, 10, 300, 200, "OwnerDraw Menu", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
SetWindowCallback(@myWindowCallback())
hMenu = CreateMenu(0, WindowID(0))
MenuTitle("&File")
MenuItem(1, "&Open")
MenuItem(2, "&Save")
MenuItem(3, "E&xit")
MenuTitle("&Edit")
MenuItem(4, "&Cut")
MenuItem(5, "C&opy")
MenuItem(6, "&Paste")
;...Here we set ownerdraw for Menu Titles "File" and "Edit"
For i = 0 To 2
menuItems(i, 0)\text$ = GetMenuTitleText(0, i)
ModifyMenu_(hMenu, i, #MF_BYPOSITION | #MF_OWNERDRAW, i, menuItems(i ,0))
Next i
;...Show the menu changes
DrawMenuBar_(WindowID(0))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow