program ToniCounter;
uses
SysUtils, DateUtils, Windows, Messages;
const
{ Fensterklassennamen und Fenstername. }
WindowClassName = '
Toni Returns!';
WindowName = '
Toni Returns!';
{ Fenstergröße, sollte eigendlich so ausreichen. }
WindowWidth : LongWord = 400;
WindowHeight : LongWord = 50;
{ Datum der Rückkehr oder what ever. }
ReturnDate = 0;
// Anpassen
var
ScreenX, ScreenY, TaskbarHeight : LongWord;
WindowClassEx : TWndClassEx;
Window, TaskbarWnd : HWnd;
Msg : TMsg;
TaskbarRect, WindowRect : TRect;
PaintThreadHandle : THandle;
PaintThreadID : LongWord;
szTime : PChar;
function PaintThread(Param : Pointer) : LongWord;
stdcall;
begin
while true
do
begin
StrPCopy(szTime, '
Hallo Welt! ' + TimeToStr(now));
//RedrawWindow(Window, nil, 0, RDW_INVALIDATE or RDW_ERASE); // so klappts nun auch
InvalidateRect(Window,
nil, True);
Sleep(1000);
end;
ExitThread(0);
end;
procedure Abort(Msg : PChar);
begin
MessageBox(0, Msg, WindowName, MB_ICONERROR
or MB_OK);
ExitProcess(0);
end;
function WindowProc(Window : HWnd; Msg: LongWord; wParam, lParam: LongInt) : LongInt;
stdcall;
var
PaintInfo : TPaintStruct;
begin
Result := 0;
case Msg
of
WM_CREATE:
begin
GetMem(szTime, 1024);
{ Thread fürs Zeichnen starten. }
PaintThreadHandle := CreateThread(
nil, 0, @PaintThread,
nil, 0, PaintThreadID);
//<--<<
if PaintThreadHandle = 0
then
Abort('
Der ZeichnenThread konnte nicht erstellt werden.');
end;
WM_DESTROY:
begin
if PaintThreadHandle <> 0
then
TerminateThread(PaintThreadHandle, 0);
FreeMem(szTime);
PostQuitMessage(0);
end;
WM_CLOSE:
begin
DestroyWindow(Window);
end;
WM_PAINT:
begin
BeginPaint(Window, PaintInfo);
SetTextColor(PaintInfo.hdc, $00000000);
SetBKMode(PaintInfo.hdc, TRANSPARENT);
SetTextColor(PaintInfo.hdc,
RGB(255, 255, 255));
//DrawText(PaintInfo.hdc, @TimeString[1], Length(TimeString), WindowRect, DT_SINGLELINE or DT_CENTER or DT_VCENTER);
DrawText(PaintInfo.hdc, szTime, Length(szTime), WindowRect, DT_SINGLELINE
or DT_CENTER
or DT_VCENTER);
EndPaint(Window, PaintInfo);
end;
else Result := DefWindowProc(Window, Msg, wParam, lParam);
end;
end;
begin
{ Bildschirmgröße ermitteln, die brauchen wir um das Fenster zu positionieren. }
ScreenX := GetSystemMetrics(SM_CXSCREEN);
ScreenY := GetSystemMetrics(SM_CYSCREEN);
{ Hohe der Taskbar ermitteln. }
TaskbarWnd := FindWindow('
Shell_TrayWnd',
nil);
TaskbarHeight := 0;
if TaskbarWnd <> 0
then begin
GetWindowRect(TaskbarWnd, TaskbarRect);
TaskbarHeight := TaskbarRect.Bottom - TaskbarRect.Top;
end else Abort('
Das TaskbarFenster konnte nicht ermittelt werden!');
{ Fensterklasse erstellen. }
ZeroMemory(@WindowClassEx, SizeOf(TWndClassEx));
With WindowClassEx
do
begin
cbSize := SizeOf(TWndClassEx);
Style := CS_HREDRAW
or CS_VREDRAW;
lpfnWndProc := @WindowProc;
cbClsExtra := 0;
cbWndExtra := 0;
lpszMenuName :=
nil;
lpszClassName := WindowClassName;
hIconSm := 0;
hInstance := hInstance;
hIcon := LoadIcon(0, IDI_APPLICATION);
hCursor := LoadCursor(0, IDC_ARROW);
hbrBackground := GetStockObject(GRAY_BRUSH);
end;
if RegisterClassEx(WindowClassEx) = 0
then Abort('
Fensterklasse konnte nicht erstellt werden!');
{ Fenster erstellen. }
Window := CreateWindowEx(
WS_EX_TOPMOST
or WS_EX_TOOLWINDOW,
// <--<<
WindowClassName,
WindowName,
WS_POPUP
or WS_SYSMENU,
ScreenX - WindowWidth,
ScreenY - WindowHeight - TaskbarHeight,
WindowWidth,
WindowHeight,
0,
0,
hInstance,
nil);
if Window = 0
then Abort('
Das Fenster konnte nicht erstellt werden.');
GetClientRect(Window, WindowRect);
{ Fenster anzeigen. }
ShowWindow(Window, CmdShow);
UpdateWindow(Window);
{ Messages abarbeiten. }
while GetMessage(Msg, 0, 0, 0)
do begin
{ Übersetzen ... }
TranslateMessage(Msg);
{ und verteilen. }
DispatchMessage(Msg);
end;
UnregisterClass(WindowClassName, hInstance);
end.