0

我需要检索最活跃的 Windows Explorer 实例的完整路径。

所以我通过调用 HWND l_pExplorerhwnd = ::GetForegroundWindow(); 得到了 Explorer.exe 的句柄。

使用检索到的这个句柄,我需要检索它的地址栏编辑控件。我使用了 Spy++ 并将编辑控件的类名设置为 ToolbarWindow32

现在,我尝试使用以下代码片段使用 FindWindowEx 查找窗口。但我无法找回它。请帮忙

  HWND l_pExplorerhwnd = ::GetForegroundWindow();
  TCHAR l_szTempName[MAX_PATH];

  if(l_pExplorerhwnd)
  {
    ::GetWindowModuleFileName(l_pExplorerhwnd, l_szTempName, MAX_PATH);
    MessageBox(0, l_szTempName, 0, 0);
    if(::FindWindowEx(l_pExplorerhwnd, NULL, L"ToolbarWindow32", NULL))
    {
      ::GetWindowText(::FindWindowEx(l_pExplorerhwnd, NULL, L"ToolbarWindow32", NULL), l_szTempName, MAX_PATH);
      MessageBox(0, l_szTempName, 0, 0);
    }
    else
    {
      MessageBox(0, L"Error Error ", 0, 0);
    }
  }
  else
  {
    MessageBox(0, L"Error Error Error", 0, 0);
  }
4

1 回答 1

0

要直接回答您的问题,FindWindowEx适用于父窗口的直接子级,而不是后代。因此,您需要一个一个地遍历孩子:

CabinetWClass
WorkerW
ReBarWindow32
Address Band Root
msctls_progress32
Breadcrumb Parent
ToolbarWindow32

Note that this hierarchy is only what it is on my system right now. As mentioned by Tom Whittock, it would be very bad practice to use this. You have no idea whether the window hierarchy could change across updates, or even by design at runtime.

One more comment about your code. Since you are using TCHAR mappings (even though there is usually no reason to use it now unless you are intending to support Win98-), your string literals should be _T("") instead of L"".

于 2012-04-05T13:54:10.963 回答