词条 | ChooseFont |
释义 | 基本概念函数功能:该函数创建一个使用户选择逻辑字体属性的对话框,这些属性包括字体名称、字体风格(如粗体、斜体或正常体)、字号、效果(如强调线,下划线或字体颜色)和手写体(或字符集)。 函数原型:BOOL ChooseFont(LPCHOOSEFONT Ipcf); 参数: Ipcf:指向一个含有初始化对话框信息的CHOOSEFONT结构。当返回ChooseFont函数时,此结构含有用户对字体选择的信息。 返回值:如果用户点击对话框的OK按钮,返回值为非零值,CHOOSEFONT结构中的成员表明用户的选择。如果用户取消或关闭Font对话框或出现错误信息,返回值为零。若想获得更多错误信息。请调用CommDlgExtendedError函数,其返回值如下: CDERR_FINDRESFAILURE;CDERR_NOHINSTANCE;CDERR_INITIALIZATION;CDERR_NOHOOK CDERR_LOCKRESFAILURE;CDERR_NOTEMPLATE;CDERR_LOADRESFAILURE; CDERR_STRUCTSIZE;CDERR_LOADSTRFAILURE;CDERR_MAXLESSTHANMIN CDERR_MEMALLOCFAILURE;CDERR_NOFONTS;CDERR_MEMLOCKFAILURE 备注:可以为Font对话框提供一个CFHOOKProc挂钩程序。此挂钩程序能够处理发送给对话框的信息。 通过建立CHOOSEFONT结构中Flags成员的CE ENABLEHOOK标志和指定IPfn Hook成员中挂钩程序的地址可以使挂钩程序有效。 挂钩程序可以把信息WM_CHOOSEFONT_GETLOGLONT,WM_CHOOSEFONT_SETFLAGS和 WM_CHOOSEFONT_SETLOGFONT消息发送给对话框以便得到和创建当前值和对话框的图标。 速查:Windows NT:3.1及以一上版本;Windows:95及以上版本;Windows CE:不支持;头文件:Commdlg.h;库文件:comdlg32.lib;Unicode:在Windows NT环境中实现为Unicode和ANSI两个版本。 ----------------------------------------------------------------------------------------------------------------------------------- CHOOSEFONT 结构体 可用于上面ChooseFont来弹出对话框选择字体, 你做出的选择如果点击ok会保存在在传递给ChooseFont的指针所指的结构体中, 所以在调用完这个函数后可以通过分析该结构题的成员获得用户选择的字体信息, 来进行相应的客户区刷新等... 在VB中的应用1.声明Private Const LF_FACESIZE = 32 Private Const CF_PRINTERFONTS = &H2 Private Const CF_SCREENFONTS = &H1 Private Const CF_BOTH = (CF_SCREENFONTS Or CF_PRINTERFONTS) Private Const CF_EFFECTS = &H100& Private Const CF_FORCEFONTEXIST = &H10000 Private Const CF_INITTOLOGFONTSTRUCT = &H40& Private Const CF_LIMITSIZE = &H2000& Private Const REGULAR_FONTTYPE = &H400 'charset Constants Private Const ANSI_CHARSET = 0 Private Const ARABIC_CHARSET = 178 Private Const BALTIC_CHARSET = 186 Private Const CHINESEBIG5_CHARSET = 136 Private Const DEFAULT_CHARSET = 1 Private Const EASTEUROPE_CHARSET = 238 Private Const GB2312_CHARSET = 134 Private Const GREEK_CHARSET = 161 Private Const HANGEUL_CHARSET = 129 Private Const HEBREW_CHARSET = 177 Private Const JOHAB_CHARSET = 130 Private Const MAC_CHARSET = 77 Private Const OEM_CHARSET = 255 Private Const RUSSIAN_CHARSET = 204 Private Const SHIFTJIS_CHARSET = 128 Private Const SYMBOL_CHARSET = 2 Private Const THAI_CHARSET = 222 Private Const TURKISH_CHARSET = 162 Private Type LOGFONT lfHeight As Long lfWidth As Long lfEscapement As Long lfOrientation As Long lfWeight As Long lfItalic As Byte lfUnderline As Byte lfStrikeOut As Byte lfCharSet As Byte lfOutPrecision As Byte lfClipPrecision As Byte lfQuality As Byte lfPitchAndFamily As Byte lfFaceName As String * 31 End Type Private Declare Function CHOOSEFONT Lib "comdlg32.dll" Alias "ChooseFontA" (ByRef pChoosefont As CHOOSEFONT) As Long Private Type CHOOSEFONT lStructSize As Long hwndOwner As Long ' caller's window handle hDC As Long ' printer DC/IC or NULL lpLogFont As Long ' ptr. to a LOGFONT struct iPointSize As Long ' 10 * size in points of selected font flags As Long ' enum. type flags rgbColors As Long ' returned text color lCustData As Long ' data passed to hook fn. lpfnHook As Long ' ptr. to hook function lpTemplateName As String ' custom template name hInstance As Long ' instance handle of.EXE that ' contains cust. dlg. template lpszStyle As String ' return the style field here ' must be LF_FACESIZE or bigger nFontType As Integer ' same value reported to the EnumFonts ' call back with the extra FONTTYPE_ ' bits added MISSING_ALIGNMENT As Integer nSizeMin As Long ' minimum pt size allowed & nSizeMax As Long ' max pt size allowed if ' CF_LIMITSIZE is used End Type 2.函数的调用假设需要改变字体的控件名称是Text1。 Dim cf As CHOOSEFONT, lfont As LOGFONT Dim fontname As String, ret As Long cf.flags = CF_BOTH Or CF_EFFECTS Or CF_FORCEFONTEXIST Or CF_INITTOLOGFONTSTRUCT Or CF_LIMITSIZE cf.lpLogFont = VarPtr(lfont) cf.lStructSize = LenB(cf) 'cf.lStructSize = Len(cf) ' size of structure cf.hwndOwner = Form1.hWnd ' window Form1 is opening this dialog box 'cf.hDC = Printer.hDC ' device context of default printer (using VB's mechanism) cf.rgbColors = RGB(0, 0, 0) ' black cf.nFontType = REGULAR_FONTTYPE ' regular font type i.e. not bold or anything cf.nSizeMin = 10 ' minimum point size cf.nSizeMax = 72 ' maximum point size ret = CHOOSEFONT(cf) 'brings up the font dialog If ret <> 0 Then ' success fontname = StrConv(lfont.lfFaceName, vbUnicode, &H804) 'Retrieve chinese font name in english version os fontname = Left$(fontname, InStr(1, fontname, vbNullChar) - 1) 'Assign the font properties to text1 With Text1.Font .Charset = lfont.lfCharSet 'assign charset to font .Name = fontname .Size = cf.iPointSize / 10 'assign point size Text1.Text = .Name & ":" & .Charset & ":" & .Size 'display data in chosen Font End With End If |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。