How do I access a manually started Explorer's handle when my application is in Shell mode?

StackOverflow https://stackoverflow.com/questions/21584045

  •  07-10-2022
  •  | 
  •  

문제

My application is built to run in Shell mode (via registry changes).

The user is allowed to define custom 'buttons' to invoke utilities such as CMD, Regedit, Explorer...

When the user presses the button a window is opened with their specified utility.

Pressing the minimize button of the utility's window drives the application code to shrink and move the window to the bottom of the screen where it can be subsequently moved or expanded by the user.

This works nicely with the exception of Explore.exe.

In the following code the proc.MainWindowHandle is empty/zero for Emplorer.exe.

Knowing this is a 'special case' program, is there any way to determine the MainWindowHandle for Explorer.exe so that the program can manage it too?

// Minimize all utility windows
Process[] procs = Process.GetProcesses();
Process currentProcess = Process.GetCurrentProcess();
IntPtr hWnd;
foreach (Process proc in procs)
{
    if (proc.Id != currentProcess.Id)
    {
        if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
        {
            WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
            GetWindowPlacement(hWnd, ref wp);

            if (wp.showCmd != (int)ShowWindowCommand.ShowMinimized || wp.showCmd != (int)ShowWindowCommand.Minimize || wp.showCmd != (int)ShowWindowCommand.ShowMinNoActive)
            {
                ShowWindowAsync(hWnd, (int)ShowWindowCommand.ShowMinimized);
            }

            SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.DoNotActivate | SetWindowPosFlags.IgnoreResize);
        }
    }
}
도움이 되었습니까?

해결책

Of course, the explorer process may be responsible for multiple top-level windows so it might take a little more work to identify the specific one that you are looking for.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top