(Gast)
n/a Beiträge
|
Speicher (Resource) Problem
24. Okt 2008, 12:57
Hab ein Problem mit meiner Uhr wäre nett wenn mal jemand drüber schaut.
Warum diese immer weiter Daten in den Speicher haut obwohl ich meines erachtens alles freigebe.
Delphi-Quellcode:
function ClockProc(WinHandle: HWND; Msg: UINT; wP: wParam; lP: LParam): LResult;
var
rc, rw: TRect;
lpt: TPoint;
Graphics: cardinal;
Img, imgW, imgH: cardinal;
tx, ty: integer;
ARGB1, ARGB2: COLORREF;
ps: TPaintStruct;
hDCBack: cardinal;
nHH, nMM, nSS, nMS: word;
nAngle: single;
CenterX, CenterY, X, Y: integer;
Pi180: double;
TheTime: TDateTime;
begin
with SkinEngine do
begin
case Msg of
WM_TIMER:
FUpdateWindow(WinHandle, False);
WM_ERASEBKGND:
begin
Result := 1;
Exit;
end;
WM_PAINT, WM_PRINT:
begin
Img := GetProperty(WinHandle, PROP_IMAGE);
ARGB1 := GetProperty(WinHandle, PROP_TEXT_COLOR);
ARGB2 := GetProperty(WinHandle, TRACK_ARGB);
GetClientRect(WinHandle, rc);
if Img <> 0 then
begin
if Msg = WM_PAINT then
begin
nhDC := BeginPaint(WinHandle, ps);
if not Composited then
begin
nhDC := DoubleBuffer(ps.hDC, rc.Right, rc.Bottom, 1);
GetWindowRect(WinHandle, rw);
lpt.x := rw.Left;
lpt.y := rw.Top;
ScreenToClient(Mainwindow(0), lpt);
// BACK_PaintBitmap
hDCBack := CreateCompatibleDC(nhDC);
SelectObject(hDCBack, GetBackBitmap(Mainwindow(0)));
BitBlt(nhDC, 0, 0, rc.Right, rc.Bottom, hDCBack,
lpt.x, lpt.y, SRCCOPY);
DeleteDC(hDCBack);
end;
end else // WM_PRINT
nhDC := wP;
end;
if GdipCreateFromHDC(nhDC, Graphics) = 0 then
begin
Pi180 := 0.0174532925199433;
GetImageSize(Img, imgW, imgH);
tx := (rc.Right - integer(imgW)) div 2;
ty := (rc.Bottom - integer(imgH)) div 2;
TheTime := Time;
DecodeTime(TheTime, nHH, nMM, nSS, nMS);
if nHH > 12 then
nHH := nHH - 12;
GdipSetSmoothingMode(Graphics, 4); // SmoothingModeAntiAlias
GdipDrawImageRectRectI(Graphics, Img,
tx, ty, ImgW, ImgH, 0, 0, ImgW, ImgH, 2, nil, False, nil);
if imgW < imgH then
imgH := imgW;
if imgH < imgW then
imgW := imgH;
CenterX := tx + integer(imgW) div 2;
CenterY := ty + integer(imgH) div 2;
// Zeichne den Stunden Zeiger
if nHH > 12 then
nHH := nHH - 12;
nAngle := (nHH * 30 - 90) + 30 * nMM div 60;
X := CenterX + round(COS(nAngle * Pi180) *
(CenterX - (integer(imgW) div 4)));
Y := CenterY + Round(SIN(nAngle * Pi180) *
(CenterY - (integer(imgW) div 4)));
DrawLine(Graphics, CenterX + 2, CenterY + 2, X + 2, Y + 2,
$40000000, (imgW div 40));
DrawLine(Graphics, CenterX, CenterY, X, Y, ARGB1, (imgW div 40));
// Zeichne Minuten Zeiger
nAngle := (nMM * 6 - 90) + 6 * nSS div 60;
X := CenterX + round(COS(nAngle * Pi180) *
(CenterX - (integer(imgW) div 5)));
Y := CenterY + round(SIN(nAngle * Pi180) *
(CenterY - (integer(imgW) div 5)));
DrawLine(Graphics, CenterX + 2, CenterY + 2, X + 2, Y + 2,
$40000000, (imgW div 40));
DrawLine(Graphics, CenterX, CenterY, X, Y, ARGB1, (imgW div 40));
// Zeichne Sekunden Zeiger
nAngle := (nSS * 6 - 90);
X := CenterX + round(COS(nAngle * Pi180) *
(CenterX - (integer(imgW) div 6)));
Y := CenterY + round(SIN(nAngle * Pi180) *
(CenterY - (integer(imgW) div 6)));
DrawLine(Graphics, CenterX + 2, CenterY + 2, X + 2, Y + 2,
$40000000, (imgW div 50));
DrawLine(Graphics, CenterX, CenterY, X, Y, ARGB2, (imgW div 50));
nAngle := (nSS * 6 - 270);
X := CenterX + round(COS(nAngle * Pi180) * (imgW div 8));
Y := CenterY + round(SIN(nAngle * Pi180) * (imgW div 8));
DrawLine(Graphics, CenterX + 2, CenterY + 2, X + 2, Y + 2,
$40000000, (imgW div 50));
DrawLine(Graphics, CenterX, CenterY, X, Y, ARGB2, (imgW div 50));
// Zeichne das Zentrum der Uhr
DrawEllipseFilled(Graphics, CenterX - 1, CenterY - 1, 6, 6, $40000000);
DrawEllipseFilled(Graphics, CenterX - 3, CenterY - 3, 6, 6, $FFFF0000);
GdipDeleteGraphics(Graphics);
end;
if Msg = WM_PAINT then
begin
if not Composited then
DoubleBuffer(0, 0, 0, 0);
EndPaint(WinHandle, ps);
end;
Result := 0;
exit;
end;
WM_DESTROY:
begin
// Lösche das Image
Img := GetProperty(WinHandle, PROP_IMAGE);
DeleteResource(Img);
KillTimer(WinHandle, 1);
end;
end;
Result := DefWindowProc(WinHandle, Msg, wP, lP);
end;
end;
Hier wird der zeiger gezeichnet und anschließend alles gelöscht
Delphi-Quellcode:
procedure DrawLine(Graphics: cardinal; x1, y1, x2, y2: integer;
ARGB: COLORREF; PenSize: integer);
var
hPen: integer;
begin
GdipCreatePen1(ARGB, PenSize, 2, hPen);
GdipDrawLineI(Graphics, hPen, x1, y1, x2, y2);
GdipDeletePen(hPen);
end;
Delphi-Quellcode:
procedure DrawEllipseFilled(Graphics: cardinal; x1, y1, x2, y2, ARGB: COLORREF);
var
hBrush: Pointer;
begin
GdipCreateSolidFill(ARGB, hBrush);
GdipFillEllipseI(Graphics, hBrush, x1, y1, x2, y2);
GdipDeleteBrush(hBrush);
end;
gruss Emil
|