Font sizes are scaled automatically, also in Menu and StatusBar.
Please see the following code, I just added Menu and StatusBar. Please note that I do
change the font size, it is always 10 - the scaling is done automatically by Windows!
Code: Select all
Prototype proto_SetProcessDPIAware()
If OpenLibrary(0,"user32.dll")
SetProcessDPIAware.proto_SetProcessDPIAware = GetFunction(0,"SetProcessDPIAware")
If SetProcessDPIAware
;Debug "calling SetProcessDPIAware()"
SetProcessDPIAware() ; Windows Vista+ / Windows Server 2008+
EndIf
EndIf
Global _dpiScaleFactorX.d = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX) / 96
Global _dpiScaleFactorY.d = GetDeviceCaps_(GetDC_(0),#LOGPIXELSY) / 96
Macro dpiX(_num_) : (_num_ * _dpiScaleFactorX) : EndMacro
Macro dpiY(_num_) : (_num_ * _dpiScaleFactorY) : EndMacro
; Load the font
t=LoadFont(1, "Arial", 10, #PB_Font_HighQuality) ;Load Arial Font, Size 10 - 28/NOV/2013
SetGadgetFont(#PB_Default, FontID(1))
If t=0 : MessageRequester("Error", "Can't load Arial font.") : EndIf
If OpenWindow(0, dpiX(0), dpiY(0), dpiX(640), dpiY(325), "DPIaware - " + Str(_dpiScaleFactorX*100) +"%", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, dpiX(10),dpiY( 10),dpiX(200),dpiY(25), "Standard Button")
ButtonGadget(1, dpiX(10),dpiY( 40),dpiX(200),dpiY(25), "Left Button", #PB_Button_Left)
ButtonGadget(2, dpiX(10),dpiY( 70),dpiX(200),dpiY(25), "Right Button", #PB_Button_Right)
ButtonGadget(3, dpiX(10),dpiY(100),dpiX(200),dpiY(60), "Multiline Button (longer text gets automatically wrapped)", #PB_Button_MultiLine)
ButtonGadget(4, dpiX(10),dpiY(170),dpiX(200),dpiY(25), "Toggle Button", #PB_Button_Toggle)
If CreateMenu(0,WindowID(0))
MenuTitle("Project")
MenuItem(1, "Open" +Chr(9)+"Ctrl+O")
MenuItem(2, "Save" +Chr(9)+"Ctrl+S")
MenuItem(3, "Save as"+Chr(9)+"Ctrl+A")
MenuItem(4, "Close" +Chr(9)+"Ctrl+C")
EndIf
CreateStatusBar(0,WindowID(0))
AddStatusBarField(dpiX(320))
AddStatusBarField(dpiX(320))
StatusBarText(0, 0, "Field 1")
StatusBarText(0, 1, "Field 2")
ListViewGadget(5, dpiX(430),dpiY(10),dpiX(200),dpiy(185))
For i = 0 To 100 : AddGadgetItem(5,-1,"Item "+i) : Next
CanvasGadget(6, dpiX(220),dpiY(10),dpiX(200),dpiy(185))
If StartDrawing( CanvasOutput(6) )
Box(0,0,OutputWidth(),OutputHeight(),RGB($40,$40,$40))
Line(dpiX( 0) ,dpiY(0), dpiX(200),dpiy(185),RGB($FF,$FF,$00))
Line(dpiX(200),dpiY(0),-dpiX(200),dpiy(185),RGB($FF,$FF,$00))
StopDrawing()
EndIf
If LoadImage(0,#PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.bmp")
ResizeImage(0,dpiX(ImageWidth(0)),dpiY(ImageHeight(0)))
ImageGadget(7,dpiX(10),dpiY(205),dpiX(381),dpiY(68),ImageID(0))
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf