Einzelnen Beitrag anzeigen

Benutzerbild von rollstuhlfahrer
rollstuhlfahrer

Registriert seit: 1. Aug 2007
Ort: Ludwigshafen am Rhein
1.529 Beiträge
 
Delphi 7 Professional
 
#7

Re: [nonVCL]Bildschirmschoner Vorschau verschieben & sch

  Alt 4. Jun 2008, 14:04
HI,

ich hab mitlerweile die Fensterklasse gewechselt, CreateWindowEx und CreateWindow ausprobiert. Problem ist: sobald als Stil WS_Popup dazukommt, wird die Vorschau angezeigt, ist es nicht dabei, wird die vorschau nicht angezeigt, aber entsprechend geschlossen. Weil ich nicht weiterkomme, häng ich den bisherigen Code an.

Delphi-Quellcode:
unit PreViewU;

interface

uses
  Windows,
  Messages,
  globals, // width, heigth, classname, appname
  MySysUtils; // IntTostr, StrToInt, Uppercase, strtointdef
// CommCtrl;

var
  hTimer: HWND;
(*  Window: TWndClassEx = (
    cbSize          : SizeOf(TWndClassEx);
//    Style          : CS_HREDRAW or CS_VREDRAW;
    Style          : CS_VREDRAW or CS_HREDRAW or CS_SAVEBITS or CS_DBLCLKS;
//    lpfnWndProc    : @WndProc;
    cbClsExtra      : 0;
    cbWndExtra      : 0;
    hbrBackground  : COLOR_APPWORKSPACE;
    lpszMenuName    : nil;
    lpszClassName  : ClassName;
    hIconSm        : 0;
  );                              *)

  Window: TWndClass;
  Msg: TMsg;
  Width, Height: Integer;

procedure PreView;

implementation

// Create-Event
function WMCreate(hWnd: HWND): HWND;
begin
// Aus der TaskBar bannen
(*SetWindowLong(hWnd, GWL_EXSTYLE,
              GetWindowLong(hWnd, GWL_EXSTYLE)
              or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);        *)


// Timer erstellen
Result := SetTimer(hWnd, IDC_TIMER, 1, nil);
end;

// Timer-Event
procedure WMTimer(hWnd: HWND);
var dc: HDC;
    Brush: HBRUSH;
    Color: COLORREF;
begin
dc := GetDC(hWnd);
if dc = 0 then MessageBox(0, 'Kein DC-Objekt', 'FEHLER', mb_iconwarning);
(*Inc(r);
TextOut(dc, 10, 10, PChar(IntToStr(r)), 3);
brush := CreateSolidBrush(RGB(r, 255, 255));
SelectObject(dc, brush);
SetBkColor(dc, RGB(r, 255, 255));*)


Color := RGB(Random(255), Random(255), Random(255));
Brush := CreateSolidBrush(Color);
FillRect(dc, Rect(0, 0, WindowWidth, WindowHeight), Brush);
ReleaseDC(hWnd, dc);
end;

// Fenster wird geschlossen
procedure WMDestroy(hwnd: HWND);
begin
KillTimer(hwnd, IDC_Timer);
ShowCursor(true);
PostQuitMessage(0);
end;

// Window-Prozedur
function WndProc(hWnd: HWND; uMsg: UINT; wParam: wParam; lParam: LParam): lresult; stdcall;
begin
  Result := 0;
  case uMsg of
    WM_DESTROY: WMDestroy(hWnd);
    WM_CREATE: hTimer := WMCreate(hWnd);
    WM_CLOSE: PostQuitMessage(0);

    WM_TIMER: WMTimer(hWnd);
  else
    Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
  end;
end;

// Screensaver-Main
procedure PreView;
var
  parentwindow: HWND;
  apphwnd: HWND;
  Rec: TRect;
begin
Window.style := CS_VREDRAW or CS_HREDRAW or CS_SAVEBITS or CS_DBLCLKS;
Window.lpfnWndProc := @WndProc;
Window.cbClsExtra := 0;
Window.cbWndExtra := 0;
Window.hInstance := HInstance;
Window.hIcon := LoadIcon(hInstance,MAKEINTRESOURCE(100));
Window.hCursor := LoadCursor(0, IDC_ARROW);
Window.hbrBackground := GetStockObject(BLACK_BRUSH);
Window.lpszMenuName := nil;
Window.lpszClassName := ClassName;

(*Window.hbrBackground := GetStockObject(BLACK_BRUSH);
Window.hInstance := hInstance;
Window.hIcon := LoadIcon(hInstance,MAKEINTRESOURCE(100));
Window.hCursor := LoadCursor(0, IDC_ARROW);
Window.lpszClassName := ClassName;
Window.lpfnWndProc := @WndProc;
RegisterClassEx(Window);        *)

RegisterClass(Window);

parentwindow := StrToIntDef(ParamStr(2), 0);

GetWindowRect(parentwindow, Rec);
Width := Rec.Right - Rec.Left;
Height := Rec.Bottom - Rec.Top;

CreateWindowEx(0, ClassName, AppName,
    WS_VISIBLE or WS_CHILD,
    Rec.Left, Rec.Top, Width, Height,
    parentwindow, 0, hInstance, nil);

(*Apphwnd := CreateWindow(
        ClassName,
        AppName,
        WS_VISIBLE or WS_Child,
        Rec.Left,
        Rec.Top,
        Width,
        Height,
        parentwindow,
        0,
        hInstance,
        nil);

if GetParent(apphwnd) <> parentwindow then
begin
  MessageBox(0, 'Parent nicht zugewiesen', 'FEHLER', MB_ICONSTOP);
  SetParent(apphwnd, parentwindow);
end;           *)


{Nachrichtenschleife starten}
while GetMessage(msg,0,0,0) do
begin
  TranslateMessage(msg);
  DispatchMessage(msg);
end;
end;

end.
Bernhard
Bernhard
Iliacos intra muros peccatur et extra!
  Mit Zitat antworten Zitat