API to find out the currently used display percentage

I am looking for a method where I can find the display percentage used in Windows 7, 8 and 10. I'm fairly sure this is NOT the same as the magnification level. It is making all forms size in a weird way in my projects but I'm finding more and more people are using this feature (especially with Tablets) and so more and more of my forms look strange.

I'm using VB6 and VBA still so I could do with examples formatted for this language.

Below, I have put an image of where you change the setting and you'll see it is not the same as Magnification - a subject for which there seem to be a lot of pages on the web discussing. I think I am unsure of the correct terminology and therefore not finding the pages/solutions I need.

Thank you in advance.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karrtik IyerSoftware ArchitectCommented:
I think it is called DPI settings in windows, and we have a windows C/C++ API to get the current settings, I think that function is called GetDeviceCaps.
I shall try to give you a VBA code for the same.
Karrtik IyerSoftware ArchitectCommented:
It would be something like below. I have written below for a 64 bit system so PtrSafe prefix before function declaration.
Using the code below.
For 100% it would return 96 as DPI
For 125% it would return 120 as DPI
For 150% it would return 144 as DPI
Option Explicit
Private Const LOGPIXELSX As Long = 88

Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" ( _
ByVal hdc As Long, _
ByVal nIndex As Long) As Long

Private Declare PtrSafe Function GetDC Lib "user32.dll" ( _
ByVal hwnd As Long) As Long

Declare PtrSafe Function ReleaseDC Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal hdc As Long) As Long

Public Function GetDpi() As Long

Dim hdcScreen As Long
Dim iDPI As Long

iDPI = -1
hdcScreen = GetDC(0)
If (hdcScreen) Then
iDPI = GetDeviceCaps(hdcScreen, LOGPIXELSX)
ReleaseDC 0, hdcScreen
End If

GetDpi = iDPI

End Function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JedNebulaAuthor Commented:
Perfect - thank you very much.

I was able to ensure that I did a few simple calculations so as more DPIs are added (as Windows 10 already has 175%) I can deal with it...

GetDPIAsDecimal = ((GetDpi * 100) / 96) / 100
GetDPIAsPercent = (GetDpi * 100) / 96
Karrtik IyerSoftware ArchitectCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.