| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 533 人关注过本帖
标题:VFP如何调用ChooseFont(Windows API标准字体选择对话框)?
只看楼主 加入收藏
seasoners
Rank: 2
等 级:论坛游民
帖 子:59
专家分:19
注 册:2013-12-15
收藏
得分:0 
赞,非常感谢分享
5 天前 15:15
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:930
专家分:1470
注 册:2021-10-13
收藏
得分:0 
电脑里保存了一个老外写的如何调用api函数的大全apiviewer,里面详细列举了各种api函数的说明,介绍,用法,变量,结构等,以及vfp范例,找到与createfont相关的范例,分享给大家,仅做参考!

createfont相关api运用例子:
程序代码:
DO decl 

#DEFINE GMEM_FIXED                 0
#DEFINE LF_FACESIZE               32
#DEFINE FW_NORMAL                400
#DEFINE DEFAULT_CHARSET            1
#DEFINE OUT_DEFAULT_PRECIS         0
#DEFINE CLIP_DEFAULT_PRECIS        0
#DEFINE DEFAULT_QUALITY            0
#DEFINE DEFAULT_PITCH              0
#DEFINE CF_SCREENFONTS             1
#DEFINE CF_INITTOLOGFONTSTRUCT    64
#DEFINE CF_EFFECTS               256
#DEFINE CF_FORCEFONTEXIST      65536

*| typedef struct { 
*|   DWORD        lStructSize;     4
*|   HWND         hwndOwner;       4
*|   HDC          hDC;             4
*|   LPLOGFONT    lpLogFont;       4
*|   INT          iPointSize;      4
*|   DWORD        Flags;           4
*|   COLORREF     rgbColors;       4
*|   LPARAM       lCustData;       4
*|   LPCFHOOKPROC lpfnHook;        4
*|   LPCTSTR      lpTemplateName;  4
*|   HINSTANCE    hInstance;       4
*|   LPTSTR       lpszStyle;       4
*|   WORD         nFontType;       2
*|   WORD         ___MISSING_ALIGNMENT__; 2
*|   INT          nSizeMin;        4
*|   INT          nSizeMax;        4
*| } CHOOSEFONT, *LPCHOOSEFONT; total: 60 bytes

*| typedef struct tagLOGFONT { 
*|   LONG lfHeight;                   4
*|   LONG lfWidth;                    4
*|   LONG lfEscapement;               4
*|   LONG lfOrientation;              4
*|   LONG lfWeight;                   4
*|   BYTE lfItalic;                   1
*|   BYTE lfUnderline;                1
*|   BYTE lfStrikeOut;                1
*|   BYTE lfCharSet;                  1
*|   BYTE lfOutPrecision;             1
*|   BYTE lfClipPrecision;            1
*|   BYTE lfQuality;                  1
*|   BYTE lfPitchAndFamily;           1 
*|   TCHAR lfFaceName[LF_FACESIZE];  32
*| } LOGFONT, *PLOGFONT; total: 60 bytes

    LOCAL lcChooseFont, lcLogFont, hLogFont, lcFontFace

    * initializing LOGFONT structure:
    * Times New Roman, Italic
    lcLogFont = num2dword(16) +;
        num2dword(0)  +;
        num2dword(0)  +;
        num2dword(0)  +;
        num2dword(FW_NORMAL) +;
        Chr(1) +;
        Chr(0) +;
        Chr(0) +;
        Chr(DEFAULT_CHARSET)     +;
        Chr(OUT_DEFAULT_PRECIS)  +;
        Chr(CLIP_DEFAULT_PRECIS) +;
        Chr(DEFAULT_QUALITY)     +;
        Chr(DEFAULT_PITCH)       +;
        PADR("Times New Roman"+Chr(0),32)

    * copying the LOGFONT data into the global memory object
    * because CHOOSEFONT structure uses the pointer
    lnLogFontSize = 60
    hLogFont = GlobalAlloc(GMEM_FIXED, lnLogFontSize)

    * this function is re-declared below
    * with different parameter types
    DECLARE RtlMoveMemory IN kernel32 As String2Heap;
        INTEGER Destination, STRING @ Source,;
        INTEGER nLength
    = String2Heap (hLogFont, @lcLogFont, lnLogFontSize)

    * initializing CHOOSEFONT structure
    lcChooseFont = num2dword(60) +;
        num2dword(0) +;
        num2dword(0) +;
        num2dword(hLogFont) +;
        num2dword(0) +;
        num2dword(CF_SCREENFONTS + CF_EFFECTS +;
            CF_INITTOLOGFONTSTRUCT + CF_FORCEFONTEXIST) +;
        num2dword(0) +;
        num2dword(0) +;
        num2dword(0) +;
        num2dword(0) +;
        num2dword(0) +;
        num2dword(0) +;
        num2dword(0) +;
        num2dword(0) +;
        num2dword(0)

    IF ChooseFont (@lcChooseFont) <> 0
    * displaying selection
        * re-declaring API function with different parameters
        DECLARE RtlMoveMemory IN kernel32 As Heap2String;
            STRING @Dest, INTEGER Source, INTEGER nLength

        * copying data from the global memory object to VFP string
        = Heap2String (@lcLogFont, hLogFont, lnLogFontSize)

        ? "*** CHOOSEFONT Structure:"
        ? "Point size:", buf2dword(SUBSTR(lcChooseFont, 17,4))
        ? "RGB color: ", buf2dword(SUBSTR(lcChooseFont, 25,4))
        
        ?
        ? "*** LOGFONT Structure:"
        ? "Font Weight:", buf2dword(SUBSTR(lcLogFont, 17,4))
        ? "Italic:     ", Iif(Asc(SUBSTR(lcLogFont, 21,1))=0, "No","Yes")
        ? "Underline:  ", Iif(Asc(SUBSTR(lcLogFont, 22,1))=0, "No","Yes")
        ? "Strikeout:  ", Iif(Asc(SUBSTR(lcLogFont, 23,1))=0, "No","Yes")
        
        lcFontFace = SUBSTR(lcLogFont, 29)
        lcFontFace = SUBSTR(lcFontFace, 1, AT(Chr(0),lcFontFace)-1)
        ? "Font Face:  ", lcFontFace
    ENDIF

    * releasing system resources
    = GlobalFree (hLogFont)
RETURN

PROCEDURE  decl
    DECLARE INTEGER ChooseFont IN comdlg32 STRING @lpcf
    DECLARE INTEGER GlobalFree IN kernel32 INTEGER hMem
    DECLARE INTEGER GlobalAlloc IN kernel32;
        INTEGER wFlags,;
        INTEGER dwBytes

FUNCTION  num2dword (lnValue)
#DEFINE m0       256
#DEFINE m1     65536
#DEFINE m2  16777216
    LOCAL b0, b1, b2, b3
    b3 = Int(lnValue/m2)
    b2 = Int((lnValue - b3*m2)/m1)
    b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
    b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)

FUNCTION  buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    Asc(SUBSTR(lcBuffer, 2,1)) * 256 +;
    Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +;
    Asc(SUBSTR(lcBuffer, 4,1)) * 16777216


运行效果如下:
图片附件: 游客没有浏览图片的权限,请 登录注册
3 天前 13:18
cssnet
Rank: 5Rank: 5
等 级:职业侠客
威 望:5
帖 子:398
专家分:360
注 册:2013-10-4
收藏
得分:0 
以下是引用sam_jiang在2025-6-14 13:18:14的发言:

电脑里保存了一个老外写的如何调用api函数的大全apiviewer,里面详细列举了各种api函数的说明,介绍,用法,变量,结构等,以及vfp范例,找到与createfont相关的范例,分享给大家,仅做参考!


哈,你这么一说,想起来啦!apiviewer_VFP早在VFP7年代就曾下载过,只是一直都没空(准确地说,是没耐心)仔细看看……我去翻翻旧光盘。

“DO decl”这种句式,以前在红雨的API例子中常见,还挺有印象的。原以为那是他原创,敢情,源头在老外那边啊。

3 天前 14:10
cssnet
Rank: 5Rank: 5
等 级:职业侠客
威 望:5
帖 子:398
专家分:360
注 册:2013-10-4
收藏
得分:0 
刚搜了一下旧光盘,2006年,好古老,那时候MYF1都还在呢!
可,news2news早都不存在了!
再搜一下原作者Anatoliy Mogylevets……切,敢情早就捐给VFPX了,改名了,难怪一时想不起:
https://
也只有我们这种老家伙,才会对VFP如数家珍,念念不忘。
3 天前 14:49
快速回复:VFP如何调用ChooseFont(Windows API标准字体选择对话框)?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017655 second(s), 9 queries.
Copyright©2004-2025, BC-CN.NET, All Rights Reserved