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
22 static TCHAR s_szFindWhat
[256];
23 static const TCHAR s_szFindFlags
[] = _T("FindFlags");
24 static const TCHAR s_szFindFlagsR
[] = _T("FindFlagsReactOS");
25 static HWND s_hwndAbortDialog
;
30 static DWORD
GetFindFlags(void)
33 DWORD dwFlags
= RSF_LOOKATKEYS
;
34 DWORD dwType
, dwValue
, cbData
;
36 if (RegOpenKey(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
38 /* Retrieve flags from registry key */
39 cbData
= sizeof(dwValue
);
40 if (RegQueryValueEx(hKey
, s_szFindFlags
, NULL
, &dwType
, (LPBYTE
) &dwValue
, &cbData
) == ERROR_SUCCESS
)
42 if (dwType
== REG_DWORD
)
43 dwFlags
= (dwFlags
& ~0x0000FFFF) | ((dwValue
& 0x0000FFFF) << 0);
46 /* Retrieve ReactOS Regedit specific flags from registry key */
47 cbData
= sizeof(dwValue
);
48 if (RegQueryValueEx(hKey
, s_szFindFlagsR
, NULL
, &dwType
, (LPBYTE
) &dwValue
, &cbData
) == ERROR_SUCCESS
)
50 if (dwType
== REG_DWORD
)
51 dwFlags
= (dwFlags
& ~0xFFFF0000) | ((dwValue
& 0x0000FFFF) << 16);
59 static void SetFindFlags(DWORD dwFlags
)
65 if (RegCreateKeyEx(HKEY_CURRENT_USER
, g_szGeneralRegKey
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisposition
) == ERROR_SUCCESS
)
67 dwData
= (dwFlags
>> 0) & 0x0000FFFF;
68 RegSetValueEx(hKey
, s_szFindFlags
, 0, REG_DWORD
, (const BYTE
*) &dwData
, sizeof(dwData
));
70 dwData
= (dwFlags
>> 16) & 0x0000FFFF;
71 RegSetValueEx(hKey
, s_szFindFlagsR
, 0, REG_DWORD
, (const BYTE
*) &dwData
, sizeof(dwData
));
77 static INT_PTR CALLBACK
AbortFindDialogProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
86 switch(HIWORD(wParam
))
89 switch(LOWORD(wParam
))
102 static BOOL
RegSearchProc(LPVOID lpParam
)
106 if (s_hwndAbortDialog
&& PeekMessage(&msg
, s_hwndAbortDialog
, 0, 0, PM_REMOVE
))
108 TranslateMessage(&msg
);
109 DispatchMessage(&msg
);
114 BOOL
FindNext(HWND hWnd
)
124 TCHAR szFullKey
[512];
126 pszFindWhat
= s_szFindWhat
;
127 dwFlags
= GetFindFlags() & ~(RSF_LOOKATVALUES
| RSF_LOOKATDATA
);
129 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
130 lstrcpyn(szSubKey
, pszKeyPath
, sizeof(szSubKey
) / sizeof(szSubKey
[0]));
132 /* Create abort find dialog */
133 s_hwndAbortDialog
= CreateDialog(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_FINDING
), hWnd
, AbortFindDialogProc
);
134 if (s_hwndAbortDialog
)
135 ShowWindow(s_hwndAbortDialog
, SW_SHOW
);
138 lResult
= RegSearch(hKeyRoot
, szSubKey
, sizeof(szSubKey
) / sizeof(szSubKey
[0]),
139 pszFindWhat
, 0, dwFlags
, RegSearchProc
, NULL
);
141 if (s_hwndAbortDialog
)
143 DestroyWindow(s_hwndAbortDialog
);
144 s_hwndAbortDialog
= NULL
;
147 /* Did the user click "Cancel"? If so, exit without displaying an error message */
148 if (lResult
== ERROR_OPERATION_ABORTED
)
151 if (lResult
!= ERROR_SUCCESS
)
153 LoadString(NULL
, IDS_APP_TITLE
, szTitle
, sizeof(szTitle
) / sizeof(szTitle
[0]));
155 if ((lResult
!= ERROR_NO_MORE_ITEMS
) || !LoadString(NULL
, IDS_FINISHEDFIND
, szError
, sizeof(szError
) / sizeof(szError
[0])))
157 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, lResult
, 0,
158 szError
, sizeof(szError
) / sizeof(szError
[0]), NULL
);
160 MessageBox(hWnd
, szError
, szTitle
, MB_OK
);
164 RegKeyGetName(szFullKey
, sizeof(szFullKey
) / sizeof(szFullKey
[0]), hKeyRoot
, szSubKey
);
165 SelectNode(g_pChildWnd
->hTreeWnd
, szFullKey
);
169 static INT_PTR CALLBACK
FindDialogProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
175 static TCHAR s_szSavedFindValue
[256];
180 dwFlags
= GetFindFlags();
182 /* Looking at values is not yet implemented */
183 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_KEYS
);
185 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_LOOKATKEYS
) ? TRUE
: FALSE
, 0);
187 /* Looking at values is not yet implemented */
188 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_VALUES
);
191 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
192 SetWindowLong(hControl
, GWL_STYLE
, lStyle
| WS_DISABLED
);
195 /* Looking at data is not yet implemented */
196 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_DATA
);
199 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
200 SetWindowLong(hControl
, GWL_STYLE
, lStyle
| WS_DISABLED
);
203 /* Match whole string */
204 hControl
= GetDlgItem(hDlg
, IDC_MATCHSTRING
);
206 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_WHOLESTRING
) ? TRUE
: FALSE
, 0);
208 /* Case sensitivity */
209 hControl
= GetDlgItem(hDlg
, IDC_MATCHCASE
);
211 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_MATCHCASE
) ? TRUE
: FALSE
, 0);
213 hControl
= GetDlgItem(hDlg
, IDC_FINDWHAT
);
216 SetWindowText(hControl
, s_szSavedFindValue
);
218 SendMessage(hControl
, EM_SETSEL
, 0, -1);
227 switch(HIWORD(wParam
))
230 switch(LOWORD(wParam
))
235 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_KEYS
);
236 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
237 dwFlags
|= RSF_LOOKATKEYS
;
239 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_VALUES
);
240 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
241 dwFlags
|= RSF_LOOKATVALUES
;
243 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_DATA
);
244 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
245 dwFlags
|= RSF_LOOKATDATA
;
247 hControl
= GetDlgItem(hDlg
, IDC_MATCHSTRING
);
248 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
249 dwFlags
|= RSF_WHOLESTRING
;
251 hControl
= GetDlgItem(hDlg
, IDC_MATCHCASE
);
252 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
253 dwFlags
|= RSF_MATCHCASE
;
255 SetFindFlags(dwFlags
);
257 hControl
= GetDlgItem(hDlg
, IDC_FINDWHAT
);
259 GetWindowText(hControl
, s_szFindWhat
, sizeof(s_szFindWhat
) / sizeof(s_szFindWhat
[0]));
270 switch(LOWORD(wParam
))
273 GetWindowText((HWND
) lParam
, s_szSavedFindValue
, sizeof(s_szSavedFindValue
) / sizeof(s_szSavedFindValue
[0]));
274 hControl
= GetDlgItem(hDlg
, IDOK
);
277 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
278 if (s_szSavedFindValue
[0])
279 lStyle
&= ~WS_DISABLED
;
281 lStyle
|= WS_DISABLED
;
282 SetWindowLong(hControl
, GWL_STYLE
, lStyle
);
283 RedrawWindow(hControl
, NULL
, NULL
, RDW_INVALIDATE
);
293 void FindDialog(HWND hWnd
)
295 if (DialogBoxParam(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_FIND
),
296 hWnd
, FindDialogProc
, 0) != 0)