sample06 ... split source code
cat sample06.cpp
// sample06.cpp
// separate MyForm to other file
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Windows::Forms;
#include "MyForm.h"
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
Application::Run(gcnew MyForm()); // message loop
return 0;
}
cat MyForm.h
// MyForm.h
ref class MyForm : public Form
{
public:
MyForm();
Label ^m_label;
Button ^btn;
TextBox ^txt1;
void btn_Click(Object ^sender, System::EventArgs^ e);
};
cat MyForm.cpp
// MyForm.cpp
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Windows::Forms;
#include "MyForm.h"
MyForm ::MyForm()
{
//set some form properties/fields
this->Text = "sample06";
this->FormBorderStyle=::FormBorderStyle::Fixed3D;
this->MaximizeBox=false;
this->ClientSize=System::Drawing::Size(400,300);
//create the Label object and set its properties/fields
m_label=gcnew Label();
m_label->Text="The quick brown fox jumps over the lazy dog.";
m_label->Size=System::Drawing::Size(300,50);
m_label->Location=Point(5,5);
//add the label to the form
this->Controls->Add(m_label);
btn=gcnew Button();
btn->Text="Test Button";
btn->Location=Point(5,90);
btn->Size=System::Drawing::Size(100,22);
btn->Click += gcnew EventHandler( this, &MyForm::btn_Click);
//add the button
this->Controls->Add(btn);
txt1=gcnew TextBox();
txt1->ReadOnly=true;
txt1->Size=System::Drawing::Size(200,22);
txt1->Location=Point(130,90);
//add the text box
this->Controls->Add(txt1);
}
//the event handler for button click
void MyForm::btn_Click(Object ^sender, System::EventArgs ^e)
{
//we show the current date/time in the text box
DateTime dt=System::DateTime::Now;
txt1->Text=dt.ToString();
}
cat makefile
TARGET=sample06
all: $(TARGET).exe
.PHONY: all test mmm clean
.SUFFIXES: .obj
LOPT=-ENTRY:main -SUBSYSTEM:WINDOWS
OBJS=$(TARGET).obj MyForm.obj
$(TARGET).obj: $(TARGET).cpp MyForm.h
MyForm.obj: MyForm.cpp MyForm.h
$(TARGET).exe: $(OBJS)
link $(LOPT) $(OBJS)
.cpp.obj:
cl -c -Wall -Od -clr $<
test: $(TARGET).exe
./$(TARGET).exe &
clean:
-rm $(TARGET).exe *.obj *~ $(TARGET).manifest
mmm:
cat $(TARGET).cpp
cat MyForm.h
cat MyForm.cpp
@echo
cat makefile
html:
cat /dev/clipboard | code2html.exe | unix2dos