2
votes
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?

1

1 Answers

0
votes

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. E.g. 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.