How to determine the DPI setting for current user

G

Guest

Does anyone know how to check to see what the DPI setting is using VBA in
Access 2003? I want to be able to determine if the font size is "small" 96
dpi or "Large" 120 dpi and issue a message to the user.

Thanks!
Jerry
 
B

Brendan Reynolds

You can do it with the following API calls. Note, though, that if you change
the DPI setting, the new value can not be detected until Windows is
re-started.

Option Compare Database
Option Explicit

Private Const LOGPIXELSX As Long = 88

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

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

Declare 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
 
G

Guest

Thanks Brendon - It works great!

Jerry

Brendan Reynolds said:
You can do it with the following API calls. Note, though, that if you change
the DPI setting, the new value can not be detected until Windows is
re-started.

Option Compare Database
Option Explicit

Private Const LOGPIXELSX As Long = 88

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

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

Declare 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
 
B

Brendan Reynolds

Great, I'm glad it works for you.

I'm not actually sure whether the call to ReleaseDC is required in VBA. I
adapted it from an example in C++, and this *might* be one of those
housekeeping tasks that you have to do in C++ but VB/VBA does automatically
for you. I left it in on the principle of 'better safe than sorry'! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top