Windows 11 style mismatch CreatePopupImageMenu
Posted: Tue Feb 18, 2025 7:49 am


(Context) menu's without icons automatically get the newer Windows 11 design, but icon menu's keep the old look. Any workaround?
http://www.purebasic.com
https://www.purebasic.fr/english/



Code: Select all
UsePNGImageDecoder()
; Load icons
If CreateImage(0, 16, 16, 32)
StartDrawing(ImageOutput(0))
Box(0, 0, 15, 15, RGB(255, 255, 128)) ; Yellow box
DrawRotatedText(-5, 3, "+", 45, RGB(255, 0, 128)) ; Rotated text
StopDrawing()
EndIf
If LoadImage(1, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png") ; Load an icon
; Create a popup menu using Win32 API
hMenu = CreatePopupMenu_()
If hMenu
; Add menu items with icons
AppendMenu_(hMenu, #MF_STRING, 1, "Open")
SetMenuItemBitmaps_(hMenu, 1, #MF_BYCOMMAND, ImageID(1), 0) ; Set icon for "Open"
AppendMenu_(hMenu, #MF_STRING, 2, "Save")
AppendMenu_(hMenu, #MF_STRING, 3, "Save as")
AppendMenu_(hMenu, #MF_STRING, 4, "Quit")
SetMenuItemBitmaps_(hMenu, 4, #MF_BYCOMMAND, ImageID(0), 0) ; Set icon for "Quit"
; Add a separator
AppendMenu_(hMenu, #MF_SEPARATOR, 0, "")
; Add a submenu
hSubMenu = CreatePopupMenu_()
If hSubMenu
AppendMenu_(hSubMenu, #MF_STRING, 5, "PureBasic.exe")
AppendMenu_(hSubMenu, #MF_STRING, 6, "Test.txt")
AppendMenu_(hMenu, #MF_POPUP, hSubMenu, "Recent files")
EndIf
EndIf
EndIf
; Open a window
OpenWindow(0, 200, 200, 200, 120, "Win32 Popup-Menu Example")
Repeat
Event = WaitWindowEvent() ; Check for window events
Select Event
Case #PB_Event_RightClick ; Right mouse button clicked
; Display the popup menu at the cursor position
GetCursorPos_(@pt.POINT)
TrackPopupMenu_(hMenu, 0, pt\x, pt\y, 0, WindowID(0), #Null)
Case #PB_Event_Menu ; A menu item was clicked
Select EventMenu() ; Get the clicked menu item
Case 1 : Debug "Menu: Open"
Case 2 : Debug "Menu: Save"
Case 3 : Debug "Menu: Save as"
Case 4 : End
Case 5 : Debug "Menu: PureBasic.exe"
Case 6 : Debug "Menu: Test.txt"
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
; Clean up
If hMenu
DestroyMenu_(hMenu)
EndIf
If hSubMenu
DestroyMenu_(hSubMenu)
EndIf
Code: Select all
UsePNGImageDecoder()
If CreateImage(0,16,16,32)
StartDrawing(ImageOutput(0))
Box(0,0,15,15,RGB(255,255,128))
DrawRotatedText(-5,3, "+", 45, RGB(255,0,128))
StopDrawing()
EndIf
OpenWindow(0, 200, 200, 200, 120, "Image Popup-Menu Example")
If LoadImage(1,#PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png") ; load an icon
If CreatePopupImageMenu(0) ; creation of the pop-up menu begins...
MenuItem(1, "Open", ImageID(1)) ; Display the icon
MenuItem(2, "Save") ; just like in a normal menu...
MenuItem(3, "Save as")
MenuItem(4, "Quit", ImageID(0)) ; Display our own icon
MenuBar()
OpenSubMenu("Recent files")
MenuItem(5, "PureBasic.exe")
MenuItem(6, "Test.txt")
CloseSubMenu()
EndIf
Repeat
Event = WaitWindowEvent() ; check for window events
Select Event
Case #PB_Event_RightClick ; right mouse button was clicked =>
DisplayPopupMenu(0, WindowID(0)) ; now display the popup-menu
Case #PB_Event_Menu ; an item of the popup-menu was clicked
Select EventMenu() ; get the clicked menu item...
Case 1 : Debug "Menu: Open"
Case 2 : Debug "Menu: Save"
Case 3 : Debug "Menu: Save as"
Case 4 : End
Case 5 : Debug "Menu: PureBasic.exe"
Case 6 : Debug "Menu: Text.txt"
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf