Please enable DPI aware check
Support Windows DPI too
Feel free to add ,remove & change
Feel the Pure Power of PB
Tested with PB 6.xx x86 - Windows 11 x64
Code: Select all
#MNS_NOCHECK = $80000000
#MIM_BACKGROUND = 2
#MIM_STYLE = $00000010
#MIM_APPLYTOSUBMENUS = $80000000
Structure MENUINFO Align #PB_Structure_AlignC
cbSize.l
fMask.l
dwStyle.l
cyMax.l
hbrBack.i
dwContextHelpId.l
*dwMenuData
EndStructure
Global dpix.d,dpiy.d
UsePNGImageDecoder()
ExamineDesktops()
olddesktop = DesktopWidth(0)
dpix = DesktopResolutionX()
dpiy = DesktopResolutionY()
LoadImage(10, #PB_Compiler_Home + "examples/sources/Data/ToolBar/New.png")
LoadImage(11, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png")
LoadImage(12, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Save.png")
LoadImage(13, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Save.png")
LoadImage(14, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Printpreview.png")
LoadImage(15, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Print.png")
CreateImage(0,200,400,24)
StartDrawing(ImageOutput(0))
Box(0,0,200,400,$D8FEFE)
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($FF0000)
FrontColor($00FFFF)
BoxedGradient(-5, -100, 100, 400)
Box(0,0,30,200)
DrawAlphaImage(ImageID(10),5,5,255)
DrawAlphaImage(ImageID(11),5,30,255)
DrawAlphaImage(ImageID(12),5,55,255)
StopDrawing()
If OSVersion() >= #PB_OS_Windows_11
ResizeImage(0,ImageWidth(0)*dpix,ImageHeight(0)*dpiy)
EndIf
CreateImage(1,600,400,24)
StartDrawing(ImageOutput(1))
Box(0,0,600,400,$D8FEFE)
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($FF0000)
FrontColor($00FFFF)
BoxedGradient(-5, -100, 100, 400)
Box(0,0,30,200)
DrawAlphaImage(ImageID(13),5,5,255)
DrawAlphaImage(ImageID(14),5,30,255)
DrawAlphaImage(ImageID(15),5,55,255)
StopDrawing()
If OSVersion() >= #PB_OS_Windows_11
ResizeImage(1,ImageWidth(1)*dpix,ImageHeight(1)*dpiy)
EndIf
b.LOGBRUSH
b\lbStyle = #BS_PATTERN
b\lbHatch = ImageID(0)
hBrush = CreateBrushIndirect_(b)
mi.MENUINFO
mi\cbSize = SizeOf(MENUINFO)
mi\fMask = #MIM_STYLE| #MIM_BACKGROUND |#MIM_APPLYTOSUBMENUS
mi\dwStyle = #MNS_NOCHECK
mi\hbrBack = hBrush
b2.LOGBRUSH
b2\lbStyle = #BS_PATTERN
b2\lbHatch = ImageID(1)
hBrush2 = CreateBrushIndirect_(b2)
mi2.MENUINFO
mi2\cbSize = SizeOf(MENUINFO)
mi2\fMask = #MIM_STYLE| #MIM_BACKGROUND |#MIM_APPLYTOSUBMENUS
mi2\dwStyle = #MNS_NOCHECK
mi2\hbrBack = hBrush2
If OSVersion() >= #PB_OS_Windows_11
Text$=Space(6*dpix)
Else
Text$=Space(6)
EndIf
Procedure sizeCB()
ResizeGadget(0,0,0,WindowWidth(0),25)
EndProcedure
hWnd = OpenWindow(0, 0, 0, 300, 300, "New Modern Menu", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
ContainerGadget(0,0,0,WindowWidth(0),24)
SetGadgetColor(0,#PB_Gadget_BackColor,0)
TextGadget(1,4,2,40,30,"File",#SS_NOTIFY)
SetGadgetColor(1,#PB_Gadget_BackColor,0)
SetGadgetColor(1,#PB_Gadget_FrontColor,$FFFFFF)
TextGadget(2,45,2,40,30,"Edit",#SS_NOTIFY)
SetGadgetColor(2,#PB_Gadget_BackColor,0)
SetGadgetColor(2,#PB_Gadget_FrontColor,$FFFFFF)
CloseGadgetList()
If hWnd
;hMainMenu = CreateMenu_()
CreatePopupMenu(0)
hSubMenu = MenuID(0)
;AppendMenu_(hMainMenu, #MF_POPUP, hSubMenu, "File")
AppendMenu_(hSubMenu, #MF_STRING, 0, Text$+"New")
AppendMenu_(hSubMenu, #MF_STRING, 1, Text$+"Open")
AppendMenu_(hSubMenu, #MF_STRING, 2, Text$+"Exit")
CreatePopupMenu(1)
hSubMenu2 = MenuID(1)
;AppendMenu_(hMainMenu, #MF_POPUP, hSubMenu2, "Edit")
AppendMenu_(hSubMenu2, #MF_STRING, 3, Text$+"Save")
AppendMenu_(hSubMenu2, #MF_STRING, 4, Text$+"Print Preview")
AppendMenu_(hSubMenu2, #MF_STRING, 5, Text$+"Print")
SetMenuInfo_(hSubMenu, mi)
SetMenuInfo_(hSubMenu2, mi2)
BindEvent(#PB_Event_SizeWindow,@sizeCB())
;SetMenu_(hWnd, hMainMenu)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Debug EventMenu()
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 1
DisplayPopupMenu(0,WindowID(0),GadgetX(1,#PB_Gadget_ScreenCoordinate)*dpix,GadgetY(1,#PB_Gadget_ScreenCoordinate)*dpiy+24*dpiy)
Case 2
DisplayPopupMenu(1,WindowID(0),GadgetX(2,#PB_Gadget_ScreenCoordinate)*dpix,GadgetY(2,#PB_Gadget_ScreenCoordinate)*dpiy+24*dpiy)
EndSelect
EndSelect
Until Quit = 1
EndIf









