最近有几位朋友找我,VS 2012的Express版本,在C++(www.cppentry.com)/CLR项目中只能编写控制台应用程序,不支持WinForm啊,怎么办
于是,有人就尝试在CLR的控制台应用程序中编写Windows Forms应用程序,理论上讲嘛,是可以的,不信 你看看下面的代码.
[cpp] view plaincopyprint
// C++(www.cppentry.com)
#include "stdafx.h"
using namespace System;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
System::Windows::Forms::Form^ mainForm = gcnew System::Windows::Forms::Form();
// 窗体大小
mainForm->Height=300;
mainForm->Width =500;
// 窗体标题
mainForm -> Text = L"我的主窗口";
// 窗口的初始位置
mainForm -> StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
// 开始在窗口上的主消息循环并显示窗口
System::Windows::Forms::Application::Run(mainForm);
return 0;
}
// C++(www.cppentry.com)
#include "stdafx.h"
using namespace System;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
System::Windows::Forms::Form^ mainForm = gcnew System::Windows::Forms::Form();
// 窗体大小
mainForm->Height=300;
mainForm->Width =500;
// 窗体标题
mainForm -> Text = L"我的主窗口";
// 窗口的初始位置
mainForm -> StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
// 开始在窗口上的主消息循环并显示窗口
System::Windows::Forms::Application::Run(mainForm);
return 0;
}
可以说这段代码是没有问题的,运行一下就知道了.

程序是运行起来了,但让很多人不高兴,为啥 你认真瞧瞧,它总是会伴随着一个DOS窗口启动,这不太像WinForm,至少要不让那个DOS窗口跑出来.