我用CreateProcess创建的程序如何把它显示出来?(100分)

  • 主题发起人 主题发起人 月光
  • 开始时间 开始时间

月光

Unregistered / Unconfirmed
GUEST, unregistred user!
我在CreateProcess时用了一个SW_hide参数,现在想用户按一个按纽就把程序创建的dos窗口显示出来,但是CreateProcess返回的只是hProcess,hThread,dwProcessId,dwThreadId(hProcess和hThread分别是子进程的句柄和子进程的主线程的句柄,dwProcessId和dwThreadId分别是子进程的标识号和子进程的主线程的标识号),而没有dos窗口的Handle,如果有就能用ShowWindow(Handle, SW_SHOWNORMAL);方法把它显示出来,不想用findwindow,看看有没有高手知道别的方法
 
可以用EnumThreadWindows
 
你可以保存进程的ID 这样用:openprocess就可以得到方才创建的进程的句柄 然后就可以用showwindow()了
 
樓上貼原理, 我只能貼代碼了<br><br>&nbsp;function ExecuteEnumProc(hWin : HWND; lParam : LPARAM) : boolean; stdcall;<br>&nbsp;begin<br>&nbsp; &nbsp;Result := True;<br>&nbsp; &nbsp;if (IsWindowVisible(hWin)) AND (GetParent(hWin) = 0) AND<br>(GetWindow(hWin, GW_OWNER) = 0) then begin<br>&nbsp; &nbsp; &nbsp;pHWND(lParam)^ := hWin;<br>&nbsp; &nbsp; &nbsp;Result := False;<br>&nbsp; &nbsp;end;<br>&nbsp;end;<br>&nbsp;<br>&nbsp;function Execute(const CommandLine : string; const InitializationTimeout<br>: cardinal; const Init_Fudge : cardinal = EXEC_INIT_FUDGE) : HWND;<br>&nbsp;var<br>&nbsp; &nbsp;tSI : TStartupInfo;<br>&nbsp; &nbsp;tPI : TProcessInformation;<br>&nbsp; &nbsp;dwI : DWORD;<br>&nbsp;begin<br>&nbsp; &nbsp;FillChar(tSI, SizeOf(TStartupInfo), 0);<br>&nbsp; &nbsp;tSI.cb := sizeof(TStartupInfo);<br>&nbsp; &nbsp;Result := 0;<br>&nbsp; &nbsp;if (CreateProcess(nil, pchar(CommandLine), nil, nil, False, 0, nil,<br>nil, tSI, tPI)) then begin<br>&nbsp; &nbsp; &nbsp;dwI := WaitForInputIdle(tPI.hProcess, InitializationTimeout); &nbsp;//<br>Not using dwI<br>&nbsp; &nbsp; &nbsp;Sleep(Init_Fudge);<br>&nbsp; &nbsp; &nbsp;EnumThreadWindows(tPI.dwThreadId, @ExecuteEnumProc,<br>LPARAM(@Result));<br>&nbsp; &nbsp; &nbsp;CloseHandle(tPI.hProcess);<br>&nbsp; &nbsp; &nbsp;CloseHandle(tPI.hThread);<br>&nbsp; &nbsp;end;<br>&nbsp;end;<br>
 
后退
顶部