C++/CLI使用指南

Download Report

Transcript C++/CLI使用指南

C++/CLI使用指南
C++/CLI简介



C++语言,它实现了运行时取得速度和尺寸
最佳化的静态对象模型,然而它除了堆分配
外不支持程序的动态修改,它准许无限地接
近底层设备,但在程序运行过程中几乎无法
操作活动类型,也无法操作与程序相关联的
底层结构。
CLI(Common Language Infrastructure )
指的是通用语言结构,一种支持动态组件编
程模型的多重结构
C++/CLI——两者的捆绑
静态C++对象模型到CLI的动态组件对
象编程模型的捆绑
 如何用C++在.NET中编程
 C++/CLI正在ECMA(欧洲计算机制造
商协会)主持下进行标准化,以最终符
合ISO标准
 实时通用语言(CLR)是CLI的微软版
本

C#和C++/CLI速度比较
重复次数 C# 程序
 50,000
61
 500,000
600
 1,000,000
1162
 5,000,000
6369

C++程序
10
70
140
721
学习内容
新的语法
 新的指针
 控件的使用
 从C++/CLI到CTS的映射
…

生物信息学算法软件的开发
利用C++/CLI语言(或者利用C#)
 界面
 算法

控件的使用
主菜单——menuStrip
 快捷栏——toolStrip
 状态栏——statusStrip
 数据表——dataGridView
 对话框——openFileDialog,
saveFileDialog

第三方控件

Dundas Charts
menuStrip
文件(&F)
 Click事件

toolStrip
Click事件
 图标

statusStrip
statusLabel
 其他

dataGridView
与数据库的绑定
 添加数据
 array<String^ >^
 dataGridView1->Rows->Add(…);

openFileDialog

属性的改写
默认目录
 文件后缀(文本文件(*.txt)|*.txt|所有文件
(*.*)|*.*)
 默认文件后缀
 Title
…

使用方法
if ( openFileDialog1->ShowDialog() ==
System::Windows::Forms::DialogRes
ult::OK )
 if ( (fileStream = openFileDialog1>OpenFile()) == nullptr)


或者openFileDialog1->FileName
MessageBox

MessageBox::Show(L"文件没有打
开!", L"错误窗口",
MessageBoxButtons::OK,
MessageBoxIcon::Error);
其他控件
textBox
 Memo
 RichEdit
…

Dundas Charts
各种图形
 2D 3D 线 点 柱状图 面积图等等
 与数据库连接
 自己添加数据

简单的使用
for (int i = 0; i < x.size(); i++)
 {

chart1->Series["Series1"]->Points>AddXY(x[i], y[i]);
}
 chart1->Invalidate();

chart1->Series["Series1"]->Points>Clear();
 chart1->Invalidate();

动态组件的指针
声明 ^
 申请内存 gcnew
 System中的类
 空指针 nullptr
 其他指针

字符串
System::String
 std::string
 char *
 string与char *的转换
 S.c_str()
 String与string的转换?
 L”str”

文件的打开
















Stream ^fileStream;
if ( openFileDialog1->ShowDialog() ==
System::Windows::Forms::DialogResult::OK )
{
if ( (fileStream = openFileDialog1->OpenFile()) == nullptr)
{
MessageBox::Show(L"文件没有打开!", L"错误窗
口", MessageBoxButtons::OK, MessageBoxIcon::Error);
return;
}
StreamReader^ sr = gcnew StreamReader(fileStream);
String^ line;
vector <double> x, y;
while ((line = sr->ReadLine()) != nullptr)
{
array<String^ >^ splitString = nullptr;
splitString = line->Split('\t', 2);
}