简体   繁体   English

MFC应用程序:从窗体按钮启动一个(模式)对话框

[英]MFC Application: launch a (modal) dialog from a form button

I'm completely new at this and I'm trying to use VS2013 and C++ and loosely follow "Ivor Horton's Beginning Visual C++ 2010" to figure out how windows form apps and dialogs work. 我是一个全新的人,我正在尝试使用VS2013和C ++,并松散地遵循“ Ivor Horton的Beginning Visual C ++ 2010”来了解Windows窗体应用程序和对话框的工作方式。 I seem to be miserably failing at figuring out something that should be extremely simple. 我似乎很没能弄清应该非常简单的内容。

I've made a form, MyForm , added a button to it, IDD_DIALOG1 . 我制作了一个表单MyForm ,在其中添加了一个按钮IDD_DIALOG1

I also created a dialog, MyFirstDialog . 我还创建了一个对话框MyFirstDialog

I want to be able to launch MyFirstDialog when I click on IDD_DIALOG1 . 我希望能够在单击IDD_DIALOG1时启动MyFirstDialog

The book talks about event handlers, but I can't seem to find a way to get to any, so instead I have been trying to add code in the button1_Click function in MyForm.h : 这本书讨论了事件处理程序,但是我似乎找不到任何方法,所以我一直试图在MyForm.hbutton1_Click函数中添加代码:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             MyFirstDialog dlg;
             dlg.DoModal();
}

However, this completely breaks my program, with an assertion failure: 但是,这完全破坏了我的程序,并导致断言失败:

断言失败

I've looked online but I wasn't able to figure it out at all... 我在网上看过,但根本无法弄清楚...

OK, so I believe @The Forest And The Trees is right in his comment above, and WinForms don't work well with MFC. 好的,所以我相信@The Forest And The Trees在上面的评论中是正确的,并且WinForms在MFC上不能很好地工作。

I am switching over to pure MFC now. 我现在要切换到纯MFC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM