创建进程后得到该进程的主窗口句柄
var
StartUpInfo: TStartUpInfoA;
ProcessInfo: TProcessInformation;
gui: tagGUITHREADINFO;
hAcount: HWND;
begin
FillChar(StartUpInfo, Sizeof(TStartUpInfo), #0);
FillChar(ProcessInfo, Sizeof(TProcessInformation), #0);
StartUpInfo.cb := Sizeof(TstartUpInfo);
try
CreateProcessA(PAnsiChar(FszQQPath), nil, nil, nil, False, 0, nil, nil, StartUpInfo, ProcessInfo);
except
end;
WaitForInputIdle(ProcessInfo.hProcess, INFINITE);
FillMemory(@gui, Sizeof(tagGUITHREADINFO), 0);
gui.cbSize := Sizeof(tagGUITHREADINFO);
//这个可以得到刚才创建进程的主窗口句柄
GetGUIThreadInfo(ProcessInfo.dwThreadId, gui);
//得到子窗口句柄
hAcount := FindWindowExA(gui.hwndActive, 0, 'ATL:30A441A8', PAnsiChar(0));
//激活窗口
SetForegroundWindow(FrmClient.Handle);
SetActiveWindow(FrmClient.Handle);
SendMessageA(hAcount, WM_SETTEXT, 0, LPARAM(szAcount));
SendKeys(PAnsiChar(FszPas), False);
SendKeys('{ENTER}',False);
end;
//可以结束自己创建的进程
TerminateProcess(ProcessInfo.hProcess, 0);