VS2017如何创建C ++ CLR Windows窗体应用程序?

VS2017 C++/CLR无法使用windows窗体。网上查资料是微软从VS2012起就故意这么干,逼用户转向C#或VB。

搜了一上午终于找到解决方案,附后。

 

方法一: 安装插件:

VS2017 2019可以在VS插件中搜索1个德国人写的C++/CLR WINDOWS FORMS插件安装。

然后新建项目。

使用这个模板自动加1个窗体和相应代码,但是如果你试着自己手动加第二个窗体就仍然出错,并且不知其所以然。还有个笨办法,用支持C++/CLR WINDOWS窗体程序的老VS 2010,2008创建工程,添加窗体。然后在新VS中导入、升级。不过这样还是面临着你如果新增窗体就会出错。

方法二:祖传纯手工解决法(2017中测试通过)

原帖:https://social.msdn.microsoft.com/Forums/vstudio/en-US/9f0d10d4-4f1d-44fa-99ed-da08e7f25fc7/windows-forms-application-in-visual-c-

以下是粗鄙翻译,可能词不达意,英文原文复制在后

问题:我没有找到“UI”和Windows窗体那里..如何安装它?什么版本的Visual Studio?

答:如何创建C ++ CLR Windows窗体应用程序。对于VS2017,它必须是26206或更高版本,否则Designer失败。

【截图自2019,测试通过】

使用默认名称Project1创建一个新的C ++ CLR空项目

在解决方案资源管理器中
  右键单击:Project1 


    选择:属性

左侧属性
  展开:配置属性
  展开:链接器
  选择:系统

在子系统下
  选择右侧:窗口(/ SUBSYSTEM:WINDOWS)

在左侧
  选择:高级

在右边的入口点
  输入:Main
(区分大小写)

选择按钮:确定

在解决方案资源管理器中
  右键单击:Project1
  选择:添加
  选择:新建项


在左边
  展开:已安装
  展开:Visual C ++ 
  选择:UI

在右边
  选择:Windows窗体
只需使用默认名称MyForm.h ... 
  选择:添加
等待它加载并解析所有文件!

现在关闭崩溃的窗体设计器!

在解决方案资源管理器中
  展开: Project1 
  展开:源文件
  右键单击:MyForm.cpp 
  选择:查看代码

将以下代码粘贴到#include“MyForm.h”下面

using namespace Project1;

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

  MyForm form;
  Application::Run(%form);
}

选择:文件
选择:全部保存

以使设计器在VS2017 build 26206.0或更高版本中工作... 


选择:文件
选择:关闭解决方案

VS完成后自行清理

打开解决方案,设计器现在可以正常工作。

-祝开心!
fh:)_~ 
RIP Hammer 锐 蛤蟆

建议作为 hst12的答案 2017年3月27日星期一上午11:26

补遗:现在可以继续添加新窗体了。添加新窗体后,新窗体的设计器还是会崩溃!不要慌,关闭它,然后全部保存文件,再选择关闭解决方案。最后重新打开project1,即可。

---------------------------------------------------------------------------------
Create a new project, in "Visual C++" select 'CLR' and then select 'CLR Empty Project', wait till the project loaded completely, after that click on "Project" then "Add New Item..." then on the left side choose "UI" then choose "Windows Form".


I dont find "UI" and windows form there.. How to install it?
What version of Visual Studio?

How to create a C++ CLR Windows Forms Application. For VS2017 it must be build 26206 or later else Designer fails.

Create a new C++ CLR Empty Project with the default name of Project1

In Solution Explorer
  Right Click: Project1
    Select   : Properties

On Left side
  Expand   : Configuration Properties
  Expand   : Linker
  Select   : System

On right side under SubSystem
  Select   : Windows (/SUBSYSTEM:WINDOWS)

On Left side
  Select   : Advanced

On Right side under Entry Point
  Enter    : Main
(Case sensitive)

Select Button: OK

In Solution Explorer
  Right Click: Project1
  Select     : Add
  Select     : New Item
On Left
  Expand     : Installed
  Expand     : Visual C++
  Select     : UI
On Right
  Select     : Windows Form
Just use the default name of MyForm.h ...
  Select     : Add
Wait for it to load and parse all files!
Close the crashed Designer!

In Solution Explorer
  Expand:    : Project1
  Expand     : Source Files
  Right Click: MyForm.cpp
  Select     : View Code

Paste the following code below the #include "MyForm.h"

using namespace Project1;

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

  MyForm form;
  Application::Run(%form);
}


Select : File
Select : Save All

Now to get the Designer to work in VS2017 build 26206.0 or later ... 
Select : File
Select : Close Solution

After VS is done cleaning up after itself

Open the Solution, Designer should now work.

-Enjoy
fh : )_~
RIP Hammer

Proposed as answer by hst12 Monday, March 27, 2017 11:26 AM
Monday, February 20, 2017 12:46 AM
 

  • 12
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值