将公共控件或 Rich Edit 控件添加到对话框之后,在测试对话框时该控件不出现,或者对话框本身不出现。
问题示例
创建 Win32 项目,修改应用程序设置以创建 Windows 应用程序(不是控制台应用程序)。
在资源视图中,双击 .rc 文件。
在 Dialog 选项下,双击“关于”框。
将一个“IP Address Control”添加到对话框。
保存并“全部重新生成”。
执行程序。
在对话框的“帮助”菜单上,单击“关于”命令;没有显示任何对话框。
原因
目前,将下列公共控件或 Rich Edit 控件拖放到对话框上时,对话框编辑器不自动在项目中添加代码。当此问题发生时,Visual Studio 既不提供错误也不进行警告。必须手动为控件添加代码。
Slider Control Tree Control Date Time Picker
Spin Control Tab Control Month Calandar
Progress Control Animation Control IP Address Control
Hot Key Rich Edit Control Extended Combo Box
List Control Rich Edit 2.0 Control Custom Control
公共控件的修复
为了在对话框上使用公共控件,需要在创建对话框之前调用 InitCommonControlsEx 或 AFXInitCommonControls。
RichEdit 控件的修复
必须为 Rich Edit 控件调用 LoadLibrary。有关更多信息,请参阅 Platform SDK 中的对 RichEdit 1.0 控件使用 MFC、关于 Rich Edit 控件,以及 Rich Edit 控件概述。
#pragma comment( lib, "comctl32.lib" ) //此句的意思是让链接器在链接时寻找comctl32.lib库文件
INITCOMMONCONTROLSEX ipaddress={sizeof(ipaddress),ICC_INTERNET_CLASSES};
InitCommonControlsEx(&ipaddress);
DialogBoxParam(hinstExe, MAKEINTRESOURCE(IDD_DIALOG1), NULL, Dlg_Proc, _ttoi(pszCmdLine));
Reference:http://msdn.microsoft.com/zh-cn/library/dsezt3x7.aspx