procedure TFormStatusanzeige.SetParent(AParent: TWinControl);
begin
inherited;
if assigned(aParent) then
ActivateVNC;
end;
procedure TFormStatusanzeigePresse.Timer1Timer(Sender: TObject);
begin
ActivateVNC;
end;
procedure TFormStatusanzeigePresse.FormDestroy(Sender: TObject);
var
handle:HWND;
begin
handle:=FindWindowByTitle('explor');
Windows.SetParent(ExternesProgrammHandle,
Handle);
SendMessage(ExternesProgrammHandle, WM_CLOSE, 0, 0);
end;
procedure TFormStatusanzeigePresse.ActivateVNC;
var
WPM : TWindowPlacement;
Rect : TRect;
ProgramToStart, parameters:String;
WindowToShow: string;
Inifile: TInifile;
begin
Inifile:=TInifile.Create('setup.ini');
try
ProgramToStart :=Inifile.ReadString('Settings','ProgramToStart','C:\Program Files\UltraVNC\vncviewer.exe');
Parameters :=Inifile.ReadString('Settings','parameters','-port 192.168.9.140 -password blabla -fullscreen -notoolbar');
WindowToShow :=Inifile.ReadString('Settings','WindowToStart','pcname ( 192.168.9.140 ) ');
finally
Inifile.Free;
end;
ExternesProgrammHandle:=Findwindow(nil, PWideChar(WindowtoShow));
if ExternesProgrammHandle=0 then
ShellExecute(0, 'open', PWideChar(ProgramToStart), PWideChar(Parameters), nil, SW_NORMAL);
ExternesProgrammHandle:=Findwindow(nil, PWideChar(WindowtoShow));
if ExternesProgrammHandle<>0 then
begin
Windows.SetParent(ExternesProgrammHandle,Panel1.Handle);
WPM.Length:=SizeOf(WPM);
GetWindowPlacement(ExternesProgrammHandle,@WPM);
Rect.Top :=0;
Rect.Left :=0;
Rect.Right :=Panel1.Width;
Rect.Bottom:=Panel1.Height;
wpm.rcNormalPosition:=Rect;
SetWindowPlacement(ExternesProgrammHandle,@WPM);
ExternesProgrammEingehaengt:=True;
Timer1.Enabled:=false;
end;
end;
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;