I have created a new windows form application and made a form using the editor in visual studio. This is the code that was generated in form1.h:
#pragma once
namespace DatabaseForm {
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
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </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::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::RichTextBox^ richTextBox1;
private: System::Windows::Forms::Button^ button2;
protected:
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->button1 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(12, 231);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"Save";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this,
&Form1:: button1_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(12, 205);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 1;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(12, 163);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(100, 20);
this->textBox2->TabIndex = 2;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(12, 124);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(100, 20);
this->textBox3->TabIndex = 3;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(13, 186);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 4;
this->label1->Text = L"label1";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(13, 147);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(35, 13);
this->label2->TabIndex = 5;
this->label2->Text = L"label2";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(13, 108);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(35, 13);
this->label3->TabIndex = 6;
this->label3->Text = L"label3";
//
// richTextBox1
//
this->richTextBox1->Location = System::Drawing::Point(118, 12);
this->richTextBox1->Name = L"richTextBox1";
this->richTextBox1->Size = System::Drawing::Size(162, 242);
this->richTextBox1->TabIndex = 7;
this->richTextBox1->Text = L"";
//
// button2
//
this->button2->Location = System::Drawing::Point(16, 12);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 8;
this->button2->Text = L"Load DataBase";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->button2);
this->Controls->Add(this->richTextBox1);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
I have created a simple win32 console program that adds structs to a file and prints the entire struct to the screen. These are the two functions im using to do this:
struct Station{
string url;
string name;
string genre;
}temp;
string output;
void addStation(){
fstream file;
file.open("database.txt", ios::binary|ios::in|ios::out|ios::beg);
file.seekp(0, ios::end);
getline(cin, output);
temp.url = output.c_str();
getline(cin, output);
temp.name = output.c_str();
getline(cin, output);
temp.genre = output.c_str();
file.write((char*)&temp, sizeof(temp));
file.close();
};
void viewDataBase(){
fstream file;
file.open("database.txt", ios::binary|ios::in|ios::out|ios::beg);
file.seekg(0, ios::end);
fileSize = file.tellg();
file.seekg(0, ios::beg);
index = 0;
do{
cout<<"---------"<<endl;
cout<<index<<endl;
file.read((char*)&temp, sizeof(temp));
cout<<temp.url<<endl;
cout<<temp.name<<endl;
cout<<temp.genre<<endl;
index++;
}while(fileSize != file.tellg());
getch();
file.close();
};
what i want to do is have the user enter the struct information in the text boxes and then have this struct be saved to a file when button1 is pressed. When button2 is pressed, i want all of the structs in the file to be printed in richtextbox1. If anyone can tell me how i would do this it would be much appreciated, although any advice on websites or books that could help me would be better. I have found a lot of sites, but most are in c# and i just can't work out how the examples convert into c++.