关闭Windows资源管理器的特定实例

时间:2012-11-21 20:42:26

标签: c# .net windows windows-7 explorer

我在尝试WM_CLOSE一个Window Explorer进程时遇到问题,因为发送该消息然后会尝试关闭Windows Shell资源管理器进程并提示用户关闭窗口。这不是预期的行为,我想知道如何解决它?

如何在不关闭整个PC的情况下优雅地关闭各个浏览器窗口?目标是具有与用户自己单击X按钮相同的行为。

编辑:我发现我能够获得资源管理器进程的所有子窗口但是从那时起我不确定如何识别哪些窗口是实际的,用户可见/可互动的资源管理器窗口。

11/21/2012 16:27:49 [12]  DEBUG - Closing process with PID: 2680
11/21/2012 16:27:49 [12]  DEBUG - Window has 11 descendant windows
11/21/2012 16:27:49 [12]  DEBUG - Found child window:  hWnd: 590746 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window: 4:27 PM hWnd: 656010 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window:  hWnd: 2294392 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window:  hWnd: 1245586 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window: User Promoted Notification Area hWnd: 2949496 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window: System Promoted Notification Area hWnd: 1245548 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window:  hWnd: 852646 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window:  hWnd: 918356 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window: Running applications hWnd: 1769950 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window: Running applications hWnd: 1179980 Window State: Normal
11/21/2012 16:27:49 [12]  DEBUG - Found child window: TF_FloatingLangBar_WndTitle hWnd: 458926 Window State: Normal

1 个答案:

答案 0 :(得分:1)

你是怎么进窗的?您可以通过文本获取带有winapi调用的句柄,因此桌面资源管理器可能没有标题。 http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499(v=vs.85).aspx查看lpWindowName参数。

此外,我只是在猜测,你可能会看看桌面资源管理器和其他资源管理器实例之间的关系,以及它们与GetDesktopWindow()http://msdn.microsoft.com/en-us/library/windows/desktop/ms633504(v=vs.85).aspx返回的hande的关系