Ignoring the DPI font settings on Windows
- marcoagpinto
- Addict
- Posts: 1045
- Joined: Sun Mar 10, 2013 3:01 pm
- Location: Portugal
- Contact:
Ignoring the DPI font settings on Windows
Hello!
I tried my PhD project on mum's computer last week and she has the font DPI above the normal (her computer has a higher resolution).
So, my text appeared too big when I ran the project.
Is there a way of overriding the settings?
Thanks!
Kind regards,
>Marco A.G.Pinto
---------------
I tried my PhD project on mum's computer last week and she has the font DPI above the normal (her computer has a higher resolution).
So, my text appeared too big when I ran the project.
Is there a way of overriding the settings?
Thanks!
Kind regards,
>Marco A.G.Pinto
---------------
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Ignoring the DPI font settings on Windows
If only Windows, you can use the API to get the actual DPI and then factor the font size:
Code: Select all
Global igDpi.i = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX)
Global iFS09.i = ((09 * 100) / igDpi)
Global iFS10.i = ((10 * 100) / igDpi)
Global iFS12.i = ((12 * 100) / igDpi)
Global igFontGui09.i = LoadFont(1, "Microsoft Sans Serif", iFS09, #PB_Font_HighQuality + 2)
Global igFontGui10.i = LoadFont(2, "Microsoft Sans Serif", iFS10, #PB_Font_Bold | #PB_Font_HighQuality + 2)
Global igFontGui12.i = LoadFont(3, "Microsoft Sans Serif", iFS12, #PB_Font_Bold | #PB_Font_HighQuality + 2)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Ignoring the DPI font settings on Windows
The question should be: "Is there a way to layout the gadgets properly to fulfill the needs of the user?"marcoagpinto wrote:Is there a way of overriding the settings?


PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
- marcoagpinto
- Addict
- Posts: 1045
- Joined: Sun Mar 10, 2013 3:01 pm
- Location: Portugal
- Contact:
Re: Ignoring the DPI font settings on Windows
Hello!
I have the code:
How can I override the DPIs on mum's laptop with the code above?
Thanks!
Kind regards,
>Marco A.G.Pinto
---------------
How does it work?IdeasVacuum wrote:If only Windows, you can use the API to get the actual DPI and then factor the font size:Code: Select all
Global igDpi.i = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX) Global iFS09.i = ((09 * 100) / igDpi) Global iFS10.i = ((10 * 100) / igDpi) Global iFS12.i = ((12 * 100) / igDpi) Global igFontGui09.i = LoadFont(1, "Microsoft Sans Serif", iFS09, #PB_Font_HighQuality + 2) Global igFontGui10.i = LoadFont(2, "Microsoft Sans Serif", iFS10, #PB_Font_Bold | #PB_Font_HighQuality + 2) Global igFontGui12.i = LoadFont(3, "Microsoft Sans Serif", iFS12, #PB_Font_Bold | #PB_Font_HighQuality + 2)
I have the code:
Code: Select all
; Load the font
t=LoadFont(1, "Arial", 10) ;Load Arial Font, Size 10 - 28/NOV/2013
SetGadgetFont(#PB_Default, FontID(1))
If t=0 : MessageRequester("Error", "Can't load Arial font.") : EndIf
Thanks!
Kind regards,
>Marco A.G.Pinto
---------------
- marcoagpinto
- Addict
- Posts: 1045
- Joined: Sun Mar 10, 2013 3:01 pm
- Location: Portugal
- Contact:
Re: Ignoring the DPI font settings on Windows
The status bar of my tool almost doesn't fit in my 1366x768 laptop resolution.uwekel wrote:The question should be: "Is there a way to layout the gadgets properly to fulfill the needs of the user?"marcoagpinto wrote:Is there a way of overriding the settings?There must be a reason why a user sets a larger dpi value! In my case, i also use 125% on Windows at my office, because otherwise the very small letters are very difficult to read. Unfortunately, on Windows, the a lot of programs do not layout properly or just overwrite the customized settings. Poor
Mum has a higher resolution but her DPI settings affect the size and it doesn't fit there either.
Thanks!
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Ignoring the DPI font settings on Windows
Well, is your Mum not happy with the DPI on her PC? If not, you can change it for her via Windows:
Right-mouse Desktop, Display Properties, Settings, Advanced, DPI Setting. Most commonplace is 96 DPI.
Your mum's monitor is not 4K, right? Even Windows 8.1 desktop is not actually ready for 4K yet, so none of the typical desktop apps like Office work very well. 4K is apparently fine via the Modern interface.
The code I posted showed that you can scale the font according to the dpi, and thus your intended text size in relation to your app's window will be respected. The whole app could look too small if the dpi is very high though, so you might instead want to re-size your window and the gadgets.
Right-mouse Desktop, Display Properties, Settings, Advanced, DPI Setting. Most commonplace is 96 DPI.
Your mum's monitor is not 4K, right? Even Windows 8.1 desktop is not actually ready for 4K yet, so none of the typical desktop apps like Office work very well. 4K is apparently fine via the Modern interface.
The code I posted showed that you can scale the font according to the dpi, and thus your intended text size in relation to your app's window will be respected. The whole app could look too small if the dpi is very high though, so you might instead want to re-size your window and the gadgets.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- marcoagpinto
- Addict
- Posts: 1045
- Joined: Sun Mar 10, 2013 3:01 pm
- Location: Portugal
- Contact:
Re: Ignoring the DPI font settings on Windows
Hello!IdeasVacuum wrote:Well, is your Mum not happy with the DPI on her PC? If not, you can change it for her via Windows:
Right-mouse Desktop, Display Properties, Settings, Advanced, DPI Setting. Most commonplace is 96 DPI.
Your mum's monitor is not 4K, right? Even Windows 8.1 desktop is not actually ready for 4K yet, so none of the typical desktop apps like Office work very well. 4K is apparently fine via the Modern interface.
The code I posted showed that you can scale the font according to the dpi, and thus your intended text size in relation to your app's window will be respected. The whole app could look too small if the dpi is very high though, so you might instead want to re-size your window and the gadgets.
Her laptop is FULL-HD but I reduced the resolution in it slightly when she bought it.
I thank you for your kind help, but I don't understand your API code.
It uses 3 fonts size? And in two of them it has a BOLD option?
And, why the +2 in the High Quality?
I know mum is happy with her DPI, but I am thinking about my PhD tool which must work the same way in all COMPUTERS (edited).
If after it is ready, and I need to defend it and if the university computer to be used has a huge DPI, the entire layout will be a mess and I will fail to defend it.

I hope you now understand why I am so annoying...

The tool must work 100% equal in all computers, no matter their specifications.
Re: Ignoring the DPI font settings on Windows
Try this, mister PhD:
Fonts are automatically scaled.
Gadgets size and position must be adjusted/scaled, according to DPI settings.
Same for images, but if you use images in your application, it would be even
better if you include highDPI versions and load that images.
Hope your University has Windows Vista/7/8/8.1/+. XP isn't supported anymore anyway...
A possible future PhD should have the knowledge and brain to do something like this himself, in my opinion.
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(285), "DPIaware", #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)
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
Gadgets size and position must be adjusted/scaled, according to DPI settings.
Same for images, but if you use images in your application, it would be even
better if you include highDPI versions and load that images.
Hope your University has Windows Vista/7/8/8.1/+. XP isn't supported anymore anyway...
A possible future PhD should have the knowledge and brain to do something like this himself, in my opinion.
- marcoagpinto
- Addict
- Posts: 1045
- Joined: Sun Mar 10, 2013 3:01 pm
- Location: Portugal
- Contact:
Re: Ignoring the DPI font settings on Windows
I am little and scaredDanilo wrote: A possible future PhD should have the knowledge and brain to do something like this himself, in my opinion.

Re: Ignoring the DPI font settings on Windows
Danilo, I wasn't aware of the vertical scale factor and will have to investigate it further. Thanks for the code.
OT
marcoagpinto, according to the great Professor Jim McCanney... PhD stands for Piled Higher & Deeper.
With over 200 college credit hours, while not even close to the good professor, I still consider myself to be an A.D. (above doctor), and don't need or desire any validation from those in "academics".
From my life experiences, something being doctored is not a good thing.
For the past generation or so, there has been a vetting process to make sure that only those demonstrating fealty to the ruling kabbal will be granted the PhD title.
Listen to any of these lectures and perhaps you'll also begin to realize that simple truth.
OT
marcoagpinto, according to the great Professor Jim McCanney... PhD stands for Piled Higher & Deeper.
With over 200 college credit hours, while not even close to the good professor, I still consider myself to be an A.D. (above doctor), and don't need or desire any validation from those in "academics".
From my life experiences, something being doctored is not a good thing.
For the past generation or so, there has been a vetting process to make sure that only those demonstrating fealty to the ruling kabbal will be granted the PhD title.
Listen to any of these lectures and perhaps you'll also begin to realize that simple truth.
Keep it BASIC.
Re: Ignoring the DPI font settings on Windows
Hi marcoagpinto,
Keep asking questions, and looking for answers.
Don't feel bad or embarrassed by your question, those feeling should be reserved for people who forget that character is measured by how we treat each other, not by our knowledge of PureBasic.
Keep asking questions, and looking for answers.
Don't feel bad or embarrassed by your question, those feeling should be reserved for people who forget that character is measured by how we treat each other, not by our knowledge of PureBasic.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: Ignoring the DPI font settings on Windows
Of course, keep asking questions, and looking for answers.
Last edited by Danilo on Sun Feb 08, 2015 8:23 pm, edited 1 time in total.
Re: Ignoring the DPI font settings on Windows
@Danilo
I'm sorry to find you very offensive with your self blinding over-the-top-arrogance and pretensions.
Such a standpoint is surely the way to decline human achievements.
Are you a car mechanic?
So much for a top down friendly PureBasic forum
"Even a stopped clock gives the right time twice a day"
I'm sorry to find you very offensive with your self blinding over-the-top-arrogance and pretensions.
Such a standpoint is surely the way to decline human achievements.
Are you a car mechanic?
So much for a top down friendly PureBasic forum

"Even a stopped clock gives the right time twice a day"
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi
Missing a download-file on the forums? ~ check out this backup page.
Missing a download-file on the forums? ~ check out this backup page.
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Ignoring the DPI font settings on Windows
Vera wrote:Such a standpoint is surely the way to decline human achievements.

Re: Ignoring the DPI font settings on Windows
Pursuing a PhD is a worthy goal and in no way demands the student be a programming expert. We must recognize for many, future programming will not require such mundane skills as memorizing syntax or arranging bits and bytes.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum