sample05

LINK オプションで コンソールの出現を抑える


cat sample05.cpp
// sample04.cpp
// add a button with click handler and also add a textbox
#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;

ref class MyForm : public Form
{
public:
    MyForm();
    Label ^m_label;
    Button ^btn;
    TextBox ^txt1;
    void btn_Click(Object ^sender, System::EventArgs^ e);
};

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    Application::Run(gcnew MyForm()); // message loop
    return 0;
}

MyForm ::MyForm()
{
    //set some form properties/fields
    this->Text = "sample05";
    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=sample05

all: $(TARGET).exe

.PHONY: all test mmm clean
.SUFFIXES: .obj
LOPT=-ENTRY:main -SUBSYSTEM:WINDOWS

OBJS=$(TARGET).obj

$(TARGET).obj: $(TARGET).cpp

$(TARGET).exe: $(OBJS)
        link $(LOPT) $(OBJS)

.cpp.obj:
        cl -c -Wall -Od -clr $<

test:
        ./$(TARGET).exe &

clean:
        -rm $(TARGET).exe *.obj *~

mmm:
        cat $(TARGET).cpp
        @echo
        cat makefile

html:
        cat /dev/clipboard | code2html.exe | unix2dos