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
)
79 UNREFERENCED_PARAMETER(lParam
);
80 UNREFERENCED_PARAMETER(hDlg
);
89 switch(HIWORD(wParam
))
92 switch(LOWORD(wParam
))
105 static BOOL
RegSearchProc(LPVOID lpParam
)
108 UNREFERENCED_PARAMETER(lpParam
);
110 if (s_hwndAbortDialog
&& PeekMessage(&msg
, s_hwndAbortDialog
, 0, 0, PM_REMOVE
))
112 TranslateMessage(&msg
);
113 DispatchMessage(&msg
);
118 BOOL
FindNext(HWND hWnd
)
128 TCHAR szFullKey
[512];
130 pszFindWhat
= s_szFindWhat
;
131 dwFlags
= GetFindFlags() & ~(RSF_LOOKATVALUES
| RSF_LOOKATDATA
);
133 pszKeyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hKeyRoot
);
134 lstrcpyn(szSubKey
, pszKeyPath
, sizeof(szSubKey
) / sizeof(szSubKey
[0]));
136 /* Create abort find dialog */
137 s_hwndAbortDialog
= CreateDialog(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_FINDING
), hWnd
, AbortFindDialogProc
);
138 if (s_hwndAbortDialog
)
139 ShowWindow(s_hwndAbortDialog
, SW_SHOW
);
142 lResult
= RegSearch(hKeyRoot
, szSubKey
, sizeof(szSubKey
) / sizeof(szSubKey
[0]),
143 pszFindWhat
, 0, dwFlags
, RegSearchProc
, NULL
);
145 if (s_hwndAbortDialog
)
147 DestroyWindow(s_hwndAbortDialog
);
148 s_hwndAbortDialog
= NULL
;
151 /* Did the user click "Cancel"? If so, exit without displaying an error message */
152 if (lResult
== ERROR_OPERATION_ABORTED
)
155 if (lResult
!= ERROR_SUCCESS
)
157 LoadString(NULL
, IDS_APP_TITLE
, szTitle
, sizeof(szTitle
) / sizeof(szTitle
[0]));
159 if ((lResult
!= ERROR_NO_MORE_ITEMS
) || !LoadString(NULL
, IDS_FINISHEDFIND
, szError
, sizeof(szError
) / sizeof(szError
[0])))
161 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, lResult
, 0,
162 szError
, sizeof(szError
) / sizeof(szError
[0]), NULL
);
164 MessageBox(hWnd
, szError
, szTitle
, MB_OK
);
168 RegKeyGetName(szFullKey
, sizeof(szFullKey
) / sizeof(szFullKey
[0]), hKeyRoot
, szSubKey
);
169 SelectNode(g_pChildWnd
->hTreeWnd
, szFullKey
);
173 static INT_PTR CALLBACK
FindDialogProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
179 static TCHAR s_szSavedFindValue
[256];
184 dwFlags
= GetFindFlags();
186 /* Looking at values is not yet implemented */
187 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_KEYS
);
189 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_LOOKATKEYS
) ? TRUE
: FALSE
, 0);
191 /* Looking at values is not yet implemented */
192 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_VALUES
);
195 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
196 SetWindowLong(hControl
, GWL_STYLE
, lStyle
| WS_DISABLED
);
199 /* Looking at data is not yet implemented */
200 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_DATA
);
203 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
204 SetWindowLong(hControl
, GWL_STYLE
, lStyle
| WS_DISABLED
);
207 /* Match whole string */
208 hControl
= GetDlgItem(hDlg
, IDC_MATCHSTRING
);
210 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_WHOLESTRING
) ? TRUE
: FALSE
, 0);
212 /* Case sensitivity */
213 hControl
= GetDlgItem(hDlg
, IDC_MATCHCASE
);
215 SendMessage(hControl
, BM_SETCHECK
, (dwFlags
& RSF_MATCHCASE
) ? TRUE
: FALSE
, 0);
217 hControl
= GetDlgItem(hDlg
, IDC_FINDWHAT
);
220 SetWindowText(hControl
, s_szSavedFindValue
);
222 SendMessage(hControl
, EM_SETSEL
, 0, -1);
231 switch(HIWORD(wParam
))
234 switch(LOWORD(wParam
))
239 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_KEYS
);
240 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
241 dwFlags
|= RSF_LOOKATKEYS
;
243 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_VALUES
);
244 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
245 dwFlags
|= RSF_LOOKATVALUES
;
247 hControl
= GetDlgItem(hDlg
, IDC_LOOKAT_DATA
);
248 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
249 dwFlags
|= RSF_LOOKATDATA
;
251 hControl
= GetDlgItem(hDlg
, IDC_MATCHSTRING
);
252 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
253 dwFlags
|= RSF_WHOLESTRING
;
255 hControl
= GetDlgItem(hDlg
, IDC_MATCHCASE
);
256 if (hControl
&& (SendMessage(hControl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
257 dwFlags
|= RSF_MATCHCASE
;
259 SetFindFlags(dwFlags
);
261 hControl
= GetDlgItem(hDlg
, IDC_FINDWHAT
);
263 GetWindowText(hControl
, s_szFindWhat
, sizeof(s_szFindWhat
) / sizeof(s_szFindWhat
[0]));
274 switch(LOWORD(wParam
))
277 GetWindowText((HWND
) lParam
, s_szSavedFindValue
, sizeof(s_szSavedFindValue
) / sizeof(s_szSavedFindValue
[0]));
278 hControl
= GetDlgItem(hDlg
, IDOK
);
281 lStyle
= GetWindowLong(hControl
, GWL_STYLE
);
282 if (s_szSavedFindValue
[0])
283 lStyle
&= ~WS_DISABLED
;
285 lStyle
|= WS_DISABLED
;
286 SetWindowLong(hControl
, GWL_STYLE
, lStyle
);
287 RedrawWindow(hControl
, NULL
, NULL
, RDW_INVALIDATE
);
297 void FindDialog(HWND hWnd
)
299 if (DialogBoxParam(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_FIND
),
300 hWnd
, FindDialogProc
, 0) != 0)