MFC中button控件背景色和字体的设置,或者可以采用添加背景图片的方法;已验证有效MFC其他的简单使用使用

所有的操作针对添加的对话框

添加初始化:类导向--虚函数--OnInitDialog()

1、添加背景色:WM_PAINT->void CAboutDlg::OnPaint()


2、调用子对话框:InitInstance();创建了新的对话框,不要忘记将类添加到头文件中

3、

关于改变AfxMessageBox对话框标题

   其实这个标题,也就是我们的默认的工程名,我们应该怎么在不改变工程名的基础上改变标题呢?其实这个标题在资源StringTable里就能找到,查找AFX_IDS_APP_TITLE,在这里你就能轻而易举的改变标题了

4、MFC中改变button的背景颜色和字体颜色,字体大小等;采用自绘的方式:需要将控件Owner Draw改为TRUE,不然无法没有效果

添加ClrButton.h

#if !defined(AFX_CLRBUTTON_H__3611A4FC_CBDB_11D5_A183_B13329B34330__INCLUDED_)
#define AFX_CLRBUTTON_H__3611A4FC_CBDB_11D5_A183_B13329B34330__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ClrButton.h : header file
//

/
// CClrButton window

const COLORREF BLACK = RGB(1, 1, 1);
const COLORREF GRARY = RGB(122, 122, 122);
const COLORREF DKRED = RGB(128, 0, 0);
const COLORREF GREEN = RGB(0, 255, 0);
const COLORREF RED = RGB(255, 0, 0);
const COLORREF BLUE = RGB(0, 0, 255);
const COLORREF WHITE = RGB(255, 255, 255);

class CClrButton : public CButton
{
// Construction
public:
	CClrButton();

// Attributes
public:
// Operations
public:
	// UK version
	void SetColour(COLORREF text_colour, 
				   COLORREF background_colour);

	// US version
	void SetColor(COLORREF text_colour, 
				  COLORREF background_colour)
	{
		SetColour(text_colour, 
				  background_colour);		
	};

	// UK version
	void SetColour(COLORREF text_colour, 
				   COLORREF background_colour, 
				   COLORREF disabled_background_colour);

	// US version
	void SetColor(COLORREF text_colour, 
				  COLORREF background_colour, 
				  COLORREF disabled_background_colour)
	{
		SetColour(text_colour, 
				  background_colour, 
				  disabled_background_colour);
	};

	void ResetColour();

// Overrides
	// ClassWizard generated virtual function overrides
	//{
  {AFX_VIRTUAL(CClrButton)
	public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CClrButton();

private:
	COLORREF text_colour, background_colour, disabled_background_colour;
	COLORREF light, highlight, shadow, dark_shadow;

	// Generated message map functions
protected:
	//{
  {AFX_MSG(CClrButton)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG

	void DrawFrame(CDC *dc, CRect r, int state);
	void DrawFilledRect(CDC *dc, CRect r, COLORREF colour);
	void DrawLine(CDC *dc, long sx, long sy, long ex, long ey, COLORREF colour);
	void DrawButtonText(CDC *dc, CRect r, const char *buf, COLORREF text_colour);

	DECLARE_MESSAGE_MAP()
};

/

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

#endif // !defined(AFX_CLRBUTTON_H__3611A4FC_CBDB_11D5_A183_B13329B34330__INCLUDED_)


添加ClrButton.c(在编码不同时,下面可能产生错误;Unicode和宽字节编码)

// ClrButton.cpp : implementation file
//


#include "stdafx.h"
#include "ClrButton.h"
<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一枚努力的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值