求助::一个窗体与一个.cpp之间如何关联??

marcus2006 2008-03-08 12:01:37
环境:VS2005
目标:创建一个象Msgbox的窗体,有Yes和No两个button,如果选Yes我就调用另一个cpp中的函数,否则就关闭它.15秒不选择就默认选择No.
创建步骤:1.先创建了一个控制台CLR,生成了一个EnumWindows的cpp,项目名字就叫EnumWindows
2.在这个cpp中我写了自己的函数
3.插入一个Form窗体叫msgbox,添加2个button
问题:
我如何在msgbox中调用cpp中的函数?
1.我尝试创建一个叫EnumWindows的头文件,里面申明了cpp我要用的namespace
2.在msgbox头上include这个头文件,然后using 了我要用的namespace
3.尝试在msgbox的Yes的单击时用 我的namespace::函数名 的方法调用,发现不能识别

本人还在看[c++经典入门],入门时间不长,所以这些问题可能对很多人比较肤浅,但是我确实不懂,还请赐教.麻烦写清楚步骤.谢谢
源码:绿色是我自己加的,其他系统自动生成#pragma once
EnumWIndows.h的内容:
namespace marcus;


msgbox.h的内容,它就是窗体双击显示的内容
#include "EnumWindows.h"
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using marcus;

namespace EnumWindows {

/// <summary>
/// Msgbox 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class Msgbox : public System::Windows::Forms::Form
{
public:
Msgbox(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}

protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Msgbox()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Timer^ timer1;
private: System::Windows::Forms::Label^ time;
private: System::ComponentModel::IContainer^ components;
protected:

private:
/// <summary>
/// 必需的设计器变量。
/// </summary>


#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->time = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(30, 103);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"Yes";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Msgbox::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(146, 103);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 1;
this->button2->Text = L"No";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Msgbox::button2_Click);
//
// label1
//
this->label1->Location = System::Drawing::Point(28, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(236, 77);
this->label1->TabIndex = 2;
this->label1->Text = L"Do you want to perform another EnumWindows\?The result will be stored in another M"
L"arcus_EnumWindows_i,\'i\' is self added.No click in 15 seconds, \'No\' is default bu"
L"tton";
//
// time
//
this->time->AutoSize = true;
this->time->Location = System::Drawing::Point(109, 146);
this->time->Name = L"time";
this->time->Size = System::Drawing::Size(59, 12);
this->time->TabIndex = 3;
this->time->Text = L"0 Seconds";
//
// Msgbox
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(266, 177);
this->Controls->Add(this->time);
this->Controls->Add(this->label1);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Name = L"Msgbox";
this->Text = L"Msgbox";
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {

Msgbox::Close ;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
marcus:: //这个地方想加marcus下的函数,系统不能识别 }
};
}
...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
marcus2006 2008-03-10
  • 打赏
  • 举报
回复
flush
marcus2006 2008-03-08
  • 打赏
  • 举报
回复
增加说明
1.cpp就是创建时生成的一个cpp文件
2.我是后来才加的msgbox窗体,如果让项目先启动它,而不是先启动我的EnumWindows.cpp?
marcus2006 2008-03-08
  • 打赏
  • 举报
回复
Flush

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧