热情软件屋

 

如何判断显示模式是大字体还是小字体


编号:QA003028
建立日期: 2000年6月7日 最后修改日期:2002年1月10日
所属类别:

wqshui:
    怎样通过VB5.0判断是大字体还是小字体,能不能重新启动计算机就更改?

回答:

    一个近似的方法是使用GetDeviceCaps()获得LOGPIXELSY和LOGPIXELSX的设置,一般的每英寸96个点为小字体,而120个点为大字体。不过修改字体设置必须要重新启动计算机。
    微软推荐的检测大/小字体的方法(Windows 95, Windows 98, Windows Me, or Windows NT 3.51)是调用API函数GetTextMetrics()。Windows显示驱动在小字体模式下使用VGASYS.FON,而在大字体模式下使用8514SYS.FON 。下面是一个例子:
     '** API要用到的类型 **
     Type TEXTMETRIC
     tmHeight As Integer
     tmAscent As Integer
     tmDescent As Integer
     tmInternalLeading As Integer
     tmExternalLeading As Integer
     tmAveCharWidth As Integer
     tmMaxCharWidth As Integer
     tmWeight As Integer
     tmItalic As String * 1
     tmUnderlined As String * 1
     tmStruckOut As String * 1
     tmFirstChar As String * 1
     tmLastChar As String * 1
     tmDefaultChar As String * 1
     tmBreakChar As String * 1
     tmPitchAndFamily As String * 1
     tmCharSet As String * 1
     tmOverhang As Integer
     tmDigitizedAspectX As Integer
     tmDigitizedAspectY As Integer
     End Type
    
     '** Win32 API 定义 **
     Declare Function GetTextMetrics Lib "gdi32" Alias "GetTextMetricsA" _
     (ByVal hdc As Long, lpMetrics As TEXTMETRIC) As Long
     Declare Function GetDesktopWindow Lib "user32" () As Long
     Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
     Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc _
     As Long) As Long
     Declare Function SetMapMode Lib "gdi32" (ByVal hdc As Long, ByVal _
     nMapMode As Long) As Long
    
     '** 常数 **
     Global Const MM_TEXT = 1
    
     '** 函数 **
     Public Function gbl_GetFontRes() As String
     Dim hdc, hwnd, PrevMapMode As Long
     Dim tm As TEXTMETRIC
    
     ' 默认返回小字体
     gbl_GetFontRes = "VGA"
    
     ' 获得桌面窗口的句柄
     hwnd = GetDesktopWindow()
    
     ' 获得桌面的上下文句柄
     hdc = GetWindowDC(hwnd)
     If hdc Then
     ' 设置映射方式为点阵
     PrevMapMode = SetMapMode(hdc, MM_TEXT)
    
     ' 获得系统字体的大小
     GetTextMetrics hdc, tm
    
     ' 设置映射方式回原来的值
     PrevMapMode = SetMapMode(hdc, PrevMapMode)
    
     ' 释放设备上下文句柄
     ReleaseDC hwnd, hdc
    
     ' 如果系统字体大于16个像素,则使用大字体
     If tm.tmHeight > 16 Then gbl_GetFontRes = "8514"
     End If
    
     End Function

此问题由李海回答。

 
把这个问题推荐给朋友
   
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio