Closing a Specific Instance of Windows Explorer
Asked Answered
O

1

3

I'm having a problem trying to WM_CLOSE a Window Explorer process in that sending that message will then try to close the Windows Shell explorer process and prompt the user to shut down windows. This is not the intended behaviour and I was wondering how I could work around it?

How can I close individual explorer windows gracefully, without shutting down the whole PC at the same time? The goal is to have the same behaviour as if the user had clicked on the X button themselves.

EDIT: I've found that I'm able to get all the child windows of the explorer process but from that point I'm not sure how to identify which windows are the actual, user visible / interactable Explorer windows.

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
Osteology answered 21/11, 2012 at 20:42 Comment(0)
L
1

How are you getting the window? You can obtain handles with winapi calls by text so perhaps the desktop explorer has no caption. http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499(v=vs.85).aspx Look at the lpWindowName parameter.

Also, and I am just guessing here, you might look at the relationship between the desktop explorer and the other explorer instances as far as how they are related to the hande returned by GetDesktopWindow() http://msdn.microsoft.com/en-us/library/windows/desktop/ms633504(v=vs.85).aspx

Legacy answered 21/11, 2012 at 20:54 Comment(3)
Hey, thanks for the tips. I've found a way to list all the child windows of the explorer process, and could definitely compare the hWnd returned by the GetDesktopWindow with one of the ones returned, but in the instance I posted above, I only had two Windows Explorer windows open, so it looks like it'll be complicated to narrow it down than that. :)Osteology
Is the class the same? FindWindow looks for class too. Is the shell process always the child of the desktop and the others not? There has to be some way to differentiate between that one and the one being used by the shell.Legacy
Also, is the shell handle the one from GetDesktopWindow? The desktop is the highest level parent. When I use spy++ I see that the explorer instance I have has a title of what ever directory it is in. That should help you differentiate.Legacy

© 2022 - 2024 — McMap. All rights reserved.