请教:关于Dialog中SetFont()的用法,HELP……
vc建立的MFC单文档项目,想通过SetFont()来改变Dialog中的字体。
先看看代码:
CFont font;//成员变量,即在.h文件中声明
在OnInitDialog()中填加如下代码:
CDialog::OnInitDialog();
……
font.CreateFont(30,0,0,0,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,"宋体");
this->SetFont();
……
return TRUE;
对话框显示出来的时候,Dialog上Static控件,Button控件,…… 一点变化都没有。
是不是我使用SetFont()的方法有问题?还是不应该在OnInitDialog()中设置字体?
小弟苦思不得其解,特来求教。
请帮忙,谢谢!
问题点数:0、回复次数:5Top
1 楼Semigod()回复于 2004-12-02 22:54:42 得分 0
SetFont(&font);Top
2 楼leky2000(懒客)回复于 2004-12-02 23:00:17 得分 0
是啊,没有参数怎么set啊另外你为什么不在对话框资源文件中直接改为你的font?Top
3 楼vcleaner(我没当大哥很久了.......)回复于 2004-12-03 08:20:46 得分 0
参考:
修改属性页字体
http://support.microsoft.com/default.aspx?scid=kb;en-us;142170Top
4 楼jiangsheng(蒋晟.Net[MVP])回复于 2004-12-03 08:34:03 得分 0
http://community.csdn.net/Expert/TopicView.asp?id=3601128Top
5 楼chwk(学习ing)回复于 2004-12-03 08:45:24 得分 0
可以查看MSDN
Called by the framework when a visual aspect of an owner-drawn button has changed.
virtual void DrawItem(
LPDRAWITEMSTRUCT lpDrawItemStruct
);
Example
// NOTE: CMyButton is a class derived from CButton. The CMyButton
// object was created as follows:
//
// CMyButton myButton;
// myButton.Create(_T("My button"),
// WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,
// CRect(10,10,100,30), pParentWnd, 1);
//
// This example implements the DrawItem method for a CButton-derived
// class that draws the button's text using the color red.
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
UINT uStyle = DFCS_BUTTONPUSH;
// This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
// If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED;
// Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle);
// Get the button's text.
CString strText;
GetWindowText(strText);
// Draw the button text using the text color red.
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
Top




