2 * Registry editing UI functions.
4 * Copyright (C) 2003 Dimitrie O. Paun
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
36 static TCHAR
* editValueName
;
37 static TCHAR
* stringValueData
;
39 void error(HWND hwnd
, INT resId
, ...)
47 hInstance
= GetModuleHandle(0);
49 if (!LoadString(hInstance
, IDS_ERROR
, title
, COUNT_OF(title
)))
50 lstrcpy(title
, "Error");
52 if (!LoadString(hInstance
, resId
, errfmt
, COUNT_OF(errfmt
)))
53 lstrcpy(errfmt
, "Unknown error string!");
56 _vsntprintf(errstr
, COUNT_OF(errstr
), errfmt
, ap
);
59 MessageBox(hwnd
, errstr
, title
, MB_OK
| MB_ICONERROR
);
62 INT_PTR CALLBACK
modify_string_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
70 SetDlgItemText(hwndDlg
, IDC_VALUE_NAME
, editValueName
);
71 SetDlgItemText(hwndDlg
, IDC_VALUE_DATA
, stringValueData
);
74 switch (LOWORD(wParam
)) {
76 if ((hwndValue
= GetDlgItem(hwndDlg
, IDC_VALUE_DATA
))) {
77 if ((len
= GetWindowTextLength(hwndValue
))) {
78 if ((valueData
= HeapReAlloc(GetProcessHeap(), 0, stringValueData
, (len
+ 1) * sizeof(TCHAR
)))) {
79 stringValueData
= valueData
;
80 if (!GetWindowText(hwndValue
, stringValueData
, len
+ 1))
87 EndDialog(hwndDlg
, wParam
);
94 BOOL
ModifyValue(HWND hwnd
, HKEY hKey
, LPTSTR valueName
)
101 if (!hKey
|| !valueName
) return FALSE
;
103 editValueName
= valueName
;
105 lRet
= RegQueryValueEx(hKey
, valueName
, 0, &type
, 0, &valueDataLen
);
106 if (lRet
!= ERROR_SUCCESS
) {
107 error(hwnd
, IDS_BAD_VALUE
, valueName
);
111 if ( (type
== REG_SZ
) || (type
== REG_EXPAND_SZ
) ) {
112 if (!(stringValueData
= HeapAlloc(GetProcessHeap(), 0, valueDataLen
))) {
113 error(hwnd
, IDS_TOO_BIG_VALUE
, valueDataLen
);
116 lRet
= RegQueryValueEx(hKey
, valueName
, 0, 0, stringValueData
, &valueDataLen
);
117 if (lRet
!= ERROR_SUCCESS
) {
118 error(hwnd
, IDS_BAD_VALUE
, valueName
);
121 if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING
), hwnd
, modify_string_dlgproc
) == IDOK
) {
122 lRet
= RegSetValueEx(hKey
, valueName
, 0, type
, stringValueData
, lstrlen(stringValueData
) + 1);
123 if (lRet
== ERROR_SUCCESS
) result
= TRUE
;
125 } else if ( type
== REG_DWORD
) {
126 MessageBox(hwnd
, "Can't edit dwords for now", "Error", MB_OK
| MB_ICONERROR
);
128 error(hwnd
, IDS_UNSUPPORTED_TYPE
, type
);
132 HeapFree(GetProcessHeap(), 0, stringValueData
);
133 stringValueData
= NULL
;