+ if (FAILED(GetSearchResultsFolder(&pShellBrowser, &hwnd, NULL)))
+ {
+ // Open a new search results folder
+ 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;
+
+ CComHeapPtr<ITEMIDLIST> findFolderPidl;
+ hr = SHParseDisplayName(szShellGuid, NULL, &findFolderPidl, 0, NULL);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ hr = pShellBrowser->BrowseObject(findFolderPidl, 0);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ CComPtr<IShellFolder> pShellFolder;
+ hr = GetSearchResultsFolder(*pShellBrowser, &hwnd, &pShellFolder);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ // Subscribe to search events
+ DWORD fAdviseCookie;
+ hr = AtlAdvise(pShellFolder, static_cast<IDispatch *>(this), DIID_DSearchCommandEvents, &fAdviseCookie);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+ }
+
+ ::PostMessageW(hwnd, WM_SEARCH_START, 0, (LPARAM) pSearchStart.Detach());
+
+ SetSearchInProgress(TRUE);
+
+ return TRUE;
+}
+
+LRESULT CSearchBar::OnStopButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
+{
+ HWND hwnd;
+ HRESULT hr = GetSearchResultsFolder(NULL, &hwnd, NULL);
+ if (SUCCEEDED(hr))
+ ::PostMessageW(hwnd, WM_SEARCH_STOP, 0, 0);
+
+ return TRUE;
+}
+
+BOOL CSearchBar::GetAddressEditBoxPath(WCHAR (&szPath)[MAX_PATH])
+{
+ HWND hComboboxEx = GetDlgItem(IDC_SEARCH_COMBOBOX);
+ ::GetWindowTextW(hComboboxEx, szPath, _countof(szPath));
+ INT iSelectedIndex = SendMessageW(hComboboxEx, CB_GETCURSEL, 0, 0);
+ if (iSelectedIndex != CB_ERR)
+ {
+ WCHAR szItemText[MAX_PATH];
+ COMBOBOXEXITEMW item = {0};
+ item.mask = CBEIF_LPARAM | CBEIF_TEXT;
+ item.iItem = iSelectedIndex;
+ item.pszText = szItemText;
+ item.cchTextMax = _countof(szItemText);
+ SendMessageW(hComboboxEx, CBEM_GETITEMW, 0, (LPARAM)&item);
+
+ if (!wcscmp(szItemText, szPath) && SHGetPathFromIDListW((LPCITEMIDLIST)item.lParam, szPath))
+ {
+ return TRUE;
+ }
+ }
+
+ DWORD dwAttributes = GetFileAttributesW(szPath);
+ return dwAttributes != INVALID_FILE_ATTRIBUTES
+ && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY);
+}
+
+LRESULT CSearchBar::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
+{
+ INT iWidth = LOWORD(lParam);
+ INT iPadding = 10;