Timer



cat timer_test.cpp
// timer_test.cpp

#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;

#include "timer_test.h"
#include "myApp.h"

[STAThreadAttribute]
int main(array<System::String ^> ^args){
	Application::Run(gcnew myApp()); // message loop
	return EXIT_SUCCESS;
}
cat myApp.h
// myApp.h

#pragma once
ref class myApp : public Form {
public:
	myApp();		//constructor
//	~myApp();		//destructor
//	!myApp();		//finalizer
//

private:
	System::Windows::Forms::Timer^ timer1;
	System::ComponentModel::IContainer^ components;
	System::Windows::Forms::Label^ label1;
	void InitializeComponent(void);
	void timer1_Tick(Object^ sender, System::EventArgs^ e);

};		//semi-colon
cat myApp.cpp
// myApp.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 "timer_test.h"
#include "myApp.h"

//	myApp::~myApp(){}		//destructor
//	myApp::!myApp(){}		//finalizer
myApp::myApp(){		//constructor
	// set some form properties/fields
	this->InitializeComponent();


}
void myApp::InitializeComponent(void){
	this->components = gcnew System::ComponentModel::Container();
	this->timer1 = gcnew System::Windows::Forms::Timer(this->components);
	this->label1 = gcnew System::Windows::Forms::Label();

// timer1
	this->timer1->Enabled = true;
	this->timer1->Interval = 5000;
	this->timer1->Tick += gcnew System::EventHandler(this,&myApp::timer1_Tick);

// label1
	this->label1->Location = System::Drawing::Point(184, 16);
	this->label1->Name = "label1";
	this->label1->Size = System::Drawing::Size(400, 16);
	this->label1->Text = "0";
	this->Controls->Add(label1);
	
// Form
	this->Text = "timer_test";
	this->FormBorderStyle=::FormBorderStyle::Fixed3D;
	this->MaximizeBox=false;
	this->ClientSize=System::Drawing::Size(640,480);
}

void myApp::timer1_Tick(Object^ sender, System::EventArgs^ e)
{
//	MessageBox::Show(System::DateTime::Now.ToString());
	this->label1->Text=System::DateTime::Now.ToString();
}
cat AssemblyInfo.cpp
// AssemblyInfo.cpp
//
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
	
//
// General Assembly Information
//
[assembly:AssemblyCompanyAttribute("smnb")];
[assembly:AssemblyCopyrightAttribute("Copyright smnb(c)  2007")];
[assembly:AssemblyTrademarkAttribute("smnb")];

[assembly:AssemblyProductAttribute("AssemblyInfo_test")];
[assembly: AssemblyFileVersion ("2.1.1852.0")];
[assembly: AssemblyInformationalVersion("1.2")] ; // Win32 version visible in Property

[assembly:AssemblyTitleAttribute("AssemblyInfo_test")];
[assembly:AssemblyDescriptionAttribute("This is a test.")];

	// Assembly Version  (Major Version).(Minor Version).(Build Number).(Revision)
//[assembly:AssemblyVersionAttribute("1.0.*")]; // Build and Revision are using default.
// Build will be number of days since 2000/1/1
// Revision will be half of number of seconds since midnight of the day.
// ... doesn't work outside Visual Studio probably..
[assembly:AssemblyVersionAttribute("1.0.1.0")]; // Build and Revision are using default.
[assembly:AssemblyConfigurationAttribute("Release")]; // or debug
[assembly:AssemblyCultureAttribute("")]; // don't define this for main assembly

[assembly:ComVisible(false)]; // COM can't refer types in this Assembly

[assembly:CLSCompliantAttribute(true)];// Class marked as CLS compliant.

// study http://www.microsoft.com/japan/msdn/security/guidance/secmod81.mspx
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];

cat makefile
# makefile for timer_test

.PHONY: all test mmm clean 
.SUFFIXES: .exe .obj .txt .resources .dll

TARGET=timer_test

CULTUREDIRS=
DLLS=

all: $(TARGET).exe $(DLLS)


LOPT=-ENTRY:main -SUBSYSTEM:WINDOWS

OBJS=$(TARGET).obj myApp.obj AssemblyInfo.obj

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

myApp.obj: myApp.cpp myApp.h


AssemblyInfo.obj: AssemblyInfo.cpp

meta: $(TARGET).exe
	ILDasm /out:$@ /metadata $<

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

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

test: $(TARGET).exe
	./$(TARGET).exe &

clean:
	@-rm $(TARGET).exe *.obj *~ $(TARGET).exe.manifest 1>/dev/null 2>&1
	@-rm *.resources 1>/dev/null 2>&1
	@-rm -fr $(CULTUREDIRS)

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

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

install: $(TARGET).exe
	cp $(TARGET).exe ~/bin
	cp $(TARGET).exe.manifest ~/bin