From 363ddf9c70207baca4a7074d252550f7d1dc1a9f Mon Sep 17 00:00:00 2001 From: Brock Mammen Date: Sat, 20 Jul 2019 13:05:03 -0500 Subject: [PATCH] [SHELLFIND] Set status bar text after opening search results folder --- dll/win32/browseui/shellfind/CSearchBar.cpp | 106 +++++++++++++++----- dll/win32/browseui/shellfind/CSearchBar.h | 1 + 2 files changed, 80 insertions(+), 27 deletions(-) diff --git a/dll/win32/browseui/shellfind/CSearchBar.cpp b/dll/win32/browseui/shellfind/CSearchBar.cpp index 803521619ce..7efcd2bfe6d 100644 --- a/dll/win32/browseui/shellfind/CSearchBar.cpp +++ b/dll/win32/browseui/shellfind/CSearchBar.cpp @@ -112,6 +112,53 @@ LRESULT CSearchBar::OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bH return TRUE; } +HRESULT CSearchBar::GetSearchResultsFolder(IShellBrowser **ppShellBrowser, HWND *pHwnd, IShellFolder **ppShellFolder) +{ + HRESULT hr; + CComPtr pShellBrowser; + if (!ppShellBrowser) + ppShellBrowser = &pShellBrowser; + if (!*ppShellBrowser) + { + hr = IUnknown_QueryService(m_pSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, ppShellBrowser)); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + } + + CComPtr pShellView; + hr = (*ppShellBrowser)->QueryActiveShellView(&pShellView); + if (FAILED(hr) || !pShellView) + return hr; + + CComPtr pFolderView; + hr = pShellView->QueryInterface(IID_PPV_ARG(IFolderView, &pFolderView)); + if (FAILED(hr) || !pFolderView) + return hr; + + CComPtr pShellFolder; + if (!ppShellFolder) + ppShellFolder = &pShellFolder; + hr = pFolderView->GetFolder(IID_PPV_ARG(IShellFolder, ppShellFolder)); + if (FAILED(hr) || !pShellFolder) + return hr; + + CLSID clsid; + hr = IUnknown_GetClassID(*ppShellFolder, &clsid); + if (FAILED(hr)) + return hr; + if (clsid != CLSID_FindFolder) + return E_FAIL; + + if (pHwnd) + { + hr = pShellView->GetWindow(pHwnd); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + } + + return S_OK; +} + LRESULT CSearchBar::OnSearchButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { CComPtr pShellBrowser; @@ -119,41 +166,46 @@ LRESULT CSearchBar::OnSearchButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndC if (FAILED_UNEXPECTEDLY(hr)) return hr; - WCHAR szShellGuid[MAX_PATH]; - const WCHAR shellGuidPrefix[] = L"shell:::"; - memcpy(szShellGuid, shellGuidPrefix, sizeof(shellGuidPrefix)); - hr = StringFromGUID2(CLSID_FindFolder, szShellGuid + _countof(shellGuidPrefix) - 1, _countof(szShellGuid) - _countof(shellGuidPrefix)); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; + HWND hwnd; + if (FAILED(GetSearchResultsFolder(&pShellBrowser, &hwnd, NULL))) + { + WCHAR szShellGuid[MAX_PATH]; + const WCHAR shellGuidPrefix[] = L"shell:::"; + memcpy(szShellGuid, shellGuidPrefix, sizeof(shellGuidPrefix)); + hr = StringFromGUID2(CLSID_FindFolder, szShellGuid + _countof(shellGuidPrefix) - 1, + _countof(szShellGuid) - _countof(shellGuidPrefix)); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; - LPITEMIDLIST findFolderPidl; - hr = SHParseDisplayName(szShellGuid, NULL, &findFolderPidl, 0, NULL); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; + LPITEMIDLIST findFolderPidl; + hr = SHParseDisplayName(szShellGuid, NULL, &findFolderPidl, 0, NULL); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; - return pShellBrowser->BrowseObject(findFolderPidl, 0); + hr = pShellBrowser->BrowseObject(findFolderPidl, 0); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + } + + GetSearchResultsFolder(&pShellBrowser, &hwnd, NULL); + if (hwnd) + // TODO: Use message ID in header file + ::PostMessageW(hwnd, WM_USER + 1, 0, (LPARAM) StrDupW(L"Starting search...")); + + return S_OK; } LRESULT CSearchBar::OnClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { - HRESULT hr; - CComPtr pShellBrowser; - hr = IUnknown_QueryService(pSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pShellBrowser)); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - CComPtr pShellView; - hr = pShellBrowser->QueryActiveShellView(&pShellView); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; HWND hwnd; - hr = pShellView->GetWindow(&hwnd); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; + HRESULT hr = GetSearchResultsFolder(NULL, &hwnd, NULL); + if (SUCCEEDED(hr)) + { + LPCWSTR path = L"C:\\readme.txt"; + // TODO: Use message ID in header file + ::PostMessageW(hwnd, WM_USER, 0, (LPARAM) StrDupW(path)); + } - LPWSTR path = (LPWSTR) L"C:\\readme.txt"; - - // TODO: Use message ID in header file - ::PostMessageW(hwnd, WM_USER, 0, (LPARAM) StrDupW(path)); return 0; } diff --git a/dll/win32/browseui/shellfind/CSearchBar.h b/dll/win32/browseui/shellfind/CSearchBar.h index 3bef4202bab..fd84b0c58f1 100644 --- a/dll/win32/browseui/shellfind/CSearchBar.h +++ b/dll/win32/browseui/shellfind/CSearchBar.h @@ -43,6 +43,7 @@ private: BOOL bFocused; void InitializeSearchBar(); + HRESULT GetSearchResultsFolder(IShellBrowser **ppShellBrowser, HWND *pHwnd, IShellFolder **ppShellFolder); HRESULT ExecuteCommand(CComPtr& menu, UINT nCmd); // *** ATL event handlers ***