找不到Window Explorer

时间:2013-08-09 09:26:03

标签: c++ windows vc6

我在XP系统上使用VC6。我想找到一个标题与“C:\”匹配的窗口,但找不到它。 hr的返回值是-2147023116。有人可以帮忙吗?

HWND hwnd = FindWindow(NULL, "C:\\");
IWebBrowserApp *pwba;
HWND hwndindex = NULL;
HRESULT hr = pwba->get_HWND((long*)hwndindex);
if (hwnd == hwndindex)
{
  BOOL found = true;
  blablabla...
}

2 个答案:

答案 0 :(得分:2)

下面的代码应该有效:

INT iIndex = 1;
HWND hwnd = ::GetWindow( ::GetDesktopWindow(), GW_CHILD | GW_HWNDFIRST );
while( hwnd ) {
  CString sCaption; 
  ::GetWindowText(hwnd, sCaption.GetBuffer(256), 255);
  sCaption.ReleaseBuffer();

  //DWORD dwProcessID = 0L;
  //::GetWindowThreadProcessId(hwnd, &dwProcessID);   

  //CString sExePath;
  //::GetModuleFileName((HMODULE)dwProcessID, sExePath.GetBuffer(MAX_PATH), MAX_PATH);
  //sExePath.ReleaseBuffer();

  if ( sCaption.Find(_T("c:\\")) != -1 ) {  
        // found you!
  }

  hwnd = ::GetWindow( hwnd, GW_HWNDNEXT );
}

答案 1 :(得分:0)

HRESULT hr = pwba->get_HWND((long*)&hwndindex);

问题解决了!我错过了一个重要的“&”