MFC的static控件问题

zhou1zhou8 2009-09-17 05:15:10
怎么改变其内字体的大小?急等。
...全文
108 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fishion 2009-09-17
  • 打赏
  • 举报
回复
CFont m_font;放到类声明里


CFont* pFont = GetDlgItem(IDC_STATIC1)->GetFont();
LOGFONT lf;
pFont->GetLogFont(&lf);
lf.lfWidth = 7;
lf.lfHeight = 14;
lf.lfWeight =650;
//strcpy(lf.lfFaceName, _T("Arial"));
m_font.CreateFontIndirect(&lf);
GetDlgItem(IDC_STATIC1)->SetFont(&m_font);
WuXinyang 2009-09-17
  • 打赏
  • 举报
回复
m_CtrlText.Create("创建CStatic控件", WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, 33);
m_NormalFont.CreateFont(-16,0, 0,0,400, 0,0,0, 134, 3,2,1, 49,"隶书");
m_CtrlText.SetFont(&m_NormalFont);

在OnCreate里写
chb610 2009-09-17
  • 打赏
  • 举报
回复
MARK
youyifang 2009-09-17
  • 打赏
  • 举报
回复
setfont()
zyq5945 2009-09-17
  • 打赏
  • 举报
回复
别人写的一个变色CStatic
#if !defined(AFX_ColorStatic_H__4CCD6BDB_9694_47EC_A643_42A2CEBF62DF__INCLUDED_)
#define AFX_ColorStatic_H__4CCD6BDB_9694_47EC_A643_42A2CEBF62DF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000



class CColorStatic : public CStatic //可设置背景颜色的静态框
{

public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CColorStatic)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL

public:
void SetText(LPCTSTR lpszText);

protected:
CFont m_font;
CRect m_rc;
CString m_strText;

//{{AFX_MSG(CColorStatic)
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ColorStatic_H__4CCD6BDB_9694_47EC_A643_42A2CEBF62DF__INCLUDED_)


#include "stdafx.h"
#include "resource.h"
#include "ColorStatic.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(CColorStatic, CStatic)
//{{AFX_MSG_MAP(CColorStatic)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CColorStatic::OnPaint()
{
CPaintDC dc(this);

dc.FillSolidRect(m_rc,RGB(123,156,235)); //绘制背景

dc.SelectObject(&m_font);
dc.SetBkMode(TRANSPARENT); //设置背景透明
dc.SetTextColor(RGB(255,255,255)); //设置文字颜色为白色
dc.DrawText(m_strText.GetBuffer(0),m_strText.GetLength(),&m_rc,DT_SINGLELINE | DT_VCENTER | DT_LEFT | DT_PATH_ELLIPSIS);
}



void CColorStatic::SetText(LPCTSTR lpszText)
{
m_strText = lpszText;
Invalidate();
}


/********************************************************************/
/* */
/* Function name : PreSubclassWindow */
/* Description : Initialize control variables */
/* */
/********************************************************************/
void CColorStatic::PreSubclassWindow()
{
GetClientRect(m_rc);

m_font.CreateFont(12, 0,0,0,FW_BOLD, 0,0,0,
DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "宋体");

CStatic::PreSubclassWindow();
}

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧