1 Screenshot
2 Source code
/*
* Timer.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.18
#include <sol\ApplicationView.h>
#include <sol\Font.h>
#include <sol\PaintDC.h>
#include <sol/StringConverter.h>
#include <sol/StringT.h>
#include <time.h>
namespace SOL {
class AppView :public ApplicationView {
private:
Font font;
public:
/**
* Constructor
*/
AppView(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name, args)
{
Args ar;
ar.set(XmNheight, (-12)*2);
ar.set(XmNweight, (ulong) FW_BOLD);
ar.set(XmNfaceName, _T("Arial"));
font.create(ar);
addEventHandler(WM_TIMER, this,
(Handler)&AppView::timeout, NULL);
addEventHandler(WM_PAINT, this,
(Handler)&AppView::paint, NULL);
setTimer(1, 1000, NULL);
}
public:
~AppView() {
killTimer(1);
}
private:
long paint(Event& event)
{
time_t ntime;
time(&ntime);
char buffer[128];
sprintf_s(buffer, CountOf(buffer), "%s", ctime(&ntime));
buffer[strlen(buffer)-1] = ZERO;
StringConverter converter;
StringT<TCHAR> tstring;
converter.convert(buffer, tstring);
const TCHAR* string = (const TCHAR*)tstring;
PaintDC pdc(this);
HFONT prev = (HFONT)pdc.select(&font);
pdc.textOut(10, 10, string, strlen(string));
pdc.select(prev);
return 0;
}
private:
long timeout(Event& event)
{
invalidate((RECT*)NULL);
update();
return 0;
}
};
}
//
void Main(int argc, TCHAR** argv)
{
ModuleFileName module(argv[0]);
const TCHAR* name = module.getFileName();
try {
Application applet(name, argc, argv);
Args args;
args.set(XmNwidth, 400);
args.set(XmNheight, 80);
AppView appView(applet, name, args);
appView.realize();
applet.run();
} catch (Exception& ex) {
caught(ex);
} catch (...) {
caught(UnknownException());
}
}
Last modified: 1 Feb 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.