开发者

Hide multiple windows by Process

开发者 https://www.devze.com 2023-04-01 21:20 出处:网络
I have a process and I would like to hide the window. It work great if the process have only one window.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消