Einzelnen Beitrag anzeigen

t.roller
(Gast)

n/a Beiträge
 
#6

AW: Copy Windowsfenster minimiert starten

  Alt 7. Aug 2016, 16:15
So geht's:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Winapi.ShellAPI, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    cbSHOW: TCheckBox;
    ASource: TEdit;
    ADest: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Status: TLabel;
    lbERROR: TLabel;
    ARenameCheck: TCheckBox;
    procedure Button1Click(Sender: TObject);
    procedure CopyInThread(ASource, ADest : String);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  myThread: TThread;

implementation

{$R *.dfm}

procedure TForm1.CopyInThread(ASource, ADest : String);
var aThread : TThread;
  sh: TSHFileOpStruct;
  Err : Integer;
begin
  aThread :=
    TThread.CreateAnonymousThread(
      procedure
      begin
        sh.lpszProgressTitle:= PChar('MyCopier');
        sh.Wnd := 0;// Application.Handle;
        sh.wFunc := FO_COPY;
        sh.pFrom := PChar(ASource + #0#0);
        sh.pTo := PChar(ADest + #0#0);
        sh.fFlags := FOF_NOCONFIRMATION or fof_MultiDestFiles or FOF_NOCONFIRMMKDIR;
        if ARenameCheck.Checked then
        sh.fFlags := sh.fFlags or fof_RenameOnCollision;
        Err:=ShFileOperation(sh);
        if Err <> 0 then
          begin
          ShowMessage('Error: ' + inttostr(Err) + ' '  + SysErrorMessage(GetLastError));
          end;
      end);

  aThread.FreeOnTerminate := True;
// aThread.OnTerminate := ...
  aThread.Start;
end;

procedure TForm1.Button1Click(Sender: TObject);
var Handle: THandle;
    strSource, strDest : String;
begin
strSource:= ASource.text;
strDest:= ADest.text;
CopyInThread(strSource, strDest);
if NOT cbSHOW.Checked then // CheckBox
BEGIN
  Sleep(2000); // Wichtig!!! Warten bis COPY-WINDOW vorhanden ist.
  Application.ProcessMessages;
  Handle:= FindWindow(PChar('OperationStatusWindow'), nil);
  if Handle <> 0 then ShowWindow(Handle, SW_MINIMIZE);
  Self.SetFocus;
END;
  Winapi.Windows.Beep(1500,200);
end;

end.

Geändert von t.roller ( 7. Aug 2016 um 20:43 Uhr)
  Mit Zitat antworten Zitat