Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfind.c
Go to the documentation of this file.
00001 /* 00002 * Regedit find dialog 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 */ 00018 00019 00020 #include <regedit.h> 00021 00022 #define RSF_WHOLESTRING 0x00000001 00023 #define RSF_LOOKATKEYS 0x00000002 00024 #define RSF_LOOKATVALUES 0x00000004 00025 #define RSF_LOOKATDATA 0x00000008 00026 #define RSF_MATCHCASE 0x00010000 00027 00028 static TCHAR s_szFindWhat[256]; 00029 static const TCHAR s_szFindFlags[] = _T("FindFlags"); 00030 static const TCHAR s_szFindFlagsR[] = _T("FindFlagsReactOS"); 00031 static HWND s_hwndAbortDialog; 00032 static BOOL s_bAbort; 00033 00034 static DWORD s_dwFlags; 00035 static TCHAR s_szName[MAX_PATH]; 00036 static DWORD s_cbName; 00037 static const TCHAR s_empty[] = {0}; 00038 static const TCHAR s_backslash[] = {'\\', 0}; 00039 00040 extern VOID SetValueName(HWND hwndLV, LPCTSTR pszValueName); 00041 00042 BOOL DoEvents(VOID) 00043 { 00044 MSG msg; 00045 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 00046 { 00047 if (msg.message == WM_QUIT) 00048 s_bAbort = TRUE; 00049 if (!IsDialogMessage(s_hwndAbortDialog, &msg)) 00050 { 00051 TranslateMessage(&msg); 00052 DispatchMessage(&msg); 00053 } 00054 } 00055 return s_bAbort; 00056 } 00057 00058 static LPTSTR lstrstri(LPCTSTR psz1, LPCTSTR psz2) 00059 { 00060 INT i, cch1, cch2; 00061 00062 cch1 = lstrlen(psz1); 00063 cch2 = lstrlen(psz2); 00064 for(i = 0; i <= cch1 - cch2; i++) 00065 { 00066 if (CompareString(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, 00067 psz1 + i, cch2, psz2, cch2) == 2) 00068 return (LPTSTR) (psz1 + i); 00069 } 00070 return NULL; 00071 } 00072 00073 static BOOL CompareName(LPCTSTR pszName1, LPCTSTR pszName2) 00074 { 00075 if (s_dwFlags & RSF_WHOLESTRING) 00076 { 00077 if (s_dwFlags & RSF_MATCHCASE) 00078 return lstrcmp(pszName1, pszName2) == 0; 00079 else 00080 return lstrcmpi(pszName1, pszName2) == 0; 00081 } 00082 else 00083 { 00084 if (s_dwFlags & RSF_MATCHCASE) 00085 return _tcsstr(pszName1, pszName2) != NULL; 00086 else 00087 return lstrstri(pszName1, pszName2) != NULL; 00088 } 00089 } 00090 00091 static BOOL 00092 CompareData( 00093 DWORD dwType, 00094 LPCTSTR psz1, 00095 LPCTSTR psz2) 00096 { 00097 INT i, cch1 = lstrlen(psz1), cch2 = lstrlen(psz2); 00098 if (dwType == REG_SZ || dwType == REG_EXPAND_SZ) 00099 { 00100 if (s_dwFlags & RSF_WHOLESTRING) 00101 { 00102 if (s_dwFlags & RSF_MATCHCASE) 00103 return 2 == CompareString(LOCALE_SYSTEM_DEFAULT, 0, 00104 psz1, cch1, psz2, cch2); 00105 else 00106 return 2 == CompareString(LOCALE_SYSTEM_DEFAULT, 00107 NORM_IGNORECASE, psz1, cch1, psz2, cch2); 00108 } 00109 00110 for(i = 0; i <= cch1 - cch2; i++) 00111 { 00112 if (s_dwFlags & RSF_MATCHCASE) 00113 { 00114 if (2 == CompareString(LOCALE_SYSTEM_DEFAULT, 0, 00115 psz1 + i, cch2, psz2, cch2)) 00116 return TRUE; 00117 } 00118 else 00119 { 00120 if (2 == CompareString(LOCALE_SYSTEM_DEFAULT, 00121 NORM_IGNORECASE, psz1 + i, cch2, psz2, cch2)) 00122 return TRUE; 00123 } 00124 } 00125 } 00126 return FALSE; 00127 } 00128 00129 int compare(const void *x, const void *y) 00130 { 00131 const LPCTSTR *a = (const LPCTSTR *)x; 00132 const LPCTSTR *b = (const LPCTSTR *)y; 00133 return lstrcmpi(*a, *b); 00134 } 00135 00136 BOOL RegFindRecurse( 00137 HKEY hKey, 00138 LPCTSTR pszSubKey, 00139 LPCTSTR pszValueName, 00140 LPTSTR *ppszFoundSubKey, 00141 LPTSTR *ppszFoundValueName) 00142 { 00143 HKEY hSubKey; 00144 LONG lResult; 00145 TCHAR szSubKey[MAX_PATH]; 00146 DWORD i, c, cb, type; 00147 BOOL fPast = FALSE; 00148 LPTSTR *ppszNames = NULL; 00149 LPBYTE pb = NULL; 00150 00151 if (DoEvents()) 00152 return FALSE; 00153 00154 lstrcpy(szSubKey, pszSubKey); 00155 hSubKey = NULL; 00156 00157 lResult = RegOpenKeyEx(hKey, szSubKey, 0, KEY_ALL_ACCESS, &hSubKey); 00158 if (lResult != ERROR_SUCCESS) 00159 return FALSE; 00160 00161 if (pszValueName == NULL) 00162 pszValueName = s_empty; 00163 00164 lResult = RegQueryInfoKey(hSubKey, NULL, NULL, NULL, NULL, NULL, NULL, 00165 &c, NULL, NULL, NULL, NULL); 00166 if (lResult != ERROR_SUCCESS) 00167 goto err; 00168 ppszNames = (LPTSTR *) malloc(c * sizeof(LPTSTR)); 00169 if (ppszNames == NULL) 00170 goto err; 00171 ZeroMemory(ppszNames, c * sizeof(LPTSTR)); 00172 00173 for(i = 0; i < c; i++) 00174 { 00175 if (DoEvents()) 00176 goto err; 00177 00178 s_cbName = MAX_PATH * sizeof(TCHAR); 00179 lResult = RegEnumValue(hSubKey, i, s_szName, &s_cbName, NULL, NULL, 00180 NULL, &cb); 00181 if (lResult == ERROR_NO_MORE_ITEMS) 00182 { 00183 c = i; 00184 break; 00185 } 00186 if (lResult != ERROR_SUCCESS) 00187 goto err; 00188 if (s_cbName >= MAX_PATH * sizeof(TCHAR)) 00189 continue; 00190 00191 ppszNames[i] = _tcsdup(s_szName); 00192 } 00193 00194 qsort(ppszNames, c, sizeof(LPTSTR), compare); 00195 00196 for(i = 0; i < c; i++) 00197 { 00198 if (DoEvents()) 00199 goto err; 00200 00201 if (!fPast && lstrcmpi(ppszNames[i], pszValueName) == 0) 00202 { 00203 fPast = TRUE; 00204 continue; 00205 } 00206 if (!fPast) 00207 continue; 00208 00209 if ((s_dwFlags & RSF_LOOKATVALUES) && 00210 CompareName(ppszNames[i], s_szFindWhat)) 00211 { 00212 *ppszFoundSubKey = _tcsdup(szSubKey); 00213 if (ppszNames[i][0] == 0) 00214 *ppszFoundValueName = NULL; 00215 else 00216 *ppszFoundValueName = _tcsdup(ppszNames[i]); 00217 goto success; 00218 } 00219 00220 lResult = RegQueryValueEx(hSubKey, ppszNames[i], NULL, &type, 00221 NULL, &cb); 00222 if (lResult != ERROR_SUCCESS) 00223 goto err; 00224 pb = malloc(cb); 00225 if (pb == NULL) 00226 goto err; 00227 lResult = RegQueryValueEx(hSubKey, ppszNames[i], NULL, &type, 00228 pb, &cb); 00229 if (lResult != ERROR_SUCCESS) 00230 goto err; 00231 00232 if ((s_dwFlags & RSF_LOOKATDATA) && 00233 CompareData(type, (LPTSTR) pb, s_szFindWhat)) 00234 { 00235 *ppszFoundSubKey = _tcsdup(szSubKey); 00236 if (ppszNames[i][0] == 0) 00237 *ppszFoundValueName = NULL; 00238 else 00239 *ppszFoundValueName = _tcsdup(ppszNames[i]); 00240 goto success; 00241 } 00242 free(pb); 00243 pb = NULL; 00244 } 00245 00246 if (ppszNames != NULL) 00247 { 00248 for(i = 0; i < c; i++) 00249 free(ppszNames[i]); 00250 free(ppszNames); 00251 } 00252 ppszNames = NULL; 00253 00254 lResult = RegQueryInfoKey(hSubKey, NULL, NULL, NULL, &c, NULL, NULL, 00255 NULL, NULL, NULL, NULL, NULL); 00256 if (lResult != ERROR_SUCCESS) 00257 goto err; 00258 ppszNames = (LPTSTR *) malloc(c * sizeof(LPTSTR)); 00259 if (ppszNames == NULL) 00260 goto err; 00261 ZeroMemory(ppszNames, c * sizeof(LPTSTR)); 00262 00263 for(i = 0; i < c; i++) 00264 { 00265 if (DoEvents()) 00266 goto err; 00267 00268 s_cbName = MAX_PATH * sizeof(TCHAR); 00269 lResult = RegEnumKeyEx(hSubKey, i, s_szName, &s_cbName, NULL, NULL, 00270 NULL, NULL); 00271 if (lResult == ERROR_NO_MORE_ITEMS) 00272 { 00273 c = i; 00274 break; 00275 } 00276 if (lResult != ERROR_SUCCESS) 00277 goto err; 00278 if (s_cbName >= MAX_PATH * sizeof(TCHAR)) 00279 continue; 00280 00281 ppszNames[i] = _tcsdup(s_szName); 00282 } 00283 00284 qsort(ppszNames, c, sizeof(LPTSTR), compare); 00285 00286 for(i = 0; i < c; i++) 00287 { 00288 if (DoEvents()) 00289 goto err; 00290 00291 if ((s_dwFlags & RSF_LOOKATKEYS) && 00292 CompareName(ppszNames[i], s_szFindWhat)) 00293 { 00294 *ppszFoundSubKey = malloc( 00295 (lstrlen(szSubKey) + lstrlen(ppszNames[i]) + 2) * 00296 sizeof(TCHAR)); 00297 if (*ppszFoundSubKey == NULL) 00298 goto err; 00299 if (szSubKey[0]) 00300 { 00301 lstrcpy(*ppszFoundSubKey, szSubKey); 00302 lstrcatW(*ppszFoundSubKey, s_backslash); 00303 } 00304 else 00305 **ppszFoundSubKey = 0; 00306 lstrcatW(*ppszFoundSubKey, ppszNames[i]); 00307 *ppszFoundValueName = NULL; 00308 goto success; 00309 } 00310 00311 if (RegFindRecurse(hSubKey, ppszNames[i], NULL, ppszFoundSubKey, 00312 ppszFoundValueName)) 00313 { 00314 LPTSTR psz = *ppszFoundSubKey; 00315 *ppszFoundSubKey = malloc( 00316 (lstrlen(szSubKey) + lstrlen(psz) + 2) * sizeof(TCHAR)); 00317 if (*ppszFoundSubKey == NULL) 00318 goto err; 00319 if (szSubKey[0]) 00320 { 00321 lstrcpy(*ppszFoundSubKey, szSubKey); 00322 lstrcatW(*ppszFoundSubKey, s_backslash); 00323 } 00324 else 00325 **ppszFoundSubKey = 0; 00326 lstrcatW(*ppszFoundSubKey, psz); 00327 free(psz); 00328 goto success; 00329 } 00330 } 00331 00332 err: 00333 if (ppszNames != NULL) 00334 { 00335 for(i = 0; i < c; i++) 00336 free(ppszNames[i]); 00337 free(ppszNames); 00338 } 00339 free(pb); 00340 RegCloseKey(hSubKey); 00341 return FALSE; 00342 00343 success: 00344 if (ppszNames != NULL) 00345 { 00346 for(i = 0; i < c; i++) 00347 free(ppszNames[i]); 00348 free(ppszNames); 00349 } 00350 RegCloseKey(hSubKey); 00351 return TRUE; 00352 } 00353 00354 BOOL RegFindWalk( 00355 HKEY * phKey, 00356 LPCTSTR pszSubKey, 00357 LPCTSTR pszValueName, 00358 LPTSTR *ppszFoundSubKey, 00359 LPTSTR *ppszFoundValueName) 00360 { 00361 LONG lResult; 00362 DWORD i, c; 00363 HKEY hBaseKey, hSubKey; 00364 TCHAR szKeyName[MAX_PATH]; 00365 TCHAR szSubKey[MAX_PATH]; 00366 LPTSTR pch; 00367 BOOL fPast; 00368 LPTSTR *ppszNames = NULL; 00369 00370 hBaseKey = *phKey; 00371 if (RegFindRecurse(hBaseKey, pszSubKey, pszValueName, ppszFoundSubKey, 00372 ppszFoundValueName)) 00373 return TRUE; 00374 00375 if (lstrlen(pszSubKey) >= MAX_PATH) 00376 return FALSE; 00377 00378 lstrcpy(szSubKey, pszSubKey); 00379 while(szSubKey[0] != 0) 00380 { 00381 if (DoEvents()) 00382 return FALSE; 00383 00384 pch = _tcsrchr(szSubKey, _T('\\')); 00385 if (pch == NULL) 00386 { 00387 lstrcpy(szKeyName, szSubKey); 00388 szSubKey[0] = 0; 00389 hSubKey = hBaseKey; 00390 } 00391 else 00392 { 00393 lstrcpyn(szKeyName, pch + 1, MAX_PATH); 00394 *pch = 0; 00395 lResult = RegOpenKeyEx(hBaseKey, szSubKey, 0, KEY_ALL_ACCESS, 00396 &hSubKey); 00397 if (lResult != ERROR_SUCCESS) 00398 return FALSE; 00399 } 00400 00401 lResult = RegQueryInfoKey(hSubKey, NULL, NULL, NULL, &c, NULL, NULL, 00402 NULL, NULL, NULL, NULL, NULL); 00403 if (lResult != ERROR_SUCCESS) 00404 goto err; 00405 00406 ppszNames = (LPTSTR *) malloc(c * sizeof(LPTSTR)); 00407 if (ppszNames == NULL) 00408 goto err; 00409 ZeroMemory(ppszNames, c * sizeof(LPTSTR)); 00410 00411 for(i = 0; i < c; i++) 00412 { 00413 if (DoEvents()) 00414 goto err; 00415 00416 s_cbName = MAX_PATH * sizeof(TCHAR); 00417 lResult = RegEnumKeyExW(hSubKey, i, s_szName, &s_cbName, 00418 NULL, NULL, NULL, NULL); 00419 if (lResult == ERROR_NO_MORE_ITEMS) 00420 { 00421 c = i; 00422 break; 00423 } 00424 if (lResult != ERROR_SUCCESS) 00425 break; 00426 ppszNames[i] = _tcsdup(s_szName); 00427 } 00428 00429 qsort(ppszNames, c, sizeof(LPTSTR), compare); 00430 00431 fPast = FALSE; 00432 for(i = 0; i < c; i++) 00433 { 00434 if (DoEvents()) 00435 goto err; 00436 00437 if (!fPast && lstrcmpi(ppszNames[i], szKeyName) == 0) 00438 { 00439 fPast = TRUE; 00440 continue; 00441 } 00442 if (!fPast) 00443 continue; 00444 00445 if ((s_dwFlags & RSF_LOOKATKEYS) && 00446 CompareName(ppszNames[i], s_szFindWhat)) 00447 { 00448 *ppszFoundSubKey = malloc( 00449 (lstrlen(szSubKey) + lstrlen(ppszNames[i]) + 2) * 00450 sizeof(TCHAR)); 00451 if (*ppszFoundSubKey == NULL) 00452 goto err; 00453 if (szSubKey[0]) 00454 { 00455 lstrcpy(*ppszFoundSubKey, szSubKey); 00456 lstrcatW(*ppszFoundSubKey, s_backslash); 00457 } 00458 else 00459 **ppszFoundSubKey = 0; 00460 lstrcatW(*ppszFoundSubKey, ppszNames[i]); 00461 *ppszFoundValueName = NULL; 00462 goto success; 00463 } 00464 00465 if (RegFindRecurse(hSubKey, ppszNames[i], NULL, 00466 ppszFoundSubKey, ppszFoundValueName)) 00467 { 00468 LPTSTR psz = *ppszFoundSubKey; 00469 *ppszFoundSubKey = malloc( 00470 (lstrlen(szSubKey) + lstrlen(psz) + 2) * 00471 sizeof(TCHAR)); 00472 if (*ppszFoundSubKey == NULL) 00473 goto err; 00474 if (szSubKey[0]) 00475 { 00476 lstrcpy(*ppszFoundSubKey, szSubKey); 00477 lstrcatW(*ppszFoundSubKey, s_backslash); 00478 } 00479 else 00480 **ppszFoundSubKey = 0; 00481 lstrcatW(*ppszFoundSubKey, psz); 00482 free(psz); 00483 goto success; 00484 } 00485 } 00486 if (ppszNames != NULL) 00487 { 00488 for(i = 0; i < c; i++) 00489 free(ppszNames[i]); 00490 free(ppszNames); 00491 } 00492 ppszNames = NULL; 00493 00494 if (hBaseKey != hSubKey) 00495 RegCloseKey(hSubKey); 00496 } 00497 00498 if (*phKey == HKEY_CLASSES_ROOT) 00499 { 00500 *phKey = HKEY_CURRENT_USER; 00501 if (RegFindRecurse(*phKey, s_empty, NULL, ppszFoundSubKey, 00502 ppszFoundValueName)) 00503 return TRUE; 00504 } 00505 00506 if (*phKey == HKEY_CURRENT_USER) 00507 { 00508 *phKey = HKEY_LOCAL_MACHINE; 00509 if (RegFindRecurse(*phKey, s_empty, NULL, ppszFoundSubKey, 00510 ppszFoundValueName)) 00511 goto success; 00512 } 00513 00514 if (*phKey == HKEY_LOCAL_MACHINE) 00515 { 00516 *phKey = HKEY_USERS; 00517 if (RegFindRecurse(*phKey, s_empty, NULL, ppszFoundSubKey, 00518 ppszFoundValueName)) 00519 goto success; 00520 } 00521 00522 if (*phKey == HKEY_USERS) 00523 { 00524 *phKey = HKEY_CURRENT_CONFIG; 00525 if (RegFindRecurse(*phKey, s_empty, NULL, ppszFoundSubKey, 00526 ppszFoundValueName)) 00527 goto success; 00528 } 00529 00530 err: 00531 if (ppszNames != NULL) 00532 { 00533 for(i = 0; i < c; i++) 00534 free(ppszNames[i]); 00535 free(ppszNames); 00536 } 00537 if (hBaseKey != hSubKey) 00538 RegCloseKey(hSubKey); 00539 return FALSE; 00540 00541 success: 00542 if (ppszNames != NULL) 00543 { 00544 for(i = 0; i < c; i++) 00545 free(ppszNames[i]); 00546 free(ppszNames); 00547 } 00548 if (hBaseKey != hSubKey) 00549 RegCloseKey(hSubKey); 00550 return TRUE; 00551 } 00552 00553 00554 static DWORD GetFindFlags(void) 00555 { 00556 HKEY hKey; 00557 DWORD dwType, dwValue, cbData; 00558 DWORD dwFlags = RSF_LOOKATKEYS | RSF_LOOKATVALUES | RSF_LOOKATDATA; 00559 00560 if (RegOpenKey(HKEY_CURRENT_USER, g_szGeneralRegKey, &hKey) == ERROR_SUCCESS) 00561 { 00562 /* Retrieve flags from registry key */ 00563 cbData = sizeof(dwValue); 00564 if (RegQueryValueEx(hKey, s_szFindFlags, NULL, &dwType, (LPBYTE) &dwValue, &cbData) == ERROR_SUCCESS) 00565 { 00566 if (dwType == REG_DWORD) 00567 dwFlags = (dwFlags & ~0x0000FFFF) | ((dwValue & 0x0000FFFF) << 0); 00568 } 00569 00570 /* Retrieve ReactOS Regedit specific flags from registry key */ 00571 cbData = sizeof(dwValue); 00572 if (RegQueryValueEx(hKey, s_szFindFlagsR, NULL, &dwType, (LPBYTE) &dwValue, &cbData) == ERROR_SUCCESS) 00573 { 00574 if (dwType == REG_DWORD) 00575 dwFlags = (dwFlags & ~0xFFFF0000) | ((dwValue & 0x0000FFFF) << 16); 00576 } 00577 00578 RegCloseKey(hKey); 00579 } 00580 return dwFlags; 00581 } 00582 00583 static void SetFindFlags(DWORD dwFlags) 00584 { 00585 HKEY hKey; 00586 DWORD dwDisposition; 00587 DWORD dwData; 00588 00589 if (RegCreateKeyEx(HKEY_CURRENT_USER, g_szGeneralRegKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) 00590 { 00591 dwData = (dwFlags >> 0) & 0x0000FFFF; 00592 RegSetValueEx(hKey, s_szFindFlags, 0, REG_DWORD, (const BYTE *) &dwData, sizeof(dwData)); 00593 00594 dwData = (dwFlags >> 16) & 0x0000FFFF; 00595 RegSetValueEx(hKey, s_szFindFlagsR, 0, REG_DWORD, (const BYTE *) &dwData, sizeof(dwData)); 00596 00597 RegCloseKey(hKey); 00598 } 00599 } 00600 00601 static INT_PTR CALLBACK AbortFindDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00602 { 00603 UNREFERENCED_PARAMETER(lParam); 00604 UNREFERENCED_PARAMETER(hDlg); 00605 00606 switch(uMsg) 00607 { 00608 case WM_CLOSE: 00609 s_bAbort = TRUE; 00610 break; 00611 00612 case WM_COMMAND: 00613 switch(HIWORD(wParam)) 00614 { 00615 case BN_CLICKED: 00616 switch(LOWORD(wParam)) 00617 { 00618 case IDCANCEL: 00619 s_bAbort = TRUE; 00620 break; 00621 } 00622 break; 00623 } 00624 break; 00625 } 00626 return 0; 00627 } 00628 00629 BOOL FindNext(HWND hWnd) 00630 { 00631 HKEY hKeyRoot; 00632 LPCTSTR pszKeyPath; 00633 BOOL fSuccess; 00634 TCHAR szFullKey[512]; 00635 LPCTSTR pszValueName; 00636 LPTSTR pszFoundSubKey, pszFoundValueName; 00637 00638 if (_tcslen(s_szFindWhat) == 0) 00639 { 00640 FindDialog(hWnd); 00641 return TRUE; 00642 } 00643 00644 s_dwFlags = GetFindFlags(); 00645 00646 pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); 00647 if (pszKeyPath == NULL) 00648 { 00649 hKeyRoot = HKEY_CLASSES_ROOT; 00650 pszKeyPath = s_empty; 00651 } 00652 00653 /* Create abort find dialog */ 00654 s_hwndAbortDialog = CreateDialog(GetModuleHandle(NULL), 00655 MAKEINTRESOURCE(IDD_FINDING), hWnd, AbortFindDialogProc); 00656 if (s_hwndAbortDialog) 00657 { 00658 ShowWindow(s_hwndAbortDialog, SW_SHOW); 00659 UpdateWindow(s_hwndAbortDialog); 00660 } 00661 s_bAbort = FALSE; 00662 00663 pszValueName = GetValueName(g_pChildWnd->hListWnd, -1); 00664 00665 EnableWindow(hFrameWnd, FALSE); 00666 EnableWindow(g_pChildWnd->hTreeWnd, FALSE); 00667 EnableWindow(g_pChildWnd->hListWnd, FALSE); 00668 EnableWindow(g_pChildWnd->hAddressBarWnd, FALSE); 00669 00670 fSuccess = RegFindWalk(&hKeyRoot, pszKeyPath, pszValueName, 00671 &pszFoundSubKey, &pszFoundValueName); 00672 00673 EnableWindow(hFrameWnd, TRUE); 00674 EnableWindow(g_pChildWnd->hTreeWnd, TRUE); 00675 EnableWindow(g_pChildWnd->hListWnd, TRUE); 00676 EnableWindow(g_pChildWnd->hAddressBarWnd, TRUE); 00677 00678 if (s_hwndAbortDialog) 00679 { 00680 DestroyWindow(s_hwndAbortDialog); 00681 s_hwndAbortDialog = NULL; 00682 } 00683 00684 if (fSuccess) 00685 { 00686 GetKeyName(szFullKey, COUNT_OF(szFullKey), hKeyRoot, pszFoundSubKey); 00687 SelectNode(g_pChildWnd->hTreeWnd, szFullKey); 00688 SetValueName(g_pChildWnd->hListWnd, pszFoundValueName); 00689 free(pszFoundSubKey); 00690 free(pszFoundValueName); 00691 SetFocus(g_pChildWnd->hListWnd); 00692 } 00693 return fSuccess || s_bAbort; 00694 } 00695 00696 static INT_PTR CALLBACK FindDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00697 { 00698 INT_PTR iResult = 0; 00699 HWND hControl; 00700 LONG lStyle; 00701 DWORD dwFlags; 00702 static TCHAR s_szSavedFindValue[256]; 00703 00704 switch(uMsg) 00705 { 00706 case WM_INITDIALOG: 00707 dwFlags = GetFindFlags(); 00708 00709 hControl = GetDlgItem(hDlg, IDC_LOOKAT_KEYS); 00710 if (hControl) 00711 SendMessage(hControl, BM_SETCHECK, (dwFlags & RSF_LOOKATKEYS) ? TRUE : FALSE, 0); 00712 00713 hControl = GetDlgItem(hDlg, IDC_LOOKAT_VALUES); 00714 if (hControl) 00715 SendMessage(hControl, BM_SETCHECK, (dwFlags & RSF_LOOKATVALUES) ? TRUE : FALSE, 0); 00716 00717 hControl = GetDlgItem(hDlg, IDC_LOOKAT_DATA); 00718 if (hControl) 00719 SendMessage(hControl, BM_SETCHECK, (dwFlags & RSF_LOOKATDATA) ? TRUE : FALSE, 0); 00720 00721 /* Match whole string */ 00722 hControl = GetDlgItem(hDlg, IDC_MATCHSTRING); 00723 if (hControl) 00724 SendMessage(hControl, BM_SETCHECK, (dwFlags & RSF_WHOLESTRING) ? TRUE : FALSE, 0); 00725 00726 /* Case sensitivity */ 00727 hControl = GetDlgItem(hDlg, IDC_MATCHCASE); 00728 if (hControl) 00729 SendMessage(hControl, BM_SETCHECK, (dwFlags & RSF_MATCHCASE) ? TRUE : FALSE, 0); 00730 00731 hControl = GetDlgItem(hDlg, IDC_FINDWHAT); 00732 if (hControl) 00733 { 00734 SetWindowText(hControl, s_szSavedFindValue); 00735 SetFocus(hControl); 00736 SendMessage(hControl, EM_SETSEL, 0, -1); 00737 } 00738 break; 00739 00740 case WM_CLOSE: 00741 EndDialog(hDlg, 0); 00742 break; 00743 00744 case WM_COMMAND: 00745 switch(HIWORD(wParam)) 00746 { 00747 case BN_CLICKED: 00748 switch(LOWORD(wParam)) 00749 { 00750 case IDOK: 00751 dwFlags = 0; 00752 00753 hControl = GetDlgItem(hDlg, IDC_LOOKAT_KEYS); 00754 if (hControl && (SendMessage(hControl, BM_GETCHECK, 0, 0) == BST_CHECKED)) 00755 dwFlags |= RSF_LOOKATKEYS; 00756 00757 hControl = GetDlgItem(hDlg, IDC_LOOKAT_VALUES); 00758 if (hControl && (SendMessage(hControl, BM_GETCHECK, 0, 0) == BST_CHECKED)) 00759 dwFlags |= RSF_LOOKATVALUES; 00760 00761 hControl = GetDlgItem(hDlg, IDC_LOOKAT_DATA); 00762 if (hControl && (SendMessage(hControl, BM_GETCHECK, 0, 0) == BST_CHECKED)) 00763 dwFlags |= RSF_LOOKATDATA; 00764 00765 hControl = GetDlgItem(hDlg, IDC_MATCHSTRING); 00766 if (hControl && (SendMessage(hControl, BM_GETCHECK, 0, 0) == BST_CHECKED)) 00767 dwFlags |= RSF_WHOLESTRING; 00768 00769 hControl = GetDlgItem(hDlg, IDC_MATCHCASE); 00770 if (hControl && (SendMessage(hControl, BM_GETCHECK, 0, 0) == BST_CHECKED)) 00771 dwFlags |= RSF_MATCHCASE; 00772 00773 SetFindFlags(dwFlags); 00774 00775 hControl = GetDlgItem(hDlg, IDC_FINDWHAT); 00776 if (hControl) 00777 GetWindowText(hControl, s_szFindWhat, sizeof(s_szFindWhat) / sizeof(s_szFindWhat[0])); 00778 EndDialog(hDlg, 1); 00779 break; 00780 00781 case IDCANCEL: 00782 EndDialog(hDlg, 0); 00783 break; 00784 } 00785 break; 00786 00787 case EN_CHANGE: 00788 switch(LOWORD(wParam)) 00789 { 00790 case IDC_FINDWHAT: 00791 GetWindowText((HWND) lParam, s_szSavedFindValue, sizeof(s_szSavedFindValue) / sizeof(s_szSavedFindValue[0])); 00792 hControl = GetDlgItem(hDlg, IDOK); 00793 if (hControl) 00794 { 00795 lStyle = GetWindowLongPtr(hControl, GWL_STYLE); 00796 if (s_szSavedFindValue[0]) 00797 lStyle &= ~WS_DISABLED; 00798 else 00799 lStyle |= WS_DISABLED; 00800 SetWindowLongPtr(hControl, GWL_STYLE, lStyle); 00801 RedrawWindow(hControl, NULL, NULL, RDW_INVALIDATE); 00802 } 00803 break; 00804 } 00805 } 00806 break; 00807 } 00808 return iResult; 00809 } 00810 00811 void FindDialog(HWND hWnd) 00812 { 00813 if (DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_FIND), 00814 hWnd, FindDialogProc, 0) != 0) 00815 { 00816 if (!FindNext(hWnd)) 00817 { 00818 TCHAR msg[128], caption[128]; 00819 00820 LoadString(hInst, IDS_FINISHEDFIND, msg, sizeof(msg)/sizeof(TCHAR)); 00821 LoadString(hInst, IDS_APP_TITLE, caption, sizeof(caption)/sizeof(TCHAR)); 00822 MessageBox(0, msg, caption, MB_ICONINFORMATION); 00823 } 00824 } 00825 } 00826 Generated on Sat May 26 2012 04:15:32 for ReactOS by
1.7.6.1
|