我手头上有一个程序,作用是实现输出点阵字库图片。没有可视化界面,直接在屏幕上的一个边角产生200x200的黑色区域,显示汉字,然后输出图片 。原先的程序输出的字体是固定的,也就是在LOGFONT lf = { };中直接定义了字体。
现在我想用 字体选择段话框 来订制LOGFONT lf,以便实现不同字体的输出。查了一下,应该是要用到CFontDialog,不过我没有c++ MFC的基础,只会ANSI C. =.=源代码中,WndProc函数里有lf的声明,我希望能用CFontDialog来改变lf的设置。在这个声明附近应该添加什么代码?
源代码本身没有错误,我只是想增加功能:)
LOGFONT lf = {
-FONT_SIZE, // font size
0, // unused
0, // no angle
0, // no Orientation
400, // bold
FALSE, // no italic
FALSE, // no underline
FALSE, // no strick (middle-line)
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH,
"宋体"};

解决方案 »

  1.   

    http://topic.csdn.net/t/20041212/21/3638564.html
      

  2.   


    LOGFONT lf;
    CFontDialog dlg;
    if (dlg.DoModal() == IDOK)
    {
          dlg.GetCurrentFont(&lf);
       TRACE(_T("Face name of the selected font = %s\n"), lf.lfFaceName);
    }
      

  3.   


    你好,按照你那样修改后,程序出错了提示
    error C2065: 'CFontDialog' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'dlg'
    error C2065: 'dlg' : undeclared identifier
    error C2224: left of '.DoModal' must have struct/union type
    error C2224: left of '.GetCurrentFont' must have struct/union type
      

  4.   


    加上了这个又提示错误
    fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>
    。。原先库文件已经有
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
      

  5.   

    头文件去掉 #include <windows.h>加上#include <afx.h>
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #include <afxcmn.h>                     // MFC support for Windows Common Controls然后在工程设置里面
    设置 动态链接到 MFC dll
      

  6.   


    按照你这么设置后,原先的提示是没有了,不过又有一条错误=.-
    SetTimer (hwnd, ID_TIMER, 1, TimerProc);
    error C2664: 'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned long,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsign...
    使用的是VC6.0
      

  7.   

     是不是SetTimer与MFC有冲突?
      

  8.   

    找到 timerProc 的定义,加 CALLBACK 声明就像下面这样
    VOID CALLBACK TimerProc( HWND hwnd,
        UINT uMsg,
        UINT_PTR idEvent,
        DWORD dwTime
    )
    {
    ......
    }
      

  9.   


    代码里原先就已经加VOID CALLBACK了有的帖子说在MFC程序中SetTimer被封装在CWnd类中,调用就不用指定窗口句柄了于是SetTimer函数的原型变为:
    UINT SetTimer(UINT nIDEvent,UINT nElapse,void(CALLBACK EXPORT *lpfnTimer)(HWND,UINT ,YINT ,DWORD)) ,用法如:SetTimer(1,1000,NULL);
    奇怪啊,麻烦各位了=.=
      

  10.   

    SetTimer的问题解决了 SetTimer (hwnd, ID_TIMER, 1, TimerProc);
    改为
    SetTimer (hwnd, ID_TIMER, 1, (TIMERPROC)TimerProc);
    不过不知道为什么=.=