Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
Delphi 6 Personal
|
[nonVCL] Screensaver mit Preview (Template) - Problem
27. Jan 2006, 20:39
Moin,
folgendes Problem, das Preview wird zwar angezeigt aber nicht in dem dafür vorgesehene Fenster.
Das Handle für das Previewfenster wird von Win per Parameter an den zu startenden Scrsaver übergeben.
Ich finde den Fehler nicht.
Der Hauptteil:
Delphi-Quellcode:
function WndProc(hWnd: HWND; uMsg: UINT; wParam: wParam; lParam: LParam):
lResult; stdcall;
begin
Result := 0;
case uMsg of
WM_CREATE:
begin
if ScreenMode = scrmStart then ShowCursor(FALSE);
SetTimer(hWnd, 1, 100, nil);
end;
WM_DESTROY:
begin
if ScreenMode = scrmStart then ShowCursor(TRUE);
KillTimer(hWnd, 1);
DestroyWindow(hWnd);
PostQuitMessage(0);
end;
WM_ACTIVATE:
if (wParam = Integer(FALSE)) then
PostMessage(hWnd, WM_CLOSE, 0, 0); // terminates the screen saver.
WM_LBUTTONDOWN,
WM_MBUTTONDOWN,
WM_RBUTTONDOWN,
WM_KEYDOWN:
begin
if ScreenMode = scrmStart then
PostMessage(hWnd, WM_CLOSE, 0, 0);
end;
// Wird verwendet um den Start des Bildschirmschoners zu verhindern
// zB. wenn eine App. den Bildschirmsch. unterdrücken will
SC_SCREENSAVE,
SC_CLOSE: Result := 0;
WM_TIMER:
begin
OnTimerEvent(hWnd);
end;
else
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
end;
end;
BEGIN
InitCommonControls; // Wegen XPManifest in der Res.
// Comandline auswerten
if (ParamStr(1) + #32)[1] in [' -', ' /'] then
begin
case (ParamStr(1))[2] of
' S', ' s': ScreenMode := scrmStart;
' P', ' p': ScreenMode := scrmPreview;
' C', ' c': ScreenMode := scrmConfig;
end;
end;
if ParamCount = 0 then ScreenMode := scrmStart;
// Create Window
if System.HPrevInst = 0 then
begin
ZeroMemory(@WndClass, Sizeof(TWndClass));
with WndClass do
begin
Style := CS_VREDRAW or CS_HREDRAW or CS_SAVEBITS or CS_DBLCLKS;
lpfnWndProc := @WndProc;
cbClsExtra := 0;
cbWndExtra := 0;
hbrBackground := GetStockObject(BLACK_BRUSH);
lpszMenuName := nil;
lpszClassName := WndClassName;
hInstance := hInstance;
hIcon := LoadIcon(0, IDI_APPLICATION);
hCursor := LoadCursor(0, IDC_ARROW);
end;
RegisterClass(WndClass);
end;
if ScreenMode = scrmStart then
begin
GetClientRect(GetDesktopWindow, WndRect);
AppHWND :=
CreateWindow(
WndClassName,
AppName,
WS_VISIBLE or WS_POPUP or WS_EX_TOPMOST {or WS_SYSMENU},
WndRect.Left,
WndRect.Top,
WndRect.Right,
WndRect.Bottom,
0,
0,
hInstance,
nil);
end else
if ScreenMode = scrmPreview then
begin
ParentWnd := _StrToInt(ParamStr(2)); // Get Window Handle // <---<<<
GetClientRect(ParentWnd, WndRect);
AppHWND :=
CreateWindow(
WndClassName,
AppName,
WS_VISIBLE or WS_POPUP,
WndRect.Left,
WndRect.Top,
WndRect.Right,
WndRect.Bottom,
0, {ParentWnd,} // <---<<<
0,
hInstance,
nil);
SetParent(AppHWND, ParentWnd); // <---<<<
end else // elseif ScreenMode = scrmConfig
begin
DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DLG), AppHWND, @DlgProc,0);
PostQuitMessage(0);
end;
UpdateWindow(AppHWND);
// "Application.Run"
while GetMessage(msg, 0, 0, 0) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
END.
Matti
|