4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 static TCHAR s_szFindWhat
[256];
36 static const TCHAR s_szFindFlags
[] = _T("FindFlags");
37 static const TCHAR s_szFindFlagsR
[] = _T("FindFlagsReactOS");
38 static HWND s_hwndAbortDialog
;
43 static DWORD
GetFindFlags(void)
46 DWORD dwFlags
= RSF_LOOKATKEYS
;
47 DWORD dwType
, dwValue
, cbData
;
49 if (RegOpenKey(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
51 /* Retrieve flags from registry key */
52 cbData
= sizeof(dwValue
);
53 if (RegQueryValueEx(hKey
, s_szFindFlags
, NULL
, &dwType
, (LPBYTE
) &dwValue
, &cbData
) == ERROR_SUCCESS
)
55 if (dwType
== REG_DWORD
)
56 dwFlags
= (dwFlags
& ~0x0000FFFF) | ((dwValue
& 0x0000FFFF) << 0);
59 /* Retrieve ReactOS Regedit specific flags from registry key */
60 cbData
= sizeof(dwValue
);
61 if (RegQueryValueEx(hKey
, s_szFindFlagsR
, NULL
, &dwType
, (LPBYTE
) &dwValue
, &cbData
) == ERROR_SUCCESS
)
63 if (dwType
== REG_DWORD
)
64 dwFlags
= (dwFlags
& ~0xFFFF0000) | ((dwValue
& 0x0000FFFF) << 16);
72 static void SetFindFlags(DWORD dwFlags
)
78 if (RegCreateKeyEx(HKEY_CURRENT_USER
, g_szGeneralRegKey
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisposition
) == ERROR_SUCCESS
)
80 dwData
= (dwFlags
>> 0) & 0x0000FFFF;
81 RegSetValueEx(hKey
, s_szFindFlags
, 0, REG_DWORD
, (const BYTE
*) &dwData
, sizeof(dwData
));
83 dwData
= (dwFlags
>> 16) & 0x0000FFFF;
84 RegSetValueEx(hKey
, s_szFindFlagsR
, 0, REG_DWORD
, (const BYTE
*) &dwData
, sizeof(dwData
));
90 static INT_PTR CALLBACK
AbortFindDialogProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
99 switch(HIWORD(wParam
))
102 switch(LOWORD(wParam
))
115 static BOOL
RegSearchProc(LPVOID lpParam
)
119 if (s_hwndAbortDialog
&& PeekMessage(&msg
, s_hwndAbortDialog
, 0, 0, PM_REMOVE
))
121 TranslateMessage(&msg
);
122 DispatchMessage(&msg
);
127 BOOL
FindNext(HWND hWnd
)
137 TCHAR szFullKey
[512];
139 pszFindWhat
= s_szFindWhat
;
140 dwFlags
= GetFindFlags() & ~(RSF_LOOKATVALUES
| RSF_LOOKATDATA
);
142 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
143 lstrcpyn(szSubKey
, pszKeyPath
, sizeof(szSubKey
) / sizeof(szSubKey
[0]));
145 /* Create abort find dialog */
146 s_hwndAbortDialog
= CreateDialog(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_FINDING
), hWnd
, AbortFindDialogProc
);
147 if (s_hwndAbortDialog
)
148 ShowWindow(s_hwndAbortDialog
, SW_SHOW
);
151 lResult
= RegSearch(hKeyRoot
, szSubKey
, sizeof(szSubKey
) / sizeof(szSubKey
[0]),
152 pszFindWhat
, 0, dwFlags
, RegSearchProc
, NULL
);
154 if (s_hwndAbortDialog
)
156 DestroyWindow(s_hwndAbortDialog
);
157 s_hwndAbortDialog
= NULL
;
160 /* Did the user click "Cancel"? If so, exit without displaying an error message */
161 if (lResult
== ERROR_OPERATION_ABORTED
)
164 if (lResult
!= ERROR_SUCCESS
)
166 LoadString(NULL
, IDS_APP_TITLE
, szTitle
, sizeof(szTitle
) / sizeof(szTitle
[0]));
168 if ((lResult
!= ERROR_NO_MORE_ITEMS
) || !LoadString(NULL
, IDS_FINISHEDFIND
, szError
, sizeof(szError
) / sizeof(szError
[0])))
170 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, lResult
, 0,
171 szError
, sizeof(szError
) / sizeof(szError
[0]), NULL
);
173 MessageBox(hWnd
, szError
, szTitle
, MB_OK
);
177 RegKeyGetName(szFullKey
, sizeof(szFullKey
) / sizeof(szFullKey
[0]), hKeyRoot
, szSubKey
);
178 SelectNode(g_pChildWnd
->hTreeWnd
, szFullKey
);
182 static INT_PTR CALLBACK
FindDialogProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
188 static TCHAR s_szSavedFindValue
[256];
193 dwFlags
= GetFindFlags();
195 /* Looking at values is not yet implemented */
196 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_KEYS
);
198 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_LOOKATKEYS
) ? TRUE
: FALSE
, 0);
200 /* Looking at values is not yet implemented */
201 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_VALUES
);
204 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
205 SetWindowLong(hControl
, GWL_STYLE
, lStyle
| WS_DISABLED
);
208 /* Looking at data is not yet implemented */
209 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_DATA
);
212 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
213 SetWindowLong(hControl
, GWL_STYLE
, lStyle
| WS_DISABLED
);
216 /* Match whole string */
217 hControl
= GetDlgItem(hDlg
, IDC_MATCHSTRING
);
219 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_WHOLESTRING
) ? TRUE
: FALSE
, 0);
221 /* Case sensitivity */
222 hControl
= GetDlgItem(hDlg
, IDC_MATCHCASE
);
224 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_MATCHCASE
) ? TRUE
: FALSE
, 0);
226 hControl
= GetDlgItem(hDlg
, IDC_FINDWHAT
);
229 SetWindowText(hControl
, s_szSavedFindValue
);
231 SendMessage(hControl
, EM_SETSEL
, 0, -1);
240 switch(HIWORD(wParam
))
243 switch(LOWORD(wParam
))
248 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_KEYS
);
249 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
250 dwFlags
|= RSF_LOOKATKEYS
;
252 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_VALUES
);
253 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
254 dwFlags
|= RSF_LOOKATVALUES
;
256 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_DATA
);
257 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
258 dwFlags
|= RSF_LOOKATDATA
;
260 hControl
= GetDlgItem(hDlg
, IDC_MATCHSTRING
);
261 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
262 dwFlags
|= RSF_WHOLESTRING
;
264 hControl
= GetDlgItem(hDlg
, IDC_MATCHCASE
);
265 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
266 dwFlags
|= RSF_MATCHCASE
;
268 SetFindFlags(dwFlags
);
270 hControl
= GetDlgItem(hDlg
, IDC_FINDWHAT
);
272 GetWindowText(hControl
, s_szFindWhat
, sizeof(s_szFindWhat
) / sizeof(s_szFindWhat
[0]));
283 switch(LOWORD(wParam
))
286 GetWindowText((HWND
) lParam
, s_szSavedFindValue
, sizeof(s_szSavedFindValue
) / sizeof(s_szSavedFindValue
[0]));
287 hControl
= GetDlgItem(hDlg
, IDOK
);
290 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
291 if (s_szSavedFindValue
[0])
292 lStyle
&= ~WS_DISABLED
;
294 lStyle
|= WS_DISABLED
;
295 SetWindowLong(hControl
, GWL_STYLE
, lStyle
);
296 RedrawWindow(hControl
, NULL
, NULL
, RDW_INVALIDATE
);
306 void FindDialog(HWND hWnd
)
308 if (DialogBoxParam(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_FIND
),
309 hWnd
, FindDialogProc
, 0) != 0)