Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 26 |
Nodes: | 6 (0 / 6) |
Uptime: | 51:33:31 |
Calls: | 632 |
Files: | 1,187 |
D/L today: |
21 files (18,502K bytes) |
Messages: | 178,040 |
Hello all,
I'm in a bit of picle : I'm using user32.dll's ShellExecute to open another file explorer window, which I than want to move around.
The problem is that ShellExecute doesn't seem to return a handle to the just-created explorer window (if someone knows how to get it from ShellExecute I would like to know!).
So, I'm using FindWindowEx to find the file-explorer window. Alas, it doesn't find the window if its created mimimized.
Question: how do I find a (or rather: the last-created) file-explorer window, minimized or not ?
I've just been googeling, but am not getting any results (pertaining to the problem. Lots of others though. :-( )
Regards,
Rudy Wieser
On Tue, 10/7/2025 4:12 AM, R.Wieser wrote:
Hello all,
I'm in a bit of picle : I'm using user32.dll's ShellExecute to open another >> file explorer window, which I than want to move around.
The problem is that ShellExecute doesn't seem to return a handle to the
just-created explorer window (if someone knows how to get it from
ShellExecute I would like to know!).
So, I'm using FindWindowEx to find the file-explorer window. Alas, it
doesn't find the window if its created mimimized.
Question: how do I find a (or rather: the last-created) file-explorer
window, minimized or not ?
I've just been googeling, but am not getting any results (pertaining to the >> problem. Lots of others though. :-( )
Regards,
Rudy Wieser
Probably quicker to pop it in the Toaster, and see what comes out.
CoPilot
-------
I'm using user32.dll's ShellExecute to open another
file explorer window, which I then want to move around.
ShellExecute does not seem to return a handle to the just-created explorer window.
Using FindWindowEx, if the File Explorer window is minimized, I cannot find the window.
How do I find this (last-created) file-explorer window, whether it is minimized or not ?
Returned Answer
---------------
[Picture]
Probably quicker to pop it in the Toaster, and see what comes out....
Instead of relying on 'ShellExecute', switch to 'ShellExecuteEx' or 'CreateProcess' to get the process ID (PID) of the launched explorer instance. Then, enumerate all top-level windows and match them to...
that PID.
Windows may reuse an existing 'explorer.exe' process,
so launching a new one doesn't always mean a new PID. You might
need to monitor window creation events or use a timestamp to
correlate.
Hello all,
I'm in a bit of picle : I'm using user32.dll's ShellExecute to open another file explorer window, which I than want to move around.
The problem is that ShellExecute doesn't seem to return a handle to the just-created explorer window (if someone knows how to get it from ShellExecute I would like to know!).
So, I'm using FindWindowEx to find the file-explorer window. Alas, it doesn't find the window if its created mimimized.
Question: how do I find a (or rather: the last-created) file-explorer window, minimized or not ?
I've just been googeling, but am not getting any results (pertaining to the problem. Lots of others though. :-( )
Regards,
Rudy Wieser
Paul,
Probably quicker to pop it in the Toaster, and see what comes out....
Instead of relying on 'ShellExecute', switch to 'ShellExecuteEx' or...
'CreateProcess' to get the process ID (PID) of the launched explorer
instance. Then, enumerate all top-level windows and match them to
that PID.
Windows may reuse an existing 'explorer.exe' process,
so launching a new one doesn't always mean a new PID. You might
need to monitor window creation events or use a timestamp to
correlate.
:-) I did not need an AI to find the information mentioned in the second paragraph.
After failing to get it to work reliably I also found the "doesn't always return a new PID" information as mentioned in the third paragraph. Which
is why I dropped it.
As for monitoring the window creation events ? Why now do I get the
feeling that that is just leading to /at least/ double the problems that
such a method would solve ? :-|
As for "use a timestamp" ? That sounds interresting, but I've never heard that a created window exposes a timestamp...
I'll probably revisit the problem though, even just to see if I missed something.
Regards,
Rudy Wieser
Hello all,
I'm in a bit of picle : I'm using user32.dll's ShellExecute to open another file explorer window, which I than want to move around.
The problem is that ShellExecute doesn't seem to return a handle to the just-created explorer window (if someone knows how to get it from ShellExecute I would like to know!).
So, I'm using FindWindowEx to find the file-explorer window. Alas, it doesn't find the window if its created mimimized.
Question: how do I find a (or rather: the last-created) file-explorer window, minimized or not ?
I've just been googeling, but am not getting any results (pertaining to the problem. Lots of others though. :-( )
Regards,
Rudy Wieser
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindoww
Says the returned value is the HWND of the newly created window,
or NULL if it failed.
https://learn.microsoft.com/en-us/windows/win32/learnwin32/creating-a-window
That also states the returned value for CreateWindowEx is HWND if the
open worked, NULL if it failed.
https://stackoverflow.com/questions/7620322/get-pid-from-shellexecute
looks like you need to preset a flag, and then use GetProcessID to get
the PID.
https://forums.codeguru.com/showthread.php?467956-RESOLVED-ShellExecute-and-PID
That mentions using ShellExecuteEx to get the PID. Then:
https://stackoverflow.com/questions/11711417/get-hwnd-by-process-id-c
mentions how to get the window handle(s) for a PID.
The main value of the AI answer is the breadcrumbs.
You have to *prove* any theories offered, hold water.
Returned Answer...
if (ShellExecuteEx(&sei)) {
DWORD pid = GetProcessId(sei.hProcess);
// Now use this PID to find the window
}
```
2. Enumerate all top-level windows and match the PID:
'''cpp
HWND targetHwnd = nullptr;
EnumWindows([](HWND hwnd, LPARAM lParam) -> BOOL {
DWORD windowPid;
GetWindowThreadProcessId(hwnd, &windowPid);
if (windowPid == (DWORD)lParam) {
// Optional: Check if it's an Explorer window
wchar_t className[256];
GetClassName(hwnd, className,
sizeof(className)/sizeof(wchar_t));
if (wcscmp(className, L"CabinetWClass") == 0 ||
wcscmp(className, L"ExplorerWClass") == 0) {
targetHwnd = hwnd;
return FALSE; // Stop enumeration
}
}
return TRUE;
}, (LPARAM)pid);
```
2. Enumerate all top-level windows and match the PID:
'''cpp
HWND targetHwnd = nullptr;
EnumWindows([](HWND hwnd, LPARAM lParam) -> BOOL {
DWORD windowPid;
GetWindowThreadProcessId(hwnd, &windowPid);
if (windowPid == (DWORD)lParam) {
// Optional: Check if it's an Explorer window
wchar_t className[256];
GetClassName(hwnd, className,
sizeof(className)/sizeof(wchar_t));
if (wcscmp(className, L"CabinetWClass") == 0 ||
wcscmp(className, L"ExplorerWClass") == 0) {
targetHwnd = hwnd;
return FALSE; // Stop enumeration
}
}
return TRUE;
}, (LPARAM)pid);
On Tue, 7 Oct 2025 10:12:54 +0200, R.Wieser wrote:
Hello all,
I'm in a bit of picle : I'm using user32.dll's ShellExecute to open another >> file explorer window, which I than want to move around.
The problem is that ShellExecute doesn't seem to return a handle to the
just-created explorer window (if someone knows how to get it from
ShellExecute I would like to know!).
So, I'm using FindWindowEx to find the file-explorer window. Alas, it
doesn't find the window if its created mimimized.
Question: how do I find a (or rather: the last-created) file-explorer
window, minimized or not ?
I've just been googeling, but am not getting any results (pertaining to the >> problem. Lots of others though. :-( )
Regards,
Rudy Wieser
Use `Shell.Application` COM object to enumerate all explorer windows. Minimized or not, and hidden or not. Do like what it does, if COM usage is not applicable/acceptable.
The problem is that launching (directly or indirectly) explorer.exe may randomly cause the launched explorer process to pass the request to any of the already running explorer.exe processes, in which case the problem is
to determine /which one/ of the explorer windows owned by the various explorer.exe processes pertains to the request just made to ShellExecuteEx().
Jakob, others,
The problem is that launching (directly or indirectly) explorer.exe may
randomly cause the launched explorer process to pass the request to any of >> the already running explorer.exe processes, in which case the problem is
to determine /which one/ of the explorer windows owned by the various
explorer.exe processes pertains to the request just made to
ShellExecuteEx().
As mentioned, I *never* get a process handle back which has an explorer window (might be because I'm using WinXP), so I just scan all the windows. It doesn't make a difference (just takes a bit more time).
Also, ShellExecute(Ex) may return well before the actual window has been created (regardles of the SEE_MASK_WAITFORINPUTIDLE flag application).
One other problem I found is that when I get a CabinetWClass window the next attempt to open the same folder doesn't create a new window, but just (restores and) focusses the old one.
And something I overlooked : You cannot tell a minimized (or maximized) window to move around.
Bottom line: I have to create the new explorer window normally, move it around and only than, if wanted, minimize it.
have you maybe tried FindWindow?
If you know the exact title bar text it should work.
(if you don't open the same folder window twice...)