(1)鼠标右击项目节点,从弹出的快捷菜单中选择【属性】。

(2)在项目属性窗口中,依次找到“配置属性- 常观”,在右边的属性设置网格中找到“公共语言运行时支持”,选择“公共语言运行时支持(/clr)”。

记得为debug和release模式也设置一遍。
(3)展开“通用属性 - 框架和引用”,添加可能会用到的程序集的引用。

单击“确定”按钮,关闭属性窗口。这样,就配置好了,下面就可以编写托管代码了。
在解决方案资源管理器中,右击项目节点,从弹出的菜单中选择【添加】-【新建项】,在弹出的窗口中,找到UI节点,在右边窗格中选择“Windows窗体”。
输入名字后单击确定,这时候,我们看到灰常熟悉的窗口设计器,我们可在上面扔控件。

双击按钮,编写它的Click事件处理代码.
[cpp] view plaincopyprint
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
System::Windows::Forms::MessageBox::Show(
L"你选择的日期是:" + this->dateTimePicker1->Value.ToString(L"yyyy年MM月dd日"),
L"提示信息",
System::Windows::Forms::MessageBoxButtons::OK,
System::Windows::Forms::MessageBoxIcon::Information);
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
System::Windows::Forms::MessageBox::Show(
L"你选择的日期是:" + this->dateTimePicker1->Value.ToString(L"yyyy年MM月dd日"),
L"提示信息",
System::Windows::Forms::MessageBoxButtons::OK,
System::Windows::Forms::MessageBoxIcon::Information);
}
到了现在,窗口做好了,不过啊,还不能运行,我们还有关键的一步,对,入口点.
右击项目节点,从弹出来的菜单中选择【添加】-【新建项】,在 代码 节点下选择C++(www.cppentry.com)文件 *.cpp,随便给个名字,确定,我们在这里面写入口点函数.
注意了,我们要的是Windows应用程序,不是DOS控制台,所以我们写的是WinMain函数.首先,要包含Windows.h头文件.
看看,入口点函数如下:
[cpp] view plaincopyprint
#include <Windows.h>
int WINAPI wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd
)
{
// ..........
return 0;
}
#include <Windows.h>
int WINAPI wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd
)
{
// ..........
return 0;
}