AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi 2 questions about screensavers - run preview and check setup

2 questions about screensavers - run preview and check setup

Ein Thema von WojTec · begonnen am 5. Jun 2009
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

2 questions about screensavers - run preview and check setup

  Alt 5. Jun 2009, 13:33
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 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 )
When I use console to execute Edit2.Text, preview is loaded in Panel1
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?
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:36 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