@@ -122,6 +122,10 @@ HRESULT CSearchBar::GetSearchResultsFolder(IShellBrowser **ppShellBrowser, HWND
122122
123123LRESULT CSearchBar::OnSearchButtonClicked (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
124124{
125+ size_t len = 0 ;
126+ WCHAR endchar;
127+ WCHAR startchar;
128+
125129 CComHeapPtr<SearchStart> pSearchStart (static_cast <SearchStart *>(CoTaskMemAlloc (sizeof (SearchStart))));
126130 GetDlgItemText (IDC_SEARCH_FILENAME, pSearchStart->szFileName , _countof (pSearchStart->szFileName ));
127131 GetDlgItemText (IDC_SEARCH_QUERY, pSearchStart->szQuery , _countof (pSearchStart->szQuery ));
@@ -131,6 +135,30 @@ LRESULT CSearchBar::OnSearchButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndC
131135 return 0 ;
132136 }
133137
138+ // See if we have an szFileName by testing for its entry lenth > 0 and our searched FileName does not contain
139+ // an asterisk or a question mark. If so, then prepend and append an asterisk to the searched FileName.
140+ // (i.e. it's equivalent to searching for *<the_file_name>* )
141+ if (FAILED (StringCchLengthW (pSearchStart->szFileName , MAX_PATH, &len))) return 0 ;
142+ if ((len > 0 ) && !wcspbrk (pSearchStart->szFileName , L" *?" ))
143+ {
144+ endchar = pSearchStart->szFileName [len - 1 ];
145+ startchar = pSearchStart->szFileName [0 ];
146+ if ((len < MAX_PATH - 1 ) && (startchar != L' *' ))
147+ {
148+ memmove (&pSearchStart->szFileName [1 ], &pSearchStart->szFileName [0 ],
149+ len * sizeof (WCHAR) + sizeof (WCHAR));
150+ len = len + 1 ;
151+ pSearchStart->szFileName [0 ] = L' *' ;
152+ }
153+
154+ // See if our last character is an asterisk and if not and we have room then add one
155+ if ((len < MAX_PATH - 1 ) && (endchar != L' *' ))
156+ StringCchCatW (pSearchStart->szFileName , MAX_PATH, L" *" );
157+ }
158+
159+ // Print our final search string for szFileName
160+ TRACE (" Searched szFileName is '%S'.\n " , pSearchStart->szFileName );
161+
134162 CComPtr<IShellBrowser> pShellBrowser;
135163 HRESULT hr = IUnknown_QueryService (m_pSite, SID_SShellBrowser, IID_PPV_ARG (IShellBrowser, &pShellBrowser));
136164 if (FAILED_UNEXPECTEDLY (hr))
0 commit comments