![]() |
Eigene Anwendung finden und nach vorne setzen
Ich möchte vermeiden, dass meine Anwendung 2 mal gestartet wird. Das klappt auch ganz, habs gemacht wie
![]() Ich möchte aber nicht einfach vermeiden, dass eine 2. Instanz gestartet wird, sondern dass bei einem 2. Start einfach die bestehende Instanz in den Vordergrund geholt. Die Anwendung kann sich in einigen Fällen auch minimiert nur im Tray zu finden sein, ist vielleicht fürs Problem wichtig... Wer weiss dazu was? |
Re: Eigene Anwendung finden und nach vorne setzen
Du willst wohl folgendes machen : beim 2. Programmstart soll das Programm nicht nur zurück in den Vordergrund geholt werden, sondern besser noch, der Cursor steht auch da wo er vorher auch war ?
Stichwort : CreateSemaphore. |
Re: Eigene Anwendung finden und nach vorne setzen
Zitat:
|
Re: Eigene Anwendung finden und nach vorne setzen
eine Variante wäre:
mit ![]() ![]() |
Re: Eigene Anwendung finden und nach vorne setzen
Habe eben
![]()
Delphi-Quellcode:
Der Aufruf im Quellcode des Projektes:
unit OneInst;
interface { Make a call to this procedure in your project source immediately before the first call to CreateForm. That should ensure it is after the Application.Title assignment that can muck up the logic. If you haven't set an application title yet, then do so to ensure this works } procedure EnsureSingleInstance (MyGUID : string) ; implementation uses WinTypes, WinProcs, Forms, SysUtils, Messages; procedure EnsureSingleInstance (MyGUID : string) ; var Wnd: HWnd; WndClass, WndText: array[0..255] of char; begin {$ifdef Win32} { Try and create a semaphore. If we succeed, then check } { if the semaphore was already present. If it was } { then a previous instance is floating around. } { Note the OS will free the returned semaphore handle } { when the app shuts so we can forget about it } if (CreateSemaphore(nil, 0, 1, PChar(MyGUID)) <> 0) and (GetLastError = Error_Already_Exists) then {$else} if HPrevInst <> 0 then {$endif} begin Wnd := GetWindow(Application.Handle, gw_HWndFirst); while Wnd <> 0 do begin { Look for the other TApplication window out there } if Wnd <> Application.Handle then begin { Check it's definitely got the same class and caption } GetClassName(Wnd, WndClass, Pred(SizeOf(WndClass))); GetWindowText(Wnd, WndText, Succ(Length(Application.Title))); if (StrPas(WndClass) = Application.ClassName) and (StrPas(WndText) = Application.Title) then begin { This technique is used by the VCL: post } { a message then bring the window to the } { top, before the message gets processed } PostMessage(Wnd, wm_SysCommand, sc_Restore, 0); {$ifdef Win32} SetForegroundWindow(Wnd); {$else} BringWindowToTop(Wnd); {$endif} Halt end end; Wnd := GetWindow(Wnd, gw_HWndNext) end end end; end.
Delphi-Quellcode:
program Meinenwendung;
uses windows, dialogs, Forms, ..., OneInst ; {$R *.res} const MyGUID = '{79534BF6-900D-4FD8-BA5B-A3E327A70332}'; begin Application.Initialize; Application.Title := 'Titel'; EnsureSingleInstance (MyGUID) ; Application.CreateForm(TfrmMain, frmMain); ... Application.Run; end. |
Re: Eigene Anwendung finden und nach vorne setzen
Frage ist zwar schon beantwortet aber Just4Info: LMDOneInstance (ist bei Delphi teilweise schon dabei) macht das auch.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:44 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz