Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#15

AW: Problem beim Programmneustart mit Instanzkontrolle

  Alt 8. Nov 2013, 19:13
Das Problem "OneInstance" hatte ich heute auch und habe es im DPR-File gelöst.
Wenn das zuerst gestartete Programm minimiert ist, wird es angezeigt.
Funktioniert auch unter WIN 8.0.


Delphi-Quellcode:
program TEST1;

uses
  Forms, Windows,
  Unit1 in 'Unit1.pas{Form1};

{$R *.res}

procedure SwitchToThisWindow(h1: hWnd; x: bool); stdcall; external user32 Name
'SwitchToThisWindow'; {x = false: Size unchanged, x = true: normal size}

var
  PreviousHandle : THandle;
begin
  PreviousHandle := Windows.FindWindow(NIL,'MyProg'); //MyProg = Form1.caption
  if PreviousHandle = 0 then
  begin
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end
  else
 begin
    if Windows.IsIconic(PreviousHandle) then
        Windows.ShowWindow(PreviousHandle, SW_RESTORE);
    SwitchToThisWindow(PreviousHandle, TRUE);
    SetForegroundWindow(PreviousHandle);
    SetWindowPos(PreviousHandle,
      HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW);
 end;
end.
  Mit Zitat antworten Zitat