c++ - 在 Visual Studio C++ 2008 Pro 中对 MFC 对话框进行额外的初始化

标签 c++ mfc

如何在调用 DoModal() 之前对模态对话框进行额外的初始化; ?

整个应用程序是使用 VS 向导创建的。 我有一个主对话框(当我在 Visual Studio 2008 Professional 中选择新的 MFC 应用程序时自动创建的对话框)。
当我单击此对话框上的按钮时,我想打开另一个对话框并将 CString 值设置到 CEdit 控件中。

我的代码:

...
void MainDlg::OnClickedButtonX(){
   SecondDialogClass Dlg2;
   Dlg2.asocVar2Cedit.SetWindowTextW(L"my text");
   Dlg2.DoModal();
}
//asocVar2Cedit is the associeted control variable to the 
//CEdit control on the second Dialog (Right Click > Add Variable..  in VSC++)
...

此代码在运行时在 winocc 中生成“调试断言”错误...

有什么想法吗?
提前谢谢你。

最佳答案

OnInitDialog (WM_INITDIALOG) 处理程序添加到您的 CDialog 派生类,并让它自行初始化。

关于c++ - 在 Visual Studio C++ 2008 Pro 中对 MFC 对话框进行额外的初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2936001/

相关文章:

c++ - Docker/C++ 问题 - 编译错误/usr/bin/ld : cannot open output file server: Is a directory

c++ - 字符串在 vector 数组中被复制

c++ - #include <WinUsb.h> 在 MFC 应用程序中产生编译器错误

c++ MFC从工作线程设置/附加文本到richedit控件

c++ - 为什么这个循环是无限的?

C++ "typeid"错误 : operator not allowed in a constant expression

c++ - 在依赖的附加对象链上执行旋转变换的最快方法

c++ - 用C++枚举安装在windows上的应用程序

user-interface - MFC 组合框不可编辑

c++ - MFC WinApp在不同线程中调用InitInstance和OnAppExit/destructor