如何在Visual Studio.net C ++ 2005中以.cpp文件而不是.h文件运行Windows窗体应用程序 [英] how to run a windows form application in .cpp file instead of .h file in visual studio.net c++ 2005
问题描述
我已经在Visual Studio 2005(Windows窗体应用程序)中的按钮下的头文件中编写了一个代码,但是我想将此代码包括在.cpp文件下.但是如果我直接将此代码复制到.cpp文件中,则会出现错误.可能是我在头文件中定义了函数原型,而在cpp中定义了函数定义.您能给我发送一些示例文件来对头文件和cpp文件做些什么吗?请帮我.
以下只是.h文件中代码的一小部分:
私人:System :: Void button1_Click(System :: Object ^发件人,System :: EventArgs ^ e){
array& lt; Char& gt; ^ arr;
arr = richTextBox1-& gt;文本-& gt; ToCharArray();
int imgsize,imgsize1,ht,wdth;
ht = pictureBox1-& gt;图片-> Height;
wdth = pictureBox1-& gt;图片-> Width;
imgsize = ht * wdth;
imgsize1 = imgsize/8;
int len = richTextBox1-& gt; Text-> Length;
//数组声明
阵列& lt;阵列& lt; int& gt;> ^ messag = gcnew array<阵列& lt; int& gt; ^& gt;(imgsize1);
for(int i = 0; i& lt; imgsize1; i ++)
{messag [i] = gcnew array& lt; int& gt;(8);
}
int length = richTextBox1-& gt; Text-> Length;
embed1 :: Class1 c;
messag = c.chartobin(arr,length,imgsize1); //将文本frm textBox转换为二进制;
//打印到文件//
文件* fp1;
if((fp1 = fopen("message.txt","wb"))== NULL)
{printf("\ a \ n在创建文件时出错.\ n系统正在退出....");
出口(0);
}
for(int j = 0; j& lt; messag-& gt; Length; j ++)
{for(int i = 0; i& ltmessag [j]-& gt; Length; i ++)
{fprintf(fp1,%d",messag [j] [i]);
}
fprintf(fp1,");}
i hav written a code in header file under a button in visual studio 2005(windows form application)but i want to include this code under .cpp file.but if i copy this code directly into .cpp file it gives error.may be i hav to define the function prototype in header file and the function definition in cpp.can u pls send me some example to do this for both header and cpp file.pls help me..its urgent
the following is just a little part of the code in .h file:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
array<Char>^arr;
arr = richTextBox1->Text->ToCharArray();
int imgsize,imgsize1,ht,wdth;
ht=pictureBox1->Image->Height;
wdth=pictureBox1->Image->Width;
imgsize=ht*wdth;
imgsize1=imgsize/8;
int len=richTextBox1->Text->Length;
//array declaration
array< array< int >^ >^ messag= gcnew array< array< int >^ >(imgsize1);
for(int i=0;i<imgsize1;i++)
{ messag[i] = gcnew array<int>(8);
}
int length =richTextBox1->Text->Length;
embed1::Class1 c;
messag = c.chartobin(arr,length,imgsize1); //converts text frm textBox to binary;
//Printing to a file//
FILE *fp1;
if((fp1=fopen("message.txt","wb"))==NULL)
{ printf("\a\nError while creating a file.\nSystem is exiting....");
exit(0);
}
for (int j = 0; j < messag->Length; j++)
{ for(int i=0;i<messag[j]->Length;i++)
{ fprintf(fp1,"%d",messag[j][i]);
}
fprintf(fp1," ");}
推荐答案
您将需要头文件中的函数原型和cpp文件中的函数定义.确保它们匹配并且两个文件都包括在内.
您得到的错误是什么? :)
You will need the function prototype in a header file and the function definition in cpp file. Make sure they match and both files are included.
What is the error that you are getting? :)
这篇关于如何在Visual Studio.net C ++ 2005中以.cpp文件而不是.h文件运行Windows窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!