Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#19

AW: Problem beim Programmneustart mit Instanzkontrolle

  Alt 9. Nov 2013, 11:19
Ich habe mein DPR-File etwas geändert - vielleicht kann es jemand brauchen:

Delphi-Quellcode:
program MyProg;

uses
  Forms, Windows, SysUtils,
  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
  hMutex: Cardinal;
  PreviousHandle : THandle;

BEGIN
  hMutex := CreateMutex(nil, True, PChar(UpperCase(ExtractFileName(ParamStr(0)))));
  if GetLastError = ERROR_ALREADY_EXISTS then
  begin
  PreviousHandle := Windows.FindWindow(NIL,PChar(UpperCase(ExtractFileName(ParamStr(0)))));
    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 else
  begin
    Application.Initialize;
    Application.MainFormOnTaskbar := True;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end;
end.

Geändert von hathor ( 9. Nov 2013 um 18:18 Uhr)
  Mit Zitat antworten Zitat