Announcement

Collapse
No announcement yet.

Anwendung nur einmal starten

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Anwendung nur einmal starten

    Hallo zusammen,
    zu diesem Problem habe ich die Lösung von Hagen genutzt:

    function AtomExists: Boolean;

    function DoActivate(Wnd: hWnd; Atom: PChar): Bool; stdcall;
    var
    Focus: HWnd;
    begin
    Focus := GetProp(Wnd, Atom);
    if IsWindow(Focus) then
    begin
    Result := False;
    if IsIconic(Focus) then SendMessage(Focus, wm_SysCommand, sc_Restore, 0);
    SetForegroundWindow(Focus);
    end
    else
    Result := True;
    end;

    var
    Atom: THandle;

    begin
    Atom := GlobalFindAtom(PChar(ParamStr(0)));
    Result := Atom <> 0;
    if Result then
    EnumWindows(@DoActivate, Atom);
    end;

    begin
    if not AtomExists then
    try
    Atom := GlobalAddAtom(PChar(ParamStr(0)));
    Application.Initialize;
    ...

    Wie kann man das Problem beheben, wenn in der Entwicklungsumgebung mit STRG F2 das Programm abgebrochen wird?

    Dann wird das Atom nicht mehr entfernt.

    Danke für eine Info
    Gruß
    Holger

  • #2
    Warum nimmst du keinen Mutex:
    <pre>
    ...
    var
    Form1: TForm1;
    mHandle: THandle;

    implementation

    {$R *.dfm}

    ...

    initialization
    mHandle := CreateMutex(nil, True, 'Mein Programm');
    // Mein Programm ist eine eindeutige Kennung
    if GetLastError = ERROR_ALREADY_EXISTS then
    begin
    ShowMessage('Anwendung läuft bereits');
    Halt;
    end;

    end.
    </pre>
    Da gibt es dein Problem nicht.<br>
    bye,
    Helmu

    Comment

    Working...
    X