Entwickler-Ecke

Windows API - WM_PAINT: DrawIcon(... funzt nicht


maxk - So 20.06.04 14:26
Titel: WM_PAINT: DrawIcon(... funzt nicht
Hallo,
ich habe ein nonVCL Form erstellt und darauf mit DrawIcon ein Icon gezeichnet. Dieses Bild soll automatisch neugezeichnet werden, wenn es nicht mehr sichtbar ist. Hier mein Code aus meiner WndProc Case-Schleife:

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
 FUNCTION WndProc(hWnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; STDCALL;
 BEGIN
   Result := 0;
   CASE uMsg OF
     WM_CTLCOLORSTATIC: SetBkMode(wParam,TRANSPARENT);
     WM_NCPAINT: begin
      Result:=DefWindowProc(hWnd, uMsg, wParam, lParam);
      if wParam=0 then DrawIcon(GetDC(hWnd),8,8,AIcon)
       else DrawIcon(wParam,8,8,AIcon);
     end;
   ELSE
     Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
   END;
 END;
Die Variable AIcon ist global Definiert. Leider wird das Icon nicht gezeichnet. Hat jemand eine Lösung?


Delete - Mo 21.06.04 15:08

Warum verschwindet das Bild eigentlich? (Okay, ich geb´s zu: Ich habe mich damit noch nicht beschäftigt ...) Ich habe einmal ein Static-Control benutzt, ein Symbol geladen und das angezeigt. Das bleibt dann auch sichtbar, selbst wenn ich andere Fenster davor setze ... usw. usw. Da kümmert sich doch eigentlich Windows selbst drum.


maxk - Mo 21.06.04 20:58

Naja, wenn ich es direkt als Resource einbinde, dann verschwindet es auch nicht. Aber das Bild ist jedesmal anders. Und dann ist es wie beim Zeichnen auf ein Canvas.


maxk - Mo 28.06.04 18:17

Hier die Lösung:

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
 var PS:TPaintStruct;
 begin
  case uMsg of
     WM_PAINT: begin
      BeginPaint(hwnd, PS);
      Result:=DefWindowProc(hWnd, uMsg, wParam, lParam);
      if wParam=0 then DrawIcon(GetDC(hWnd),8,8,AIcon)
       else DrawIcon(wParam,8,8,AIcon);
      EndPaint(hwnd, PS);
     end;