I'm trying to open a new folder in the same window that is already opened. This is the code:
if (DirectoryExists(myfolder)) {
HWND currenthwnd,hwnd;
hwnd=NULL;
currenthwnd=GetForegroundWindow();
if (currenthwnd!=hwnd)
{
hwnd=currenthwnd;
if (hwnd!=NULL)
{
ShellExecute(hwnd, "open", myfolder, NULL, NULL, SW_SHOW);
}
}
}
But it opens a new window everytime. How can I achieve this?
The hwnd
which you pass is the parent window. In general you can't get random windows to do anything you want them too. You send them a message, and if they understand the message they'll react to it. Eg WM_CLOSE
is almost always understood, WM_COPYDATA
less often.
In this case, it's a bit more complex. You need to find the shell window via IShellWindows
. and then manage to call its IExplorerBrowser::BrowseToObject
method. But that's a bit too complex to explain here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.