monitor small/large font code

G

Guest

Need code to determine the monitor/screen setting 'small font' or 'large font'
I have code for screen resolution
In Control Panel, 'Display', my 'Settings' advanced tab shows 'small font 96 dpi normal'

TIA
 
V

Vasant Nanavati

Sub GetScreenFont()
MsgBox GetDeviceCaps(GetDC(0), 88), vbOKOnly _
+ vbInformation, "Screen Font Size"
End Sub

Assuming you have already declared the GetDC and GetDeviceCaps functions to
get the screen resolution.
 
B

Bob Phillips

Here's a slightly modified bit of code from Randy Birch

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2004 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
Private Declare Function GetDesktopWindow Lib "user32" _
() As Long

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

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

Private Declare Function ReleaseDC Lib "user32" _
(ByVal hwnd As Long, _
ByVal hdc As Long) As Long
Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90


Public Function ScreenFont() As String
Dim hWndDesk As Long
Dim hDCDesk As Long
Dim logPix As Long

'get the handle to the desktop window
hWndDesk = GetDesktopWindow()

'get the handle desktop display context (hDC)
hDCDesk = GetDC(hWndDesk)

'get the horizontal logical pixels
logPix = GetDeviceCaps(hDCDesk, LOGPIXELSX)

'release the hDC
Call ReleaseDC(hWndDesk, hDCDesk)

'if the return from GetDeviceCaps is 96, then
'the system is using small fonts.
If logPix = 96 Then
ScreenFont = "Small"
Else
ScreenFont = "Large"
End If

End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
V

Vasant Nanavati

88 represents a constant (named LOGPIXELX) used for convenience. It has no
inherent significance that I know of. It is one of the many parameters for
the function GetDeviceCaps which can give you all kinds of information about
an output device.
 
V

Vasant Nanavati

Hi Bob:

I didn't realize the DC needed to be released if you weren't doing anything
with it (besides getting the handle), but my API knowledge would probably
fit on the head of a pin <g>.

Regards,

Vasant.
 
B

Bob Phillips

Hi Vasant,

you probably haven't run into the problems that can arise, so it didn't
seem like an issue. Defensive programming<vbg>

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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