ChangeLog Add value delete, and dword edit support. Index: programs/regedit/En.rc =================================================================== RCS file: /var/cvs/wine/programs/regedit/En.rc,v retrieving revision 1.4 diff -u -r1.4 En.rc --- programs/regedit/En.rc 3 Jan 2004 00:33:56 -0000 1.4 +++ programs/regedit/En.rc 3 Jan 2004 16:58:50 -0000 @@ -132,6 +132,21 @@ DEFPUSHBUTTON "Cancel",IDCANCEL,175,60,30,11,WS_GROUP END +IDD_EDIT_DWORD DIALOG DISCARDABLE 22, 17, 210, 100 +STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU +CAPTION "Edit String" +FONT 8, "System" +BEGIN + LTEXT "Value name:",IDC_STATIC,5,5,119,8 + EDITTEXT IDC_VALUE_NAME,5,15,200,12, WS_BORDER | WS_TABSTOP | WS_DISABLED + LTEXT "Value data:",IDC_STATIC,5,30,90,8 + EDITTEXT IDC_VALUE_DATA,5,40,90,12, WS_BORDER | WS_TABSTOP + GROUPBOX "Base", IDC_DWORD_BASE, 120, 30, 85, 37, BS_GROUPBOX + AUTORADIOBUTTON "Hexadecimal", IDC_DWORD_HEX, 130, 40, 60, 10, WS_TABSTOP + AUTORADIOBUTTON "Decimal", IDC_DWORD_DEC, 130, 52, 60, 10, WS_TABSTOP + DEFPUSHBUTTON "OK",IDOK,140,80,30,11,WS_GROUP + DEFPUSHBUTTON "Cancel",IDCANCEL,175,80,30,11,WS_GROUP +END /* * String Table @@ -201,6 +216,8 @@ IDS_BAD_VALUE "Can't query value '%s'" IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)" IDS_TOO_BIG_VALUE "Value is too big (%ld)" + IDS_DELETE_BOX_TITLE "Confirm Value Delete" + IDS_DELETE_BOX_TEXT "Are you sure you want to delete value '%s'?" IDS_NEWKEY "New Key" END Index: programs/regedit/edit.c =================================================================== RCS file: /var/cvs/wine/programs/regedit/edit.c,v retrieving revision 1.4 diff -u -r1.4 edit.c --- programs/regedit/edit.c 3 Jan 2004 00:33:56 -0000 1.4 +++ programs/regedit/edit.c 5 Jan 2004 16:48:10 -0000 @@ -35,31 +35,58 @@ static const TCHAR* editValueName; static TCHAR* stringValueData; +static BOOL isDecimal; -void error(HWND hwnd, INT resId, ...) +INT vmessagebox(HWND hwnd, INT buttons, INT titleId, INT resId, va_list ap) { - va_list ap; TCHAR title[256]; TCHAR errfmt[1024]; TCHAR errstr[1024]; - HINSTANCE hInstance; - hInstance = GetModuleHandle(0); - - if (!LoadString(hInstance, IDS_ERROR, title, COUNT_OF(title))) + if (!LoadString(hInst, titleId, title, COUNT_OF(title))) lstrcpy(title, "Error"); - if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt))) + if (!LoadString(hInst, resId, errfmt, COUNT_OF(errfmt))) lstrcpy(errfmt, "Unknown error string!"); - va_start(ap, resId); _vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap); + + return MessageBox(hwnd, errstr, title, buttons); +} + +INT messagebox(HWND hwnd, INT buttons, INT titleId, INT resId, ...) +{ + va_list ap; + INT result; + + va_start(ap, resId); + result = vmessagebox(hwnd, buttons, titleId, resId, ap); va_end(ap); - MessageBox(hwnd, errstr, title, MB_OK | MB_ICONERROR); + return result; } -INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +void error(HWND hwnd, INT resId, ...) +{ + va_list ap; + + va_start(ap, resId); + vmessagebox(hwnd, MB_OK | MB_ICONERROR, IDS_ERROR, resId, ap); + va_end(ap); +} + +BOOL change_dword_base(HWND hwndDlg, BOOL toHex) +{ + TCHAR buf[128]; + DWORD val; + + if (!GetDlgItemText(hwndDlg, IDC_VALUE_DATA, buf, COUNT_OF(buf))) return FALSE; + if (!_stscanf(buf, toHex ? "%ld" : "%lx", &val)) return FALSE; + wsprintf(buf, toHex ? "%lx" : "%ld", val); + return SetDlgItemText(hwndDlg, IDC_VALUE_DATA, buf); +} + +INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { TCHAR* valueData; HWND hwndValue; @@ -69,9 +96,16 @@ case WM_INITDIALOG: SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); + CheckRadioButton(hwndDlg, IDC_DWORD_HEX, IDC_DWORD_DEC, isDecimal ? IDC_DWORD_DEC : IDC_DWORD_HEX); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { + case IDC_DWORD_HEX: + if (isDecimal && change_dword_base(hwndDlg, TRUE)) isDecimal = FALSE; + break; + case IDC_DWORD_DEC: + if (!isDecimal && change_dword_base(hwndDlg, FALSE)) isDecimal = TRUE; + break; case IDOK: if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) { if ((len = GetWindowTextLength(hwndValue))) { @@ -108,7 +142,7 @@ if (newKey[0] == 0) { hInstance = GetModuleHandle(0); if (!LoadString(hInstance, IDS_NEWKEY, newKey, COUNT_OF(newKey))) - lstrcpy(newKey, "new key"); + lstrcpy(newKey, "New Key"); } lstrcpy(keyName, newKey); @@ -116,8 +150,8 @@ We try it max 100 times. */ lRet = RegOpenKey(hKey, keyName, &retKey); while (lRet == ERROR_SUCCESS && keyNum < 100) { - sprintf(keyName, "%s %u", newKey, ++keyNum); - lRet = RegOpenKey(hKey, keyName, &retKey); + wsprintf(keyName, "%s %u", newKey, ++keyNum); + lRet = RegOpenKey(hKey, keyName, &retKey); } if (lRet == ERROR_SUCCESS) return FALSE; @@ -141,23 +175,31 @@ error(hwnd, IDS_BAD_VALUE, valueName); goto done; } + if ( type == REG_DWORD ) valueDataLen = 128; + if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) { + error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); + goto done; + } + lRet = RegQueryValueEx(hKey, valueName, 0, 0, stringValueData, &valueDataLen); + if (lRet != ERROR_SUCCESS) { + error(hwnd, IDS_BAD_VALUE, valueName); + goto done; + } if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) { - if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) { - error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); - goto done; - } - lRet = RegQueryValueEx(hKey, valueName, 0, 0, stringValueData, &valueDataLen); - if (lRet != ERROR_SUCCESS) { - error(hwnd, IDS_BAD_VALUE, valueName); - goto done; - } - if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) { + if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) { lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1); if (lRet == ERROR_SUCCESS) result = TRUE; } } else if ( type == REG_DWORD ) { - MessageBox(hwnd, "Can't edit dwords for now", "Error", MB_OK | MB_ICONERROR); + wsprintf(stringValueData, isDecimal ? "%ld" : "%lx", *((DWORD*)stringValueData)); + if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_DWORD), hwnd, modify_dlgproc) == IDOK) { + DWORD val; + if (_stscanf(stringValueData, isDecimal ? "%ld" : "%lx", &val)) { + lRet = RegSetValueEx(hKey, valueName, 0, type, (BYTE*)&val, sizeof(val)); + if (lRet == ERROR_SUCCESS) result = TRUE; + } + } } else { error(hwnd, IDS_UNSUPPORTED_TYPE, type); } @@ -167,4 +209,20 @@ stringValueData = NULL; return result; +} + +BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName) +{ + LONG lRet; + + if (!hKey || !valueName) return FALSE; + + if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, valueName) != IDYES) + return FALSE; + + lRet = RegDeleteValue(hKey, valueName); + if (lRet != ERROR_SUCCESS) { + error(hwnd, IDS_BAD_VALUE, valueName); + } + return lRet == ERROR_SUCCESS; } Index: programs/regedit/framewnd.c =================================================================== RCS file: /var/cvs/wine/programs/regedit/framewnd.c,v retrieving revision 1.6 diff -u -r1.6 framewnd.c --- programs/regedit/framewnd.c 3 Jan 2004 00:33:56 -0000 1.6 +++ programs/regedit/framewnd.c 3 Jan 2004 16:58:13 -0000 @@ -441,12 +441,11 @@ BOOL result = TRUE; LONG lRet; - keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); - valueName = GetValueName(g_pChildWnd->hListWnd); - if (keyPath) { - lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey); + if ((keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot))) { + lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_ALL_ACCESS, &hKey); if (lRet != ERROR_SUCCESS) hKey = 0; } + valueName = GetValueName(g_pChildWnd->hListWnd); switch (LOWORD(wParam)) { case ID_REGISTRY_IMPORTREGISTRYFILE: @@ -461,6 +460,10 @@ break; case ID_REGISTRY_PRINT: PrintRegistryHive(hWnd, _T("")); + break; + case ID_EDIT_DELETE: + if (DeleteValue(hWnd, hKey, valueName)) + RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath); break; case ID_EDIT_MODIFY: if (ModifyValue(hWnd, hKey, valueName)) Index: programs/regedit/main.h =================================================================== RCS file: /var/cvs/wine/programs/regedit/main.h,v retrieving revision 1.9 diff -u -r1.9 main.h --- programs/regedit/main.h 3 Jan 2004 00:33:56 -0000 1.9 +++ programs/regedit/main.h 3 Jan 2004 16:59:52 -0000 @@ -93,7 +93,8 @@ extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); /* edit.c */ -BOOL CreateKey(HKEY hKey); -BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName); +extern BOOL CreateKey(HKEY hKey); +extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName); +extern BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName); #endif /* __MAIN_H__ */ Index: programs/regedit/resource.h =================================================================== RCS file: /var/cvs/wine/programs/regedit/resource.h,v retrieving revision 1.3 diff -u -r1.3 resource.h --- programs/regedit/resource.h 3 Jan 2004 00:33:56 -0000 1.3 +++ programs/regedit/resource.h 3 Jan 2004 17:00:26 -0000 @@ -106,7 +106,13 @@ #define IDS_BAD_VALUE 32837 #define IDS_UNSUPPORTED_TYPE 32838 #define IDS_TOO_BIG_VALUE 32839 -#define IDS_NEWKEY 32840 +#define IDS_DELETE_BOX_TITLE 32840 +#define IDS_DELETE_BOX_TEXT 32841 +#define IDD_EDIT_DWORD 32850 +#define IDC_DWORD_BASE 32852 +#define IDC_DWORD_HEX 32853 +#define IDC_DWORD_DEC 32854 +#define IDS_NEWKEY 32860 #define IDD_EDIT_STRING 2000 #define IDC_VALUE_NAME 2001 Index: programs/regedit/treeview.c =================================================================== RCS file: /var/cvs/wine/programs/regedit/treeview.c,v retrieving revision 1.5 diff -u -r1.5 treeview.c --- programs/regedit/treeview.c 12 Dec 2003 04:08:59 -0000 1.5 +++ programs/regedit/treeview.c 5 Jan 2004 16:44:46 -0000 @@ -99,7 +99,6 @@ if (!hItem) hItem = TreeView_GetSelection(hwndTV); if (!hItem) return NULL; if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL; - printf("hRoot=%p, keyPath='%s'\n", *phRootKey, pathBuffer); return pathBuffer; } @@ -235,7 +234,6 @@ RegCloseKey(hKey); } if (errCode != ERROR_SUCCESS) dwSubCount = 0; - printf("dwSubCount=%ld, Name=%s\n", dwSubCount, Name); AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwSubCount); } RegCloseKey(hNewKey); -- Dimi.