![]() |
2 questions about screensavers - run preview and check setup
1st question: I want to show preview of selected screensaver on some control (such as TPanel). I checked on MSDN how to do it. I wanted do it with ShellExecute():
Delphi-Quellcode:
Don't work (also without ") :( 2nd attempt:
procedure TForm1.Button1Click(Sender: TObject);
var P: string; begin Edit1.Text := ExtractShortPathName(Edit1.Text); P := Format('"%s" /p %d', [Edit1.Text, Panel1.Handle]); Edit2.Text := P; ShellExecute(Handle, 'open', PChar(P), nil, nil, SW_SHOW); end;
Delphi-Quellcode:
Also don't work :cry: 3rd attempt (with CreateProcess()). I wrote simple class for further usage:
procedure TForm1.Button2Click(Sender: TObject);
var P, A: string; begin Edit1.Text := ExtractShortPathName(Edit1.Text); P := Format('%s', [Edit1.Text]); A := Format('/p %d', [Panel1.Handle]); Edit2.Text := P + A; ShellExecute(Handle, 'open', PChar(P), PChar(A), nil, SW_SHOW); end;
Delphi-Quellcode:
And try to load ssaver preview:
unit ProcessUtils;
interface uses Windows; var Process: THandle; type TProcess = class public class function Create(lpApplicationName, lpCommandLine: String): THandle; public class function Terminate(hProcess: THandle): Boolean; end; implementation class function TProcess.Create(lpApplicationName, lpCommandLine: String): THandle; var Startup: TStartupInfo; Process: TProcessInformation; Created: Boolean; begin Result := 0; FillChar(Startup, SizeOf(TStartupInfo), #0); FillChar(Process, SizeOf(TProcessInformation), #0); Startup.cb := SizeOf(TStartupInfo); Created := CreateProcess(PChar(lpApplicationName), PChar(' ' + lpCommandLine), nil, nil, False, CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil, nil, Startup, Process ); if Created then begin Result := Process.hProcess; //WaitForSingleObject(Process.hProcess, INFINITE); //CloseHandle(Process.hThread); //CloseHandle(Process.hProcess); end; end; class function TProcess.Terminate(hProcess: THandle): Boolean; var pId: DWORD; begin Result := False; // GetWindowThreadProcessId(hProcess, @pId); // hProcess := OpenProcess(PROCESS_TERMINATE, False, pId); if hProcess <> 0 then begin Result := TerminateProcess(hProcess, 0); if Result then CloseHandle(hProcess) ; end; end; initialization Process := 0; end.
Delphi-Quellcode:
Screensaver starts, but not preview in panel - I see config dialog (in normal mode, not in this panel ;)) :shock:
procedure TForm1.Button3Click(Sender: TObject);
begin Edit2.Text := Format('"%s" /p %d', [Edit1.Text, Panel1.Handle]); Process := TProcess.Create(Edit1.Text, Format('/p %d', [Panel1.Handle])); end; procedure TForm1.Button4Click(Sender: TObject); begin TProcess.Terminate(Process); end; When I use console to execute Edit2.Text, preview is loaded in Panel1 :cyclops: What I'm doing wrong and how to do it well :? :?: And also I have 2nd question: How to determine whether the screensaver have setup dialog? |
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:24 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz