DTI-Matt
DTI-Matt

Reputation: 2145

Closing a Specific Instance of Windows Explorer

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

Upvotes: 3

Views: 1128

Answers (1)

Mike Cheel
Mike Cheel

Reputation: 13106

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

Upvotes: 1

Related Questions