Autor Beitrag
Stoffel1984
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: Fr 30.07.04 17:30 
Hallo,

wie bekomme ich das Fensterhandle wenn ich nur den ExeName hab?
Hab hier schon alles durchsucht aber irgendwie nicht das passende gefunden.
Vielleicht hab ich auch einfach nur die flaschen Keywords verwendet ;)
Ich brauch das Fensterhandle um das Programm zu minimieren.
Kenne allerdinds nur den Exe- nicht den Festernamen.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
procedure TForm1.TimerOnTimer(Sender: TObject);

  function IsRunning(Exe: PChar):hwnd;
  var
    proc: PROCESSENTRY32;
    hSnap: HWND;
    looper: BOOL;
  begin
    result := 0;
    proc.dwSize:= SizeOf(proc);
    hSnap:= CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
    looper:= Process32First(HSnap, Proc);
    while integer(looper)<> 0 do
    begin
      if ExtractFileName(proc.szExeFile)= ExtractFileName(Exe) then 
      begin
        result := hsnap;
        break;
      end
      else
        Looper:= Process32Next(hSnap, proc);
    end;
    CloseHandle(hSnap);
  end;

var
  h: Hwnd;
  s: string;
  i: Integer;
begin
  s := List.Strings[TTimer(Sender).tag-1];
  s := copy(s,1,pos('=',s)-1);
  h := IsRunning(PChar(s));
  if h = 0 then
  begin
    ShellExecute(0nil, PChar(s),
                 nilnil, SW_SHOW);
    Sleep(5000);
  end;
  //Hier sollte ich das Fenster minimieren s = der Programmpfad
  CloseWindow({?});
end;



Hoffe ihr könnt mir weiterhelfen.

Schönes Wochenende,
Stoffel
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: Fr 30.07.04 18:15 
hmmm... von der logischen Seite sollte das gar nicht möglich sein, da man eine EXE ja auch mehrmals gleichzeitig ausführen kann und dann gibts da ja mehrere FensterHandles. Noch dazu: WIe willst du grad an das FensterHandle kommen? Eine EXE kann ja auch mehrere Fenster haben etc. Also ich glaub nich, dass das überhaupt geht...



MrSaint

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
Stoffel1984 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: Fr 30.07.04 18:25 
Hi,

genau das isses ja. Das Hauptfenster des Programms schließen wär halt was. Nur wie?
Wie aus dem Code ersichtlich starte ich ja die exe wenn sie nich läuft. Danach will ich halt die exe bzw. das Fenster minimieren.
Wäre blöd wenns das nich möglich ist. ShellExecute liefert ja kein FensterHandle zurück.
Gibts da vielleicht eine andere Funktion die das macht? :?
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: Fr 30.07.04 18:40 
guck dir mal CreateProcess an :)

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 30.07.04 20:10 
Ich weiß ja nicht wie du es startest, aber starte das Programm doch gleich mit minimierten Fenster.
Stoffel1984 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: Sa 31.07.04 17:43 
Hallo,

wenn ich das Programm so starte:

ausblenden Delphi-Quelltext
1:
2:
    ShellExecute(0nil, PChar(s),
                 nilnil, SW_MINIMIZE);


dann startet er mir manche Programme minimiert andere jedoch nicht.
Woran kann das liegen?

Stoffel