WM_SETFONT
An application sends a WM_SETFONT message to specify the font that a control is to use when drawing text. WM_SETFONT 
wParam = (WPARAM) hfont;            // handle of font 
lParam = MAKELPARAM(fRedraw, 0);    // redraw flag 
 
Parameters
hfont 
Value of wParam. Handle to the font. If this parameter is NULL, the control uses the default system font to draw text. 
fRedraw 
Value of lParam. Specifies whether the control should be redrawn immediately upon setting the font. Setting the fRedraw parameter to TRUE causes the control to redraw itself. 
Return Values
This message does not return a value. Res
The WM_SETFONT message applies to all controls, not just those in dialog boxes. The best time for the owner of a dialog box control to set the font of the control is when it receives the WM_INITDIALOG message. The application should call theDeleteObject function to delete the font when it is no longer needed; for example, after it destroys the control. The size of the control does not change as a result of receiving this message. To avoid clipping text that does not fit within the boundaries of the control, the application should correct the size of the control window before it sets the font. When a dialog box uses the DS_SETFONT style to set the text in its controls, the system sends the WM_SETFONT message to the dialog box procedure before it creates the controls. An application can create a dialog box that contains the DS_SETFONT style by calling any of the following functions: CreateDialogIndirect 
CreateDialogIndirectParam 
DialogBoxIndirect 
DialogBoxIndirectParam 
QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.See Also
Controls Overview, Control Messages, CreateDialogIndirect, CreateDialogIndirectParam,DeleteObject, DialogBoxIndirect, DialogBoxIndirectParam, WM_INITDIALOG, DLGTEMPLATE 
 

解决方案 »

  1.   

    定义CFont m_Font;
    然后初始化
    VERIFY(m_Font.CreateFont(12,0,0,0,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS, 
       CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,"宋体"));  
    GetDlgItem(控件ID)->SetFont(&m_Font);
      

  2.   

    1.在头文件.h定义一CFont  m_fFont;
    2.添加WM_CREATE事件,在OnCreate函数里写上
    LOGFONT lf;
    CFont *pFont = GetFont();
    pFong->GetLogFont(&lf);
    lf.lfHeigt控制字体高度
    lf.lfFaceName控制字体类型,利用LOGFONT这个结构里设置字体
    m_fFont.CreateFontIndirect(&lf);
    3.在OnInitDialog函数里
    SetFont(&m_fFont);