简体   繁体   English

如何制作一个CDialog?

[英]How to make a CDialog?

I have tried multiple things but the base comes to this: 我已经尝试了多种方法,但是基础在于:

#include <stdio.h>
#include <afxwin.h>


main( int argc, const char* argv[] )
{

   printf( "\nHello World\n\n" );

   CDialog *dlg = new CDialog();
   dlg->DoModal();

   while (true) {
      Sleep(1); // Sleep is a windows function
   }
}

When I run this, I get the following error: 运行此命令时,出现以下错误:

调试断言失败消息

What am I missing for this dialog? 我在此对话框中缺少什么?

I looked up several resources, but everything results in the same error message. 我查找了几个资源,但是所有内容都导致相同的错误消息。

Can someone tell me what am I not seeing? 有人可以告诉我我没看到什么吗?

Using the MFC in a console application requires some initializations. 在控制台应用程序中使用MFC需要一些初始化。 Without this you will get asserts. 没有这个,您将得到断言。

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
        // TODO: change error code to suit your needs
        _tprintf(_T("Fatal Error: MFC initialization failed\n"));
        return 8;
    }

You must also use a resource that is bound to the CDialog. 您还必须使用绑定到CDialog的资源。 You may use the appropriate constructors. 您可以使用适当的构造函数。 Or you derive your own dialog from CDialog using the class wizard. 或者,您可以使用类向导从CDialog派生自己的对话框。

But it doesn't make sense to me to create an MFC console application and use dialogs... Your question may need more details, what you want to do, and why you want to do it in this way. 但是创建一个MFC控制台应用程序并使用对话框对我来说没有任何意义。您的问题可能需要更多详细信息,要执行的操作以及为什么要这样做。

You may need to read some books or article before you continue this way of programming. 在继续这种编程方式之前,您可能需要阅读一些书籍或文章。

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

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