为了去除字体对话框中的颜色下拉框,我们需要重载字体对话框类:CFontDialog
1. 创建一个MFC Class,继承自CFontDialog:
// MyFontDialong.h : header file//// CMyFontDialong dialogclass 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_SUPPORTCMyFontDialong(const CHARFORMAT& charformat,DWORD dwFlags = CF_SCREENFONTS,CDC* pdcPrinter = NULL,CWnd* pParentWnd = NULL);#endifprotected://{{AFX_MSG(CMyFontDialong)virtual BOOL OnInitDialog();//}}AFX_MSGDECLARE_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++,看图解:
相信你应该明白了吧!