{******************************************************************************}
{ }
{ 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,SysUtils,Graphics,draw,functions;
const
ClassName = '
WndClass';
AppName = '
Fenster-Vorlage';
WindowWidth = 800;
WindowHeight = 600;
timebase = 1;
var
hwndMain: DWORD;
dc : HDC;
//DeviceContext für ausgabe
dcdbl : HDC;
//DeviceContext für DBL
dbl : HBITMAP;
//Speicher für DBL
hbrBkgnd:HBRUSH;
crBkgnd:COLORREF;
{ 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);
WM_KEYDOWN:
begin;
case wparam
of VK_ESCAPE: sendmessage(hwnd,WM_CLOSE,0,0);
end;
end;
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;
lpszMenuName :
nil;
lpszClassName : ClassName;
hIconSm : 0;
);
msg: TMsg;
zeit1,zeit2:longword;
begin
wc.hInstance := hInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.hbrBackground := GetStockObject(BLACK_BRUSH);
RegisterClassEx(wc);
hwndMain := CreateWindowEx(0, ClassName, AppName,WS_POPUP
or WS_VISIBLE,
0,0, WindowWidth, WindowHeight, 0,
0, hInstance,
nil);
{ Doublebuffer erstellen }
dc := GetDC(hwndmain);
dcdbl := CreateCompatibleDC(
dc);
dbl := CreateCompatibleBitmap(
dc,WindowWidth,Windowheight);
SelectObject(dcdbl,dbl);
setbkcolor(
dc,
RGB(0,0,0));
showcursor(false);
while true
do
begin
if peekMessage(msg, 0, 0, 0,PM_REMOVE)
then begin;
//Wenn überhaupt Message da ist
if msg.
Message = WM_QUIT
then Break;
TranslateMessage(msg);
DispatchMessage(msg);
end;
//Hauptfunktion aufrufen
//Nur alle timebase aufrufen
zeit1 := gettime;
if (zeit1 > zeit2+timebase)
then begin;
erasedc(
dc,WindowWidth,Windowheight);
maindraw(dcdbl,windowWidth,Windowheight);
//Doublebuffer auf den Bidlschirm blitten
BitBlt(
dc,0,0,WindowWidth,Windowheight,dcdbl,0,0,SRCPAINT);
end;
end;
showcursor(true);
DeleteObject(dbl);
DeleteDC(dcdbl);
DeleteDC(
dc);
ExitCode := msg.wParam;
end.