Autor Beitrag
mattl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 77

Win Xp Pro
Deplphi 3 Pro,Delphi 2005 PE
BeitragVerfasst: So 25.02.07 12:33 
in meinem Programm kann ein Bild über Öffnen mit geladen werden

Das mache ich mit
ausblenden Delphi-Quelltext
1:
if(paramcount = 1) and (fileexists(paramstr(1))) then  begin					

Unter oncreate
nun möchte ich verhindern dass die Anwendung ein zweites mal geöffnet wird wenn noch einmal ein bild geöffnet wird... so dass das Bild in der bereits laufenden Anwendung
geladen wird

wie kann ich das realisieren


...und ich habe die SuFu benutzt :?
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 25.02.07 12:43 
Mit einem Mutex findest du leicht heraus, ob bereits deine Anwendung offen ist. Allerdings dürfte bei dir auch FindWindow reichen ;). Wenn er fündig wurde schickst du einfahc eine Message an die bereits existierende Instahnz mit der neuen Url und anshcließemnd beendest du die 2. Instanz. Am besten machst du das in der dpr, also bevor die Forms etc. erzeugt werden.
mattl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 77

Win Xp Pro
Deplphi 3 Pro,Delphi 2005 PE
BeitragVerfasst: So 25.02.07 12:59 
dass die Anwendung nur einmal startet hätte ich schon einmal

mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  var H: THandle;

initialization
  H := CreateMutex(nil, True, 'mutex');
  if GetLastError = ERROR_ALREADY_EXISTS then Halt;

finalization
  if H <> 0 then CloseHandle(H);


vor end.

für dass mit der message und mit den instanzen bräuchte ich aber noch eine genauere erläuterung
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 25.02.07 13:05 
Wie gesagt: Mutex ist nicht zwingend erforderlich. Und wie gesagt: es wäre besser, wenn du es in die dpr packst. Also so hier ungefähr:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
  h:=FindWindow('TMainForm', '');
  if h=0 then
  begin
    Application.Initialize;
    Application.Title:='...';
    Application.CreateForm(TMainForm, MainForm);
    Application.Run;
  end
  else
  begin
    SendMessage(h, ...);
  end;