I have a project I'm working on in Visual Studio 2010 Express in C++/CLI (An explanation of CLI would also be appreciated) and I am stuck on the following error:
error C2061: syntax error : identifier 'FormOutOfTime'
Here is my code:
Runner.cpp
#include "stdafx.h"
#include "Runner.h"
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"
//Variable Dclaration
Runner::Runner()
{
// Do stuff if you need to
this->Go();
}
Runner::~Runner()
{
// Clear memory if you need to
}
void Runner::Go()
{
System::Windows::Forms::Form^ formOutOfTime;//*************************Uncomment Me Later!
formOutOfTime = gcnew FormOutOfTime();
formOutOfTime->ShowDialog();
}
FormOutOfTime.h (there is nothing really in the cpp file for this one, I'm not sure what the difference between putting stuff in the header and cpp files)
#include "FormParentalOverride.h"
#pragma once
namespace PurpleHealth {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for FormOutOfTime
/// </summary>
public ref class FormOutOfTime : public System::Windows::Forms::Form
{
public:
FormOutOfTime(void)
{
InitializeComponent();
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~FormOutOfTime()
{
if (components)
{
delete components;
}
}
protected:
private: System::Windows::Forms::Button^ btnOverride;
private: System::Windows::Forms::Button^ btnUploadData;
private: System::Windows::Forms::Button^ btnLogout;
private: System::Windows::Forms::Label^ lblPurpleHealth;
private: System::Windows::Forms::Label^ lblTimeLeft;
private: System::Windows::Forms::OpenFileDialog^ openHeartRateFile;
private: System::ComponentModel::IContainer^ components;
private: System::Windows::Forms::Form^ formParentalOverride;
private:
/// <summary>
/// Required designer variable.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(FormOutOfTime::typeid));
this->btnOverride = (gcnew System::Windows::Forms::Button());
this->btnUploadData = (gcnew System::Windows::Forms::Button());
this->btnLogout = (gcnew System::Windows::Forms::Button());
this->lblPurpleHealth = (gcnew System::Windows::Forms::Label());
this->lblTimeLeft = (gcnew System::Windows::Forms::Label());
this->openHeartRateFile = (gcnew System::Windows::Forms::OpenFileDialog());
this->SuspendLayout();
//
// btnOverride
//
this->btnOverride->BackColor = System::Drawing::Color::White;
this->btnOverride->Location = System::Drawing::Point(692, 458);
this->btnOverride->Name = L"btnOverride";
this->btnOverride->Size = System::Drawing::Size(218, 66);
this->btnOverride->TabIndex = 5;
this->btnOverride->Text = L"Parental Override";
this->btnOverride->UseVisualStyleBackColor = false;
this->btnOverride->Click += gcnew System::EventHandler(this, &FormOutOfTime::btnOverride_Click);
//
// btnUploadData
//
this->btnUploadData->BackColor = System::Drawing::Color::White;
this->btnUploadData->Location = System::Drawing::Point(449, 458);
this->btnUploadData->Name = L"btnUploadData";
this->btnUploadData->Size = System::Drawing::Size(218, 66);
this->btnUploadData->TabIndex = 6;
this->btnUploadData->Text = L"Upload Data";
this->btnUploadData->UseVisualStyleBackColor = false;
this->btnUploadData->Click += gcnew System::EventHandler(this, &FormOutOfTime::btnAddTime_Click);
//
// btnLogout
//
this->btnLogout->BackColor = System::Drawing::Color::White;
this->btnLogout->Location = System::Drawing::Point(933, 458);
this->btnLogout->Name = L"btnLogout";
this->btnLogout->Size = System::Drawing::Size(218, 66);
this->btnLogout->TabIndex = 7;
this->btnLogout->Text = L"Logout";
this->btnLogout->UseVisualStyleBackColor = false;
this->btnLogout->Click += gcnew System::EventHandler(this, &FormOutOfTime::btnLogout_Click);
//
// lblPurpleHealth
//
this->lblPurpleHealth->AutoSize = true;
this->lblPurpleHealth->BackColor = System::Drawing::Color::White;
this->lblPurpleHealth->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
this->lblPurpleHealth->Location = System::Drawing::Point(699, 377);
this->lblPurpleHealth->Name = L"lblPurpleHealth";
this->lblPurpleHealth->Size = System::Drawing::Size(203, 31);
this->lblPurpleHealth->TabIndex = 8;
this->lblPurpleHealth->Text = L"Balife Bracelets";
//
// lblTimeLeft
//
this->lblTimeLeft->AutoSize = true;
this->lblTimeLeft->BackColor = System::Drawing::Color::White;
this->lblTimeLeft->Location = System::Drawing::Point(576, 427);
this->lblTimeLeft->Name = L"lblTimeLeft";
this->lblTimeLeft->Size = System::Drawing::Size(449, 13);
this->lblTimeLeft->TabIndex = 9;
this->lblTimeLeft->Text = L"You currently have no time left. Wait until tomorrow, or upload heart rate data t"
L"o get more time.";
this->lblTimeLeft->Click += gcnew System::EventHandler(this, &FormOutOfTime::lblTimeLeft_Click);
//
// openHeartRateFile
//
this->openHeartRateFile->Title = L"Locate the file Containing Heart Rate Data";
this->openHeartRateFile->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &FormOutOfTime::openFileDialog1_FileOk);
//
// FormOutOfTime
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"$this.BackgroundImage")));
this->ClientSize = System::Drawing::Size(1600, 900);
this->Controls->Add(this->lblPurpleHealth);
this->Controls->Add(this->lblTimeLeft);
this->Controls->Add(this->btnLogout);
this->Controls->Add(this->btnUploadData);
this->Controls->Add(this->btnOverride);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
this->Name = L"FormOutOfTime";
this->RightToLeftLayout = true;
this->Text = L"FormOutOfTime";
this->TopMost = true;
this->WindowState = System::Windows::Forms::FormWindowState::Maximized;
this->Load += gcnew System::EventHandler(this, &FormOutOfTime::FormOutOfTime_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void openFileDialog1_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
}
private: System::Void FormOutOfTime_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void btnOverride_Click(System::Object^ sender, System::EventArgs^ e) {
formParentalOverride = gcnew FormParentalOverride;
formParentalOverride->ShowDialog();
}
private: System::Void btnLogout_Click(System::Object^ sender, System::EventArgs^ e) {
//ExitWindows(0, 0);
}
private: void btnAddTime_Click(System::Object ^ sender, System::EventArgs ^ e)
{
openHeartRateFile->ShowDialog();
}
private: System::Void lblTimeLeft_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
Any help at all is appreciated!
You forgot to define the namespace. Use it this way:
formOutOfTime = gcnew PurpleHealth::FormOutOfTime();
Related
I'm having a hard time searching for why I'm getting this erorr. I am working on a CLR UI windows form application using C++ on visual studios.
If I try to do
private: int valueInSquare[9];
I get an error saying " a member of a managed class cannot be a standard array"
If I change it to
private: array<int>^valueInSquare;
I get an erorr when trying to view the header file design for my form that says,
C++ CodeDOM parser error: Line: 94, Column: 24 --- Unknown type 'array^'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
Here is a portion of the code since a lot of was pre-generated by using the designer on my header file.
#pragma once
#include "Windows.h"
namespace MagicSquare {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MagicSquare
/// </summary>
public ref class MagicSquare : public System::Windows::Forms::Form
{
public:
MagicSquare(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MagicSquare()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::Label^ label9;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::TextBox^ textBox6;
private: System::Windows::Forms::TextBox^ textBox7;
private: System::Windows::Forms::TextBox^ textBox8;
private: System::Windows::Forms::TextBox^ textBox9;
private: array<int>valueInSquare;
//private: int valueInSquare[9];
private: bool valueAlreadyUsed;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->label8 = (gcnew System::Windows::Forms::Label());
this->label9 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->textBox5 = (gcnew System::Windows::Forms::TextBox());
this->textBox6 = (gcnew System::Windows::Forms::TextBox());
this->textBox7 = (gcnew System::Windows::Forms::TextBox());
this->textBox8 = (gcnew System::Windows::Forms::TextBox());
this->textBox9 = (gcnew System::Windows::Forms::TextBox());
this->valueInSquare = gcnew array<int>(9);
for (int i = 0; i < 9; i++) {
valueInSquare[i] = 10;
}
this->SuspendLayout();
//
// label1
//
this->label1->BackColor = System::Drawing::Color::Blue;
this->label1->Location = System::Drawing::Point(65, 63);
this->label1->Name = "1";
this->label1->Size = System::Drawing::Size(65, 65);
this->label1->TabIndex = 0;
this->label1->Text = L"label1";
this->label1->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label2
//
this->label2->BackColor = System::Drawing::Color::Blue;
this->label2->Location = System::Drawing::Point(218, 63);
this->label2->Name = "2";
this->label2->Size = System::Drawing::Size(65, 65);
this->label2->TabIndex = 1;
this->label2->Text = L"label2";
this->label2->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
//
// label3
//
this->label3->BackColor = System::Drawing::Color::Blue;
this->label3->Location = System::Drawing::Point(383, 63);
this->label3->Name = "3";
this->label3->Size = System::Drawing::Size(65, 65);
this->label3->TabIndex = 2;
this->label3->Text = L"label3";
this->label3->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label4
//
this->label4->BackColor = System::Drawing::Color::Blue;
this->label4->Location = System::Drawing::Point(65, 153);
this->label4->Name = "4";
this->label4->Size = System::Drawing::Size(65, 65);
this->label4->TabIndex = 3;
this->label4->Text = L"label4";
this->label4->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label5
//
this->label5->BackColor = System::Drawing::Color::Blue;
this->label5->Location = System::Drawing::Point(218, 153);
this->label5->Name = "5";
this->label5->Size = System::Drawing::Size(65, 65);
this->label5->TabIndex = 4;
this->label5->Text = L"label5";
this->label5->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label6
//
this->label6->BackColor = System::Drawing::Color::Blue;
this->label6->Location = System::Drawing::Point(383, 153);
this->label6->Name = "6";
this->label6->Size = System::Drawing::Size(65, 65);
this->label6->TabIndex = 5;
this->label6->Text = L"label6";
this->label6->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label7
//
this->label7->BackColor = System::Drawing::Color::Blue;
this->label7->Location = System::Drawing::Point(65, 242);
this->label7->Name = "7";
this->label7->Size = System::Drawing::Size(65, 65);
this->label7->TabIndex = 6;
this->label7->Text = L"label7";
this->label7->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label8
//
this->label8->BackColor = System::Drawing::Color::Blue;
this->label8->Location = System::Drawing::Point(218, 242);
this->label8->Name = "8";
this->label8->Size = System::Drawing::Size(65, 65);
this->label8->TabIndex = 7;
this->label8->Text = L"label8";
this->label8->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label9
//
this->label9->BackColor = System::Drawing::Color::Blue;
this->label9->Location = System::Drawing::Point(383, 242);
this->label9->Name = "9";
this->label9->Size = System::Drawing::Size(65, 65);
this->label9->TabIndex = 8;
this->label9->Text = L"label9";
this->label9->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(65, 84);
this->textBox1->Name = "1";
this->textBox1->Size = System::Drawing::Size(65, 20);
this->textBox1->TabIndex = 9;
this->textBox1->Visible = false;
this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MagicSquare::MagicSquare::textBoxOnKeyPressed);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(218, 84);
this->textBox2->Name = "2";
this->textBox2->Size = System::Drawing::Size(65, 20);
this->textBox2->TabIndex = 10;
this->textBox2->Visible = false;
this->textBox2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MagicSquare::MagicSquare::textBoxOnKeyPressed);
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(383, 84);
this->textBox3->Name = "3";
this->textBox3->Size = System::Drawing::Size(65, 20);
this->textBox3->TabIndex = 11;
this->textBox3->Visible = false;
this->textBox3->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MagicSquare::MagicSquare::textBoxOnKeyPressed);
//
// textBox4
//
You may have a name conflict on the identifier array. Try using its fully-qualified name cli::array, to avoid ambiguity with std::array and other usages of the name.
I'm working on a C++/CLI project and I'm new in it.In my project I have 2 forms, one is mainpage and the other one is Loginpage.
I want to have an event that when it logins successfully in the Loginpage, starts to get some jpeg pictures from the server.
I have defined the delegate, event and the method for it as below. It compiles completely and runs, but when the event is fired, it doesn't run the method.
I don't find an answer for it. I was wondering if you could help me?
MainPage.h:
#pragma once
#include "IPPort.h"
#include "Login.h"
#include "stdafx.h"
#include "Utils.h"
namespace UIv10 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class MainPage : public System::Windows::Forms::Form
{
public:
MainPage(void)
{
InitializeComponent();
Login ^ loginpage = gcnew Login();
loginpage->JPEGgenerate += gcnew UIv10::Login::JPEGgeneratorEventHandler(this, &MainPage::OnJPEGgenerate);
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MainPage()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ connectToolStripMenuItem;
private: System::Windows::Forms::ToolStrip^ toolStrip1;
private: System::Windows::Forms::ToolStripButton^ toolStripButton1;
private: System::Windows::Forms::PictureBox^ pictureBox1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainPage::typeid));
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->connectToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
this->toolStripButton1 = (gcnew System::Windows::Forms::ToolStripButton());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->menuStrip1->SuspendLayout();
this->toolStrip1->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->fileToolStripMenuItem });
resources->ApplyResources(this->menuStrip1, L"menuStrip1");
this->menuStrip1->Name = L"menuStrip1";
//
// fileToolStripMenuItem
//
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->connectToolStripMenuItem });
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
resources->ApplyResources(this->fileToolStripMenuItem, L"fileToolStripMenuItem");
//
// connectToolStripMenuItem
//
this->connectToolStripMenuItem->Name = L"connectToolStripMenuItem";
resources->ApplyResources(this->connectToolStripMenuItem, L"connectToolStripMenuItem");
this->connectToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainPage::connectToolStripMenuItem_Click);
//
// toolStrip1
//
this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->toolStripButton1 });
resources->ApplyResources(this->toolStrip1, L"toolStrip1");
this->toolStrip1->Name = L"toolStrip1";
//
// toolStripButton1
//
resources->ApplyResources(this->toolStripButton1, L"toolStripButton1");
this->toolStripButton1->Name = L"toolStripButton1";
this->toolStripButton1->Click += gcnew System::EventHandler(this, &MainPage::toolStripButton1_Click);
//
// pictureBox1
//
resources->ApplyResources(this->pictureBox1, L"pictureBox1");
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->TabStop = false;
//
// MainPage
//
resources->ApplyResources(this, L"$this");
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->toolStrip1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"MainPage";
this->WindowState = System::Windows::Forms::FormWindowState::Maximized;
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->toolStrip1->ResumeLayout(false);
this->toolStrip1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void toolStripButton1_Click(System::Object^ sender, System::EventArgs^ e) {
IPPort ^ ipportpage = gcnew IPPort();
ipportpage->Show();
}
private: System::Void connectToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
/*IPPort ^ ipportpage = gcnew IPPort();
ipportpage->Show();*/
Login^ L = gcnew Login();
L->Show();
}
void OnJPEGgenerate(System::Object^ sender,System::EventArgs^ e);
};
}
void UIv10::MainPage::OnJPEGgenerate(System::Object^ sender,System::EventArgs^ e)
{
MessageBoxA(NULL, "Failed to Login", "Attention", MB_OK);
throw gcnew System::NotImplementedException();
}
Login.h:
#include <msclr/marshal.h>
#include <Windows.h>
#ifndef Login_h
#define Login_h
bool FLogin(char use[128], char pass[64]);
#pragma once
namespace UIv10 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Login : public System::Windows::Forms::Form
{
public: delegate void JPEGgeneratorEventHandler(System::Object^ sender, EventArgs^ e);
public: event JPEGgeneratorEventHandler^ JPEGgenerate;
public:
Login(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Login()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ btnCancel2;
private: System::Windows::Forms::Button^ btnLogin;
private: System::Windows::Forms::TextBox^ txtbPassword;
private: System::Windows::Forms::TextBox^ txtbUserName;
private: System::Windows::Forms::Label^ lblPassword;
private: System::Windows::Forms::Label^ lblUserName;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->btnCancel2 = (gcnew System::Windows::Forms::Button());
this->btnLogin = (gcnew System::Windows::Forms::Button());
this->txtbPassword = (gcnew System::Windows::Forms::TextBox());
this->txtbUserName = (gcnew System::Windows::Forms::TextBox());
this->lblPassword = (gcnew System::Windows::Forms::Label());
this->lblUserName = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// btnCancel2
//
this->btnCancel2->Location = System::Drawing::Point(158, 174);
this->btnCancel2->Name = L"btnCancel2";
this->btnCancel2->Size = System::Drawing::Size(71, 23);
this->btnCancel2->TabIndex = 11;
this->btnCancel2->Text = L"Cancel";
this->btnCancel2->UseVisualStyleBackColor = true;
//
// btnLogin
//
this->btnLogin->Location = System::Drawing::Point(61, 174);
this->btnLogin->Name = L"btnLogin";
this->btnLogin->Size = System::Drawing::Size(71, 23);
this->btnLogin->TabIndex = 10;
this->btnLogin->Text = L"Login";
this->btnLogin->UseVisualStyleBackColor = true;
this->btnLogin->Click += gcnew System::EventHandler(this, &Login::btnLogin_Click);
//
// txtbPassword
//
this->txtbPassword->Location = System::Drawing::Point(112, 109);
this->txtbPassword->Name = L"txtbPassword";
this->txtbPassword->PasswordChar = '*';
this->txtbPassword->Size = System::Drawing::Size(126, 20);
this->txtbPassword->TabIndex = 9;
this->txtbPassword->Text = L"roseek";
//
// txtbUserName
//
this->txtbUserName->Location = System::Drawing::Point(112, 65);
this->txtbUserName->Name = L"txtbUserName";
this->txtbUserName->Size = System::Drawing::Size(126, 20);
this->txtbUserName->TabIndex = 8;
this->txtbUserName->Text = L"roseek";
//
// lblPassword
//
this->lblPassword->Location = System::Drawing::Point(47, 117);
this->lblPassword->Name = L"lblPassword";
this->lblPassword->Size = System::Drawing::Size(59, 12);
this->lblPassword->TabIndex = 7;
this->lblPassword->Text = L"Password";
//
// lblUserName
//
this->lblUserName->AutoSize = true;
this->lblUserName->Location = System::Drawing::Point(47, 73);
this->lblUserName->Name = L"lblUserName";
this->lblUserName->Size = System::Drawing::Size(60, 13);
this->lblUserName->TabIndex = 6;
this->lblUserName->Text = L"User Name";
//
// Login
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->btnCancel2);
this->Controls->Add(this->btnLogin);
this->Controls->Add(this->txtbPassword);
this->Controls->Add(this->txtbUserName);
this->Controls->Add(this->lblPassword);
this->Controls->Add(this->lblUserName);
this->Name = L"Login";
this->Text = L"Login";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void btnLogin_Click(System::Object^ sender, System::EventArgs^ e) {
String ^ username;
String ^ password;
username = this->txtbUserName->Text;
password = this->txtbPassword->Text;
using namespace System::Runtime::InteropServices;
IntPtr Cusername = Marshal::StringToHGlobalAnsi(username);
char* UserName = static_cast<char*>(Cusername.ToPointer());
IntPtr Cpassword = Marshal::StringToHGlobalAnsi(password);
char* Password = static_cast<char*>(Cpassword.ToPointer());
bool Lret = FLogin(UserName, Password);
if (Lret == TRUE)
{
JPEGgenerate(this,e);
this->Close();
}
else
{
JPEGgenerate(this, e);
MessageBoxA(NULL, "Failed to Login", "Attention", MB_OK);
this->Close();
}
}
};
}
#endif
Sorry for the long codes, I just don't know where the problem may be.
The actuall problem is that when JPEGgenerate(this,e); runs it should run OnJPEGgenerate. But it doesn't.
This code seems wrong for me:
MainPage(void)
{
InitializeComponent();
Login ^ loginpage = gcnew Login();
loginpage->JPEGgenerate += gcnew UIv10::Login::JPEGgeneratorEventHandler(this, &MainPage::OnJPEGgenerate);
}
As I understood you should keep reference to such object, otherwise, it will be deleted (and appropriated handler will not be invoked)
Other piece of code (it will not contain registration of event's handler)
Login^ L = gcnew Login();
L->Show();
I've got the code (using VS2010, C++, Windows Forms Application) below:
#pragma once
#include <cv.h>
#include <highgui.h>
#ifdef _DEBUG
//debug
#pragma comment(lib,"cv210d.lib")
#pragma comment(lib,"cxcore210d.lib")
#pragma comment(lib,"cvaux210d.lib")
#pragma comment(lib,"highgui210d.lib")
#else
//release
#pragma comment(lib,"cv210.lib")
#pragma comment(lib,"cxcore210.lib")
#pragma comment(lib,"cvaux210.lib")
#pragma comment(lib,"highgui210.lib")
#endif
//Global variables
IplImage* src = NULL;
IplImage* hsv = NULL;
IplImage* dst = NULL;
IplImage* v_plane = NULL;
IplImage* h_plane = NULL;
IplImage* s_plane = NULL;
namespace HW4 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::PictureBox^ pictureBox2;
private: System::Windows::Forms::Button^ ExitButton;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
this->ExitButton = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Location = System::Drawing::Point(12, 49);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(255, 212);
this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// pictureBox2
//
this->pictureBox2->Location = System::Drawing::Point(354, 49);
this->pictureBox2->Name = L"pictureBox2";
this->pictureBox2->Size = System::Drawing::Size(255, 212);
this->pictureBox2->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pictureBox2->TabIndex = 1;
this->pictureBox2->TabStop = false;
//
// ExitButton
//
this->ExitButton->Location = System::Drawing::Point(272, 278);
this->ExitButton->Name = L"ExitButton";
this->ExitButton->Size = System::Drawing::Size(64, 31);
this->ExitButton->TabIndex = 2;
this->ExitButton->Text = L"Exit";
this->ExitButton->UseVisualStyleBackColor = true;
this->ExitButton->Click += gcnew System::EventHandler(this, &Form1::ExitButton_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(635, 333);
this->Controls->Add(this->ExitButton);
this->Controls->Add(this->pictureBox2);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
src = cvLoadImage("D:\\Pictures\\hungry.jpg");
dst = cvCreateImage(cvGetSize(src),8,3);
hsv = cvCreateImage(cvGetSize(src),8,3);
h_plane = cvCreateImage(cvGetSize(src),8,1);
s_plane = cvCreateImage(cvGetSize(src),8,1);
v_plane = cvCreateImage(cvGetSize(src),8,1);
cvCvtColor(src,hsv,CV_BGR2HSV);
cvSplit(hsv,h_plane,s_plane,v_plane,0);
cvEqualizeHist(v_plane,v_plane);
cvMerge(h_plane,s_plane,v_plane,0,hsv);
cvCvtColor(hsv,dst,CV_HSV2BGR);
//Before you debug, choose SizeMode property of PictureBoxs = StretchImage.
pictureBox1->Image = gcnew //replacement of cvShowImage
System::Drawing::Bitmap(src->width,src->height,src->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) src->imageData);
pictureBox1->Refresh();
pictureBox2->Image = gcnew //replacement of cvShowImage
System::Drawing::Bitmap(dst->width,dst->height,dst->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) dst->imageData);
pictureBox2->Refresh();
/*cvReleaseImage(&src);
cvReleaseImage(&hsv);
cvReleaseImage(&dst);
cvReleaseImage(&h_plane);
cvReleaseImage(&s_plane);
cvReleaseImage(&v_plane);*/
}
private: System::Void ExitButton_Click(System::Object^ sender, System::EventArgs^ e) {
cvReleaseImage(&src);
cvReleaseImage(&hsv);
cvReleaseImage(&dst);
cvReleaseImage(&h_plane);
cvReleaseImage(&s_plane);
cvReleaseImage(&v_plane);
this->Close();
}
};
}
Consider the part of code:
cvReleaseImage(&src);
cvReleaseImage(&hsv);
cvReleaseImage(&dst);
cvReleaseImage(&h_plane);
cvReleaseImage(&s_plane);
cvReleaseImage(&v_plane);
if i put this part at the end of the Form1_Load, there'll be an error as the following picture:
However, if i put this part in the ExitButton_Click function, it's ok!
i don't know why ? hope someone can give me an explaination ! thanks for your help !^~^
In the following line you are using opencv image buffers and if you fee these buffers in the end of form load function, .net engine could not load image anymore
But if you free the buffer in form exit, it won't care ...
pictureBox1->Image = gcnew ...
The Form-Load event in .Net can be used to allocate resources before the form is loaded and rendered. By freeing the image buffer at the end of the load, you remove the image resource that the form needs to display. Just imagine that there is some internal method that calls your Load() method and then it calls an internal Display() method, which uses data from the Load() method. If you load the data and then release it before the "Display()" method is called, you are freeing memory that is required in the Display() method.
As Roozbeh said, if you put it in the exit, the form is not trying to display anything so it doesn't need that image resource (from the buffer). The exit method is naturally a good place to deallocate things.
I'm a C++-CLI beginner and I have to get familiar with some simple things.
I made a form with 1 label and 1 button.
I want to change the text of the label by clicking on the button and calling some text via a void in another cpp class (changetext.cpp)
Structure:
Form1.h //just a regular form code with 1 label and 1 button handler at the end
#pragma once
namespace ms {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
public:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
public: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ button1;
public:
public:
public:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(313, 140);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"label1";
//
// button1
//
this->button1->Location = System::Drawing::Point(101, 117);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(100, 58);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(467, 262);
this->Controls->Add(this->button1);
this->Controls->Add(this->label1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
public: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
changetext my = new changetext();
my.changeText();
}
};
}
ms.cpp (main) //just creates the form
// ms.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace ms;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
changetext.cpp
#include "stdafx.h"
#include "Form1.h"
int number;
void changeText()
{
number = 5;
Form1.label1->Text=number;
}
I am making a little mistake somewhere and I guess it has to do with header files, I'm used to code in java so headerfiles are not my cup of tea yet.
This is what to do:
Create getter in changetext.cpp
#include "stdafx.h"
#include "Form1.h"
int number = 5;
void getNumber()
{
return number;
}
Create header.h
#pragma once
void getNumber();
Include header.h and edit Form1.h
#pragma once
#include header.h
namespace ms {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
public:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
public: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ button1;
public:
public:
public:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(313, 140);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"label1";
//
// button1
//
this->button1->Location = System::Drawing::Point(101, 117);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(100, 58);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this,&Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(467, 262);
this->Controls->Add(this->button1);
this->Controls->Add(this->label1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
public: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
label1->Text=""+getNumber();
}
};
}
I have two file generated in visual studio c++ 2010 express.
test2.cpp
// test2.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace test2;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
and Form1.h
#pragma once
namespace test2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::WebBrowser^ webBrowser1;
public: System::Windows::Forms::Timer^ timer1;
private:
private: System::ComponentModel::IContainer^ components;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->webBrowser1 = (gcnew System::Windows::Forms::WebBrowser());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->SuspendLayout();
//
// webBrowser1
//
this->webBrowser1->Dock = System::Windows::Forms::DockStyle::Fill;
this->webBrowser1->IsWebBrowserContextMenuEnabled = false;
this->webBrowser1->Location = System::Drawing::Point(0, 0);
this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20);
this->webBrowser1->Name = L"webBrowser1";
this->webBrowser1->ScrollBarsEnabled = false;
this->webBrowser1->Size = System::Drawing::Size(284, 262);
this->webBrowser1->TabIndex = 0;
this->webBrowser1->Url = (gcnew System::Uri(L"http://wp.pl", System::UriKind::Absolute));
this->webBrowser1->DocumentCompleted += gcnew System::Windows::Forms::WebBrowserDocumentCompletedEventHandler(this, &Form1::webBrowser1_DocumentCompleted);
//
// timer1
//
this->timer1->Enabled = true;
this->timer1->Interval = 10000;
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->webBrowser1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
this->Name = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void webBrowser1_DocumentCompleted(System::Object^ sender, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^ e) {
}
public: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
};
}
How to using argument from command prompt? For example how change
this->timer1->Interval = 10000;
on user var? Something like
this->timer1->Interval = time;
You can get a string array containing the command-line arguments by calling Environment::GetCommandLineArgs.