Download (ca. 235 KB)
There exists a good article on CodeProject that explains the usage of Windows Search API from a WPF application. However for my own purposes I needed an option using Windows Search in an unmanaged application (like MFC) and tapping it in a way like CRecordset (with its “lovely” Move()-methods) as well. So I wrote a new C++ class called CWindowsSearch that capsules the whole COM-stuff (retrieving the connection string and the SQL statement from ISearchQueryHelper) and the OleDB-mechanism (querying and fetching the data):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | CString lsSearch = _T("the search keyword"); CWindowsSearch lkWindowsSearch; // open search if ( !lkWindowsSearch.Open(lsSearch) ) return; // get results while ( lkWindowsSearch.MoveNext() ) { // do something CString lsName = lkWindowsSearch.GetItemName(); CString lsPath = lkWindowsSearch.GetItemPath(); } // close search lkWindowsSearch.Close(); |
I packed a demo application in this post that takes a search keyword from a CEdit and “prints” the results (found file name and path) as items into a CListCtrl. Double-click on an existing item and the application will open the corresponding file. You can download the ZIP archive above to get an idea of the internal functionality, espescially about the CWindowsSearch class.








0 Responses to “Using the Windows Search API From a MFC Application”