Autor Beitrag
oPPi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66

MS Win 7 Pro, WinXP Pro
D3 Pro, TurboDelhi, Kylix 3 Pro
BeitragVerfasst: Fr 01.08.03 01:37 
Hallo,

ich bin grad dabei mir nen kleines Fernwartungstool in Verbindung mit dem VNC-Server zu schreiben. Jetzt stehe ich vor dem Problem wie kann ich das VNC-Server Programm (C:\Programme\RealVNC\WinVNC\winvnc.exe) welches sich nach dem erfolgreichen Verbinden mit der Gegenstelle noch im Systemtray

user defined image

befindet über mein Tool (Schaltfläche) beenden?

Ich hab jetzt schon einige Seiten durchforstet aber das passende hab ich nicht gefunden. Vielleicht weiß ja von euch einer Rat.

Gruß

oPPi


Zuletzt bearbeitet von oPPi am Do 07.08.03 21:00, insgesamt 1-mal bearbeitet
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Fr 01.08.03 07:00 
Möchtest du nur das TrayIcon entfernen?
Cruiser23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 191

WinXP
D7 Prof.
BeitragVerfasst: Fr 01.08.03 07:18 
Hast du denn das Handle? Wenn nein, schau hier mal rein! Wenn du es hast, kannst du an das Prog ne Close-Message schicken!
Wie das geht, darfst du mich aber nicht fragen, KA!

//Edit: Habe das und das hier im Forum gefunden. Vieleicht hilfts dir!

_________________
Du steckst immer in der Sch****, das einzige, was sich ändert, ist die Tiefe!
BungeeBug
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 901



BeitragVerfasst: Fr 01.08.03 10:00 
Hi,

deine Freunde werden Suche in: Delphi-Forum, Delphi-Library FINDWINDOW und Suche in: Delphi-Forum, Delphi-Library SENDMESSAGE sein.Wenn du jetzt noch nen bissel in der Hilfe und der Boardsuche kramst wirdst du schnell glücklich :)

Moderiert von user profile iconTino: DF-Tag hinzugefügt.
oPPi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66

MS Win 7 Pro, WinXP Pro
D3 Pro, TurboDelhi, Kylix 3 Pro
BeitragVerfasst: Fr 01.08.03 13:35 
Hy,

@toms: so wie es aussieht trägt sich das programm nur als trayicon ein. sofern der vnc-server nicht als service automatisch gestartet wird. das ist eigentlich auch beabsichtigt, das es nicht als service gestartet wird sondern manuell über mein tool.

@Cruiser23: thanks, hab ne funktion gefunden die mir das handle von WinVNC listet.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
function FindWindowByTitle(WindowTitle: string): Hwnd;
var
  NextHandle: Hwnd;
  NextTitle: array[0..260] of char;
begin
  // Get the first window
  NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
  while NextHandle > 0 do
  begin
    // retrieve its text
    GetWindowText(NextHandle, NextTitle, 255);
    if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then
    begin
      Result := NextHandle;
      Exit;
    end
    else
      // Get the next window
      NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
  end;
  Result := 0;
end;

So wenn ich jetzt nen cklick auf
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
var
  h: hwnd;
begin
  h := FindWindowByTitle('WinVNC');
  if h <> 0 then // Wenn WinVNC Handle gefunden
    ShowWindow(h, SW_NORMAL)
  else
    ShowMessage('Nicht gefunden');
end;

ausführe, wird mir das WinVNC Tray Icon als Handle angezeigt und ich kann es dann über den Schließen Button beenden Es wird dadurch auch die winvnc.exe geschlossen.
user defined image
Wie kann ich jetzt das gefundene Handle direkt ohne nochmaliges Anzeigen beenden

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: Fr 01.08.03 14:29 
Durch ShowWindow wird das Fenster angezeigt. Lass das also weg und schick eine WM_CLOSE-Message an das Fenster:

ausblenden Delphi-Quelltext
1:
SendMessage(h, WM_CLOSE, 0, 0);					

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind
oPPi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66

MS Win 7 Pro, WinXP Pro
D3 Pro, TurboDelhi, Kylix 3 Pro
BeitragVerfasst: Fr 01.08.03 14:51 
Hurra jetzt funzt es :D

I thank's for this help very much...

So und hier für alle der komplette Lösungsweg:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
{ Funktion zum finden des gesuchten Handles}
function FindWindowByTitle(WindowTitle: string): Hwnd;
var
  NextHandle: Hwnd;
  NextTitle: array[0..260] of char;
begin
  // Get the first window
  NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
  while NextHandle > 0 do
  begin
    // retrieve its text
    GetWindowText(NextHandle, NextTitle, 255);
    if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then
    begin
      Result := NextHandle;
      Exit;
    end
    else
      // Get the next window
      NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
  end;
  Result := 0;
end;

Und aufgerufen wird es z.B. über die Schaltfläche Beenden / Close:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
{ Beenden der komplette Anwendung }
procedure TForm1.btn_CloseClick(Sender: TObject);
var
  h: hwnd;
begin
  try
    h := FindWindowByTitle('WinVNC');
    if h <> 0 then // Wenn WinVNC Handle gefunden
      SendMessage(h, WM_CLOSE, 0, 0)
    else
      ShowMessage('WinVNC nicht gefunden');
  except
    Form1.Close;
    end;
end;


Dieses ist natürlich auf jedes Handle, was sich als Trayicon in die Taskbar neben der Uhr minimiert, anwendbar.

Gruß
oPPi