Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi 2 questions about screensavers - run preview and check setup (https://www.delphipraxis.net/135138-2-questions-about-screensavers-run-preview-check-setup.html)

WojTec 5. Jun 2009 12:33


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:
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;
Don't work (also without ") :( 2nd attempt:

Delphi-Quellcode:
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;
Also don't work :cry: 3rd attempt (with CreateProcess()). I wrote simple class for further usage:

Delphi-Quellcode:
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.
And try to load ssaver preview:

Delphi-Quellcode:
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;
Screensaver starts, but not preview in panel - I see config dialog (in normal mode, not in this panel ;)) :shock:
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 11:21 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz