VC6重载字体对话框,去除颜色下拉框

为了去除字体对话框中的颜色下拉框,我们需要重载字体对话框类:CFontDialog

1. 创建一个MFC Class,继承自CFontDialog:

// MyFontDialong.h : header file
//


// CMyFontDialong dialog

class CMyFontDialong : public CFontDialog
{
	DECLARE_DYNAMIC(CMyFontDialong)

public:
	CMyFontDialong(LPLOGFONT lplfInitial = NULL,
		DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS,
		CDC* pdcPrinter = NULL,
		CWnd* pParentWnd = NULL);
#ifndef _AFX_NO_RICHEDIT_SUPPORT
	CMyFontDialong(const CHARFORMAT& charformat,
		DWORD dwFlags = CF_SCREENFONTS,
		CDC* pdcPrinter = NULL,
		CWnd* pParentWnd = NULL);
#endif

protected:
	//{{AFX_MSG(CMyFontDialong)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

2. 重载OnInitDialog(),通过添加消息WM_INITDIALOG,实现如下:



BOOL CMyFontDialong::OnInitDialog() 
{
	CFontDialog::OnInitDialog();
	
	CWnd*   pStatic = GetDlgItem(0x473);		// 静态文本框:"颜色:"
	CWnd*   pComboBox = GetDlgItem(0x443);		// ComboBox:	"颜色下拉框"
	pStatic->ShowWindow(SW_HIDE);
	pComboBox->ShowWindow(SW_HIDE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
}

到此,这个定制的对话框就完成了。剩下的就是建立一个基于对话框的应用程序来测试下了。我是先建立基于对话框的MFC应用程序,再新建CMyFontDialog的,效果一样。

最后运行结果如下:



下面来解释下最关键的东西,那就是我怎么知道要隐藏的那两个控件的ID呢?呵呵,说出来其实也不是什么秘密--利用VC6自带的工具Spy++,看图解:



相信你应该明白了吧!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值