I have a process and I would like to hide the window.
It work great if the process have only one window.
But if there is a prompt dialog or an alert dialog or another sub win开发者_运维百科dow, the hide method hide only the main window, not the dialog...
Can you help me to hide all windows of a process please ?
Many Thanks
This is my code :
[DllImport("user32.dll")]
private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
public void Show()
{
ShowWindow(_processHwnd, SwShow);
}
public void Hide()
{
Process[] processRunning = Process.GetProcesses();
foreach (Process pr in processRunning)
{
if (pr.Id == _process.Id)
{
_processHwnd = pr.MainWindowHandle;
}
}
ShowWindow(_processHwnd, SwHide);
}
You need to use a bit more of the Win32 API through P/invoke to obtain the window handles for the other top-level windows.
- Call
GetWindowThreadProcessId()
to get the thread ID of the main window. - Call
EnumThreadWindows()
to enumerate all the top-level windows of that thread.
It is possible that there are windows associated with a different thread in the process but the probabilities of that are vanishingly small.
精彩评论