Reputation: 247
I'm using CreateProcess API to integrate RealVNC with my exe... I just need to process handle for the created vnc client, but I'm unsuccess so far. The code is pretty simple:
procedure TForm1.VncAuth;
var
StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
CmdLine: string;
title: string;
ProcHandle: THandle;
begin
FillChar(StartInfo,SizeOf(TStartupInfo),#0);
FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);
CmdLine:= 'vnc.exe';
UniqueString(CmdLine);
CreateProcess(NIL ,PChar(CmdLine), NIL, NIL, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS
, NIL, NIL, StartInfo, ProcInfo);
ProcHandle:= ProcInfo.hProcess;
GetWindowText(ProcHandle, PChar(title), 255);
ShowMessage(title);
end;
Nothing is returned in title var... the GetWindowText function is just a test to see if I have the right handle, if Yes I should see the vnc client title's right? Thank you!
Upvotes: 1
Views: 5186
Reputation: 613461
Window handles and process handles are not the same thing. For GetWindowText
you need a window handle.
WaitForInputIdle
to allow the process to start up and create its main window.EnumWindows
to enumerate the top level windows.GetWindowThreadProcessId
to find out the process ID of the process that created that window. The process ID of the process you created is ProcInfo.dwProcessId
.Upvotes: 5