2013-07-29 51 views
1
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); 
       } 
     } 
} 

但它每次都会打开一个新窗口。我怎样才能做到这一点?C++在已打开的窗口中执行“打开”

回答

0

您通过的hwnd父母窗口。一般来说,你不能随意选择窗口来做你想做的任何事情。你给他们发送一条消息,如果他们理解了这条消息,他们会对此作出反应。例如。 WM_CLOSE几乎总是被理解,WM_COPYDATA较少。

在这种情况下,它有点复杂。您需要通过IShellWindows找到shell窗口。然后设法调用其IExplorerBrowser::BrowseToObject方法。但是这里有点太复杂,无法解释。