{******************************************************************************}
{ }
{ Fenster-Vorlage }
{ }
{ Copyright (c) 2002 Michael Puff }
{ [url]www.luckie-online.de[/url] }
{ [email]mpuff@luckie-online.de[/email] }
{ }
{******************************************************************************}
program Fenster_Vorlage;
uses
Windows,
Messages;
const
ClassName = '
WndClass';
AppName = '
Fenster-Vorlage';
WindowWidth = 500;
WindowHeight = 350;
var
hwndMain: DWORD;
{ GetLastError }
function DisplayErrorMsg(hWnd: THandle): DWORD;
var
szBuffer:
array[0..255]
of Char;
begin
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
nil, GetLastError, 0, szBuffer,
sizeof(szBuffer),
nil);
MessageBox(hWnd, szBuffer, '
Fehler', MB_ICONSTOP);
result := GetLastError;
end;
function WndProc(hWnd: HWND; uMsg: UINT; wParam: wParam; lParam: LParam):
lresult;
stdcall;
var
x, y : integer;
begin
Result := 0;
case uMsg
of
WM_CREATE:
begin
{ Fenster zentrieren }
x := GetSystemMetrics(SM_CXSCREEN);
y := GetSystemMetrics(SM_CYSCREEN);
MoveWindow(hWnd, (x
div 2) - (WindowWidth
div 2),
(y
div 2) - (WindowHeight
div 2),
WindowWidth, WindowHeight, true);
end;
WM_DESTROY: PostQuitMessage(0);
else
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
end;
end;
var
wc: TWndClassEx = (
cbSize : SizeOf(TWndClassEx);
Style : CS_HREDRAW
or CS_VREDRAW;
lpfnWndProc : @WndProc;
cbClsExtra : 0;
cbWndExtra : 0;
hbrBackground : COLOR_APPWORKSPACE;
lpszMenuName :
nil;
lpszClassName : ClassName;
hIconSm : 0;
);
msg: TMsg;
begin
wc.hInstance := hInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, IDC_ARROW);
RegisterClassEx(wc);
hwndMain := CreateWindowEx(0, ClassName, AppName, WS_CAPTION
or WS_VISIBLE
or
WS_SYSMENU
or WS_MINIMIZEBOX
or WS_MAXIMIZEBOX
or WS_SIZEBOX,
Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT), WindowWidth, WindowHeight, 0,
0, hInstance,
nil);
while true
do
begin
if not GetMessage(msg, 0, 0, 0)
then
break;
TranslateMessage(msg);
DispatchMessage(msg);
end;
ExitCode := msg.wParam;
end.