use*_*124 1 delphi winapi delphi-2010
我正在使用CreateProcess API将RealVNC与我的exe集成...我只需要为创建的vnc客户端处理句柄,但到目前为止我还没有成功.代码非常简单:
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;
Run Code Online (Sandbox Code Playgroud)
标题var中没有返回任何内容... GetWindowText函数只是一个测试,看看我是否有正确的句柄,如果是,我应该看到vnc客户端标题是正确的?谢谢!
窗口句柄和处理句柄不是一回事.因为GetWindowText
你需要一个窗口把手.
WaitForInputIdle
,允许进程启动并创建其主窗口.EnumWindows
枚举顶级窗口.GetWindowThreadProcessId
以查找创建该窗口的进程的进程ID.您创建的进程的进程ID是ProcInfo.dwProcessId
.