Visual studio 2013 配置属性=>Linker=>Advanced。在属性窗口的右侧,将“入口点”设置为“主”。如果看不到“入口点”,只需重新打开“属性”窗口。这是下面给出的函数“main”。这是您的应用程序开始运行的地方

Visual studio 2013 配置属性=>Linker=>Advanced。在属性窗口的右侧,将“入口点”设置为“主”。如果看不到“入口点”,只需重新打开“属性”窗口。这是下面给出的函数“main”。这是您的应用程序开始运行的地方,visual-studio-2013,Visual Studio 2013,最后,双击表单设计器并将光标移动到代码底部“namespace Project1”的右括号之前。粘贴以下代码。请记住根据您的项目需要重命名此代码的变量,以使其使用空表单 [STAThread] void main(array<String^>^ arg) { Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); MyForm form

最后,双击表单设计器并将光标移动到代码底部“namespace Project1”的右括号之前。粘贴以下代码。请记住根据您的项目需要重命名此代码的变量,以使其使用空表单

[STAThread]
void main(array<String^>^ arg) {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    MyForm form;
    Application::Run(%form);
}
[STAThread]
void main(数组^arg){
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
我的形式;
应用程序::运行(%form);
}

这个答案归功于@superlinux。

以下是制作这样一个项目的步骤:

  • 进入菜单栏:File=>New=>Project,获取项目模板列表
  • 在左边的树中选择:模板= > Visual C++。选择模板列表窗口右侧的:空项目(Visual C++)
  • “解决方案资源管理器”中将有一个新的文件树,这些文件属于您的新项目。展开它。假设您有一个名为“Project1”的新项目。您将在树的顶部看到“解决方案项目1(1个项目)”。展开树之后,您应该在展开的顶部“Solution Project1(1项目)”下找到一个名为“Project1”的东西。右键单击“项目1”。从右键单击菜单中选择“添加新项目”
  • 在“添加新项”中,从树到左边,转到:VisualC++ + = > UI= > Windows窗体。单击保存。 您将遇到以下问题:“您正在向本机项目添加CLR组件。该项目将转换为具有公共语言运行时支持。是否继续?”。单击“是”。 再次,右键单击“项目1”并转到“属性”
  • 在左边的树上,转到:配置属性=>Linker=>System。在属性窗口的右侧,将“SubSystem”设置为“Windows(/SubSystem:Windows)”
  • 另外还有:配置属性=>Linker=>Advanced。在属性窗口的右侧,将“入口点”设置为“主”。如果看不到“入口点”,只需重新打开“属性”窗口。这是下面给出的函数“main”。这是您的应用程序开始运行的地方
  • 最后,双击表单设计器并将光标移动到代码底部“namespace Project1”的右括号之前。粘贴以下代码。请记住根据您的项目需要重命名此代码的变量,以使其使用空表单

    [STAThread]
    void main(array<String^>^ arg) {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
    
        MyForm form;
        Application::Run(%form);
    }
    
    [STAThread]
    void main(数组^arg){
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    我的形式;
    应用程序::运行(%form);
    }
    

  • 这个答案要归功于@superlinux。

    这个指南对我不起作用,所以我在YouTube上搜索,很容易将下面的代码放在
    MyForm.cpp
    中,而不是帖子给出的代码中,这样做很有效

    using namespace System;
    using namespace System::Windows::Forms;
    
    [STAThread]
    
    void main(array<String^>^ args)
    {
    
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        Project1::MyForm form;
        Application::Run(%form);
    }
    
    使用名称空间系统;
    使用命名空间System::Windows::Forms;
    [状态线程]
    void main(数组^args)
    {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Project1::MyForm;
    应用程序::运行(%form);
    }
    
    指南对我不起作用,所以我在YouTube上搜索,很容易将下面的代码放在
    MyForm.cpp
    中,而不是帖子给出的代码,它很有效

    using namespace System;
    using namespace System::Windows::Forms;
    
    [STAThread]
    
    void main(array<String^>^ args)
    {
    
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        Project1::MyForm form;
        Application::Run(%form);
    }
    
    使用名称空间系统;
    使用命名空间System::Windows::Forms;
    [状态线程]
    void main(数组^args)
    {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Project1::MyForm;
    应用程序::运行(%form);
    }
    
    指南对我不起作用,所以我在YouTube上搜索,很容易将下面的代码放在
    MyForm.cpp
    中,而不是帖子给出的代码,它很有效

    using namespace System;
    using namespace System::Windows::Forms;
    
    [STAThread]
    
    void main(array<String^>^ args)
    {
    
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        Project1::MyForm form;
        Application::Run(%form);
    }
    
    使用名称空间系统;
    使用命名空间System::Windows::Forms;
    [状态线程]
    void main(数组^args)
    {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Project1::MyForm;
    应用程序::运行(%form);
    }
    
    指南对我不起作用,所以我在YouTube上搜索,很容易将下面的代码放在
    MyForm.cpp
    中,而不是帖子给出的代码,它很有效

    using namespace System;
    using namespace System::Windows::Forms;
    
    [STAThread]
    
    void main(array<String^>^ args)
    {
    
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        Project1::MyForm form;
        Application::Run(%form);
    }
    
    使用名称空间系统;
    使用命名空间System::Windows::Forms;
    [状态线程]
    void main(数组^args)
    {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Project1::MyForm;
    应用程序::运行(%form);
    }
    
    我知道这可能会很晚,但其他用户可能会好奇如何在保持终端窗口打开的同时做到这一点。这样,您可以使用
    cout
    测试次要内容。无论如何,您可以创建另一个.cpp文件(只是cpp文件,而不是一个全新的类),而不是将
    int main()
    放在UI中,在其中您可以有如下内容:

    #include "MainWindow.h" //which is the name of the UI file
    using namespace Projectname //you can check this at the top of the UI file says something like namespace Projectname { ui code }
    
    [STATHREADATTRIBUTE] //you need this otherwise your window can't run things like the webbrowser
    int main(){
        MainWindow mw; //the name of the header file
        mw.ShowDialog(); //this brings up the window, you can use mw.Hide() to close it
        return 0; 
    }
    

    这样,您就不必干扰配置,并且可以保持终端窗口打开。我相信您可以稍后通过配置属性关闭终端窗口。但我通常更喜欢这种方式,因为它更容易测试我的代码。

    我知道这可能会很晚,但其他用户可能会好奇如何在保持终端窗口打开的同时做到这一点。这样,您可以使用
    cout
    测试次要内容。无论如何,您可以创建另一个.cpp文件(只是cpp文件,而不是一个全新的类),而不是将
    int main()
    放在UI中,在其中您可以有如下内容:

    #include "MainWindow.h" //which is the name of the UI file
    using namespace Projectname //you can check this at the top of the UI file says something like namespace Projectname { ui code }
    
    [STATHREADATTRIBUTE] //you need this otherwise your window can't run things like the webbrowser
    int main(){
        MainWindow mw; //the name of the header file
        mw.ShowDialog(); //this brings up the window, you can use mw.Hide() to close it
        return 0; 
    }
    
    这样,您就不必干扰配置,并且可以保持终端窗口打开。我相信你可以通过窗户把候机楼的窗户关上