我找到了一个旧的C ++控制台应用程序,我将其转换为Windows窗体。到目前为止,我已设法创建一个表单并让它调用一个函数。调用了一系列函数,用于使用std:ccout
将状态消息写入控制台,如下所示:
std::cout << "Program All using COM-object interface only" << std::endl;
我的表单上有一个公共TextBox(MyForm.h)
所有旧函数都放在Programmer.h中,MyForm.h中为#include "Programmer.h"
。
我可以让MyForm.h调用一个函数并使用它返回的值如下:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->txtBoxStatus->Text = "START";
this->txtBoxResult->BackColor = System::Drawing::Color::LightYellow;
this->txtBoxStatus->BackColor = System::Drawing::Color::LightYellow;
int s1 = 9;
s1 = StartProgram();
if (s1 == 1) {
this->txtBoxResult->BackColor = System::Drawing::Color::Green;
this->txtBoxResult->Text = "PASS";
}
if (s1 == 0) {
this->txtBoxResult->BackColor = System::Drawing::Color::Red;
this->txtBoxResult->Text = "FAIL";
//this->txtBoxStatus->BackColor = System::Drawing::Color::Red;
}
}
我想要做的是让Programmer.h中的函数直接在我的TextBox txtBoxStatus中写入消息。通过使txtBoxStatus公开,我能够在Programmer.h中的函数中编写MyForm::txtBoxStatus
,但是一旦我这样做,我会收到错误说&#34;非静态成员引用必须相对于特定对象&#34;。
此时我没有成功尝试让它发挥作用。完整的项目可以在GitHub上PSoC Programmer
查看提前感谢您的帮助!