m_hWnd, NULL,
_AtlBaseModule.GetModuleInstance(), NULL);
- CreateWindowExW(0, WC_STATIC, L"A &word or phrase in the file:",
+ CreateWindowExW(0, WC_STATIC, L"All or part &of the file name:",
WS_CHILD | WS_VISIBLE,
10, 50, 500, 20,
m_hWnd, NULL,
_AtlBaseModule.GetModuleInstance(), NULL);
- CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
+ m_fileName = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
WS_BORDER | WS_CHILD | WS_VISIBLE,
10, 70, 100, 20,
m_hWnd, NULL,
_AtlBaseModule.GetModuleInstance(), NULL);
- CreateWindowExW(0, WC_STATIC, L"&Look in:",
+ CreateWindowExW(0, WC_STATIC, L"A &word or phrase in the file:",
WS_CHILD | WS_VISIBLE,
10, 100, 500, 20,
m_hWnd, NULL,
_AtlBaseModule.GetModuleInstance(), NULL);
- CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
+ m_query = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
WS_BORDER | WS_CHILD | WS_VISIBLE,
10, 120, 100, 20,
m_hWnd, NULL,
_AtlBaseModule.GetModuleInstance(), NULL);
+ Edit_LimitText(m_query, MAX_PATH);
+
+ CreateWindowExW(0, WC_STATIC, L"&Look in:",
+ WS_CHILD | WS_VISIBLE,
+ 10, 150, 500, 20,
+ m_hWnd, NULL,
+ _AtlBaseModule.GetModuleInstance(), NULL);
+ m_path = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
+ WS_BORDER | WS_CHILD | WS_VISIBLE,
+ 10, 180, 100, 20,
+ m_hWnd, NULL,
+ _AtlBaseModule.GetModuleInstance(), NULL);
CreateWindowExW(0, WC_BUTTON, L"Sea&rch",
WS_BORDER | WS_CHILD | WS_VISIBLE,
- 10, 150, 100, 20,
+ 10, 210, 100, 20,
m_hWnd, NULL,
_AtlBaseModule.GetModuleInstance(), NULL);
}
return TRUE;
}
-LRESULT CSearchBar::OnSearchButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
+HRESULT CSearchBar::GetSearchResultsFolder(IShellBrowser **ppShellBrowser, HWND *pHwnd, IShellFolder **ppShellFolder)
{
+ HRESULT hr;
CComPtr<IShellBrowser> pShellBrowser;
- HRESULT hr = IUnknown_QueryService(pSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pShellBrowser));
- if (FAILED_UNEXPECTEDLY(hr))
+ 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<IShellView> pShellView;
+ hr = (*ppShellBrowser)->QueryActiveShellView(&pShellView);
+ if (FAILED(hr) || !pShellView)
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))
+ CComPtr<IFolderView> pFolderView;
+ hr = pShellView->QueryInterface(IID_PPV_ARG(IFolderView, &pFolderView));
+ if (FAILED(hr) || !pFolderView)
return hr;
- LPITEMIDLIST findFolderPidl;
- hr = SHParseDisplayName(szShellGuid, NULL, &findFolderPidl, 0, NULL);
- if (FAILED_UNEXPECTEDLY(hr))
+ CComPtr<IShellFolder> pShellFolder;
+ if (!ppShellFolder)
+ ppShellFolder = &pShellFolder;
+ hr = pFolderView->GetFolder(IID_PPV_ARG(IShellFolder, ppShellFolder));
+ if (FAILED(hr) || !pShellFolder)
return hr;
- return pShellBrowser->BrowseObject(findFolderPidl, 0);
+ 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::OnClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
+LRESULT CSearchBar::OnSearchButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
- HRESULT hr;
CComPtr<IShellBrowser> pShellBrowser;
- hr = IUnknown_QueryService(pSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pShellBrowser));
- if (FAILED_UNEXPECTEDLY(hr))
- return hr;
- CComPtr<IShellView> pShellView;
- hr = pShellBrowser->QueryActiveShellView(&pShellView);
+ HRESULT hr = IUnknown_QueryService(pSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pShellBrowser));
if (FAILED_UNEXPECTEDLY(hr))
return hr;
+
HWND hwnd;
- hr = pShellView->GetWindow(&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;
+
+ 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;
+ }
+
+ hr = GetSearchResultsFolder(*pShellBrowser, &hwnd, NULL);
if (FAILED_UNEXPECTEDLY(hr))
return hr;
- LPWSTR path = (LPWSTR) L"C:\\readme.txt";
+ ::PostMessageW(hwnd, WM_SEARCH_START, 0, (LPARAM) StrDupW(L"Starting search..."));
+
+ return S_OK;
+}
+
+LRESULT CSearchBar::OnClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
+{
+ HWND hwnd;
+ HRESULT hr = GetSearchResultsFolder(NULL, &hwnd, NULL);
+ if (SUCCEEDED(hr))
+ {
+ LPCWSTR path = L"C:\\readme.txt";
+ ::PostMessageW(hwnd, WM_SEARCH_ADD_RESULT, 0, (LPARAM) StrDupW(path));
+ }
- // TODO: Use message ID in header file
- ::PostMessageW(hwnd, WM_USER, 0, (LPARAM) StrDupW(path));
return 0;
}