gpt4 book ai didi

c++ - 搜索时在 IShellFolder/IShellFolder2 EnumObjects 实现上接收父窗口句柄?

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:57 25 4
gpt4 key购买 nike

在我正在处理的命名空间扩展项目中接收父窗口句柄让我抓狂。

用例如下:

  1. 用户通过windows资源管理器浏览到一个虚拟文件夹
  2. 用户执行搜索(上面的搜索框)
  3. 我需要在搜索开始前检索搜索框的文本。

我已经在带有 ISearchBoxInfo 接口(interface) ( https://msdn.microsoft.com/en-us/library/windows/desktop/dd562062%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 ) 的测试控制台应用程序上做到了这一点

我可以通过两种方式接收指向该接口(interface)的指针:

  1. 使用 IObjectWithSite::SetSite 调用 - 这不相关,因为搜索是在不同的线程中进行的,我无法在这些线程之间共享 COM 对象
  2. 识别窗口句柄并通过 IWebBrowser2 接口(interface)检索 ISearchBox。

这两种方法都不起作用,因为当我执行搜索时,EnumObjects 是通过不同的线程调用的,而且我无法找到一种方法来识别谁是父资源管理器窗口。

在做搜索的时候,来的hwnd总是null,如下: EnumObjects while searching

这是 EnumObjects 代码:

//  Allows a client to determine the contents of a folder by
// creating an item identifier enumeration object and returning
// its IEnumIDList interface. The methods supported by that
// interface can then be used to enumerate the folder's contents.
HRESULT CFolderViewImplFolder::EnumObjects(HWND hwnd, DWORD grfFlags, IEnumIDList **ppenumIDList)
{
HRESULT hr;
_fd = hwnd;

if (hwnd != NULL) // NULL when performing a search
{
const int n = GetWindowTextLength(hwnd);
wstring text(n + 1, L'#');
if (n > 0)
{
GetWindowText(hwnd, &text[0], text.length());
}
}

if (m_nLevel >= g_nMaxLevel)
{
*ppenumIDList = NULL;
hr = S_FALSE; // S_FALSE is allowed with NULL out param to indicate no contents.
}
else
{
CFolderViewImplEnumIDList *penum = new (std::nothrow) CFolderViewImplEnumIDList(grfFlags, m_nLevel + 1, this);
hr = penum ? S_OK : E_OUTOFMEMORY;
if (SUCCEEDED(hr))
{
hr = penum->Initialize();
if (SUCCEEDED(hr))
{
hr = penum->QueryInterface(IID_PPV_ARGS(ppenumIDList));
}
penum->Release();
}
}

return hr;
}

除了我的测试之外,因为我还实现了 IShellFolderViewCB.MessageSFVCB,它在正确的 线程上运行,我可以在其中检索 IShellBrowser,从而检索句柄 -当我进行搜索时,我遇到以下消息:

103, 103, 67, UnmergeMenu, WindowClosing, 106, ViewRelease, ViewRelease

之后,不再发布消息(无论我是否重新搜索)- 第一个断点总是在 EnumObjects 方法处,我没有关于父窗口的上下文。

任何光线脱落都会很好。

== 编辑 ==

我想出了一些解决方法 - 这并不适用于所有情况,但适用于大多数情况 - 其他选项仍然不错。

每当使用 hwnd = NULL 调用 EnumObjects 时,我都会执行以下操作:(它在 C# 中 - 但在 C++ 中也很容易实现)

static public string PrepareSearch(string currentFolderName, IntPtr hwnd)
{
SHDocVw.ShellWindows shellWindows = new ShellWindows();

SHDocVw.IWebBrowser2 foundBrowser = null;
bool wasFound = false;
string foundTxt = null;
foreach (SHDocVw.IWebBrowser2 eie in shellWindows)
{
// as the search is conducted in another thread, while the main window is "free" and in a search mode, it should be first busy.
string locName = eie.LocationName;
string exeName = eie.FullName;

if (!string.IsNullOrEmpty(exeName) && exeName.IndexOf("explorer.exe", StringComparison.OrdinalIgnoreCase) >= 0 &&
!string.IsNullOrEmpty(locName) &&
eie.Busy && eie.ReadyState == tagREADYSTATE.READYSTATE_LOADING)
{
// in here we're ok, we would also want to get the window title to make sure we're searching correctly.
string title = NSEFolder.WindowText((IntPtr)eie.HWND);

if (!string.IsNullOrEmpty(title) &&
title.IndexOf(currentFolderName) >= 0)
{
// one or more windows were found, ignore the quick search.
if (wasFound)
{
return null;
}

wasFound = true;
foundTxt = locName;
}

}
}

if (wasFound && !string.IsNullOrEmpty(foundTxt))
{
return foundTxt;

}


return null;
}

基本上我会遍历所有资源管理器窗口,试图找到一个确实是“explorer.exe”+ 非空搜索字符串 (LocationName) + 忙... + 标题包含当前文件夹名称的名称。

当 2 个窗口正忙并且标题中有相同​​的文件夹名称时,它将失败 - 但这可能已经足够了......这里不确定。

最佳答案

因此,在与微软交谈后 - 这样做是不可能的。我添加的解决方法是有效的(尽管并不完美)。

关于c++ - 搜索时在 IShellFolder/IShellFolder2 EnumObjects 实现上接收父窗口句柄?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48681833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com