OK, here is the better patch -- no longer creating the useless edit.h, and with more consistent bracket style. ChangeLog Add support for editing strings. Index: programs/regedit/En.rc =================================================================== RCS file: /var/cvs/wine/programs/regedit/En.rc,v retrieving revision 1.2 diff -u -r1.2 En.rc --- programs/regedit/En.rc 30 Aug 2003 00:17:33 -0000 1.2 +++ programs/regedit/En.rc 1 Dec 2003 18:10:21 -0000 @@ -119,6 +119,20 @@ DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP END +IDD_EDIT_STRING DIALOG DISCARDABLE 22, 17, 210, 75 +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,119,8 + EDITTEXT IDC_VALUE_DATA,5,40,200,12, WS_BORDER | WS_TABSTOP + DEFPUSHBUTTON "OK",IDOK,140,60,30,11,WS_GROUP + DEFPUSHBUTTON "Cancel",IDCANCEL,175,60,30,11,WS_GROUP +END + + /* * String Table */ @@ -179,6 +193,14 @@ ID_EDIT_COPYKEYNAME "Copies the name of the selected key to the clipboard" ID_EDIT_FIND "Finds a text string in a key, value or data" ID_EDIT_FINDNEXT "Finds next occurrence of text specified in previous search" +END + +STRINGTABLE DISCARDABLE +BEGIN + IDS_ERROR "Error" + 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)" END /*****************************************************************/ Index: programs/regedit/Makefile.in =================================================================== RCS file: /var/cvs/wine/programs/regedit/Makefile.in,v retrieving revision 1.12 diff -u -r1.12 Makefile.in --- programs/regedit/Makefile.in 4 Oct 2003 04:21:19 -0000 1.12 +++ programs/regedit/Makefile.in 29 Nov 2003 06:25:29 -0000 @@ -11,6 +11,7 @@ C_SRCS = \ about.c \ childwnd.c \ + edit.c \ framewnd.c \ listview.c \ main.c \ Index: programs/regedit/childwnd.c =================================================================== RCS file: /var/cvs/wine/programs/regedit/childwnd.c,v retrieving revision 1.1 diff -u -r1.1 childwnd.c --- programs/regedit/childwnd.c 7 Aug 2003 03:10:13 -0000 1.1 +++ programs/regedit/childwnd.c 1 Dec 2003 07:07:22 -0000 @@ -22,16 +22,16 @@ #include <windows.h> #include <tchar.h> #include <commctrl.h> -#include <assert.h> -#define ASSERT assert #include "main.h" +ChildWnd* pChildWnd; /******************************************************************************* * Local module support methods */ +//FIXME: why do we need this, we should remove it, we have already FindRegRoot static void MakeFullRegPath(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max) { TVITEM item; @@ -128,12 +128,11 @@ { static int last_split; /* ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA); */ - static ChildWnd* pChildWnd; switch (message) { case WM_CREATE: pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams; - ASSERT(pChildWnd); + if (!pChildWnd) return 0; pChildWnd->nSplitPos = 250; pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW); pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/); Index: programs/regedit/framewnd.c =================================================================== RCS file: /var/cvs/wine/programs/regedit/framewnd.c,v retrieving revision 1.1 diff -u -r1.1 framewnd.c --- programs/regedit/framewnd.c 7 Aug 2003 03:10:13 -0000 1.1 +++ programs/regedit/framewnd.c 2 Dec 2003 03:42:58 -0000 @@ -436,6 +436,19 @@ */ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + HKEY hKeyRoot, hKey; + TCHAR keyPath[1000] = { 0 }; + TCHAR valueName[255] = { 0 }; + int keyPathLen = 0, item; + BOOL result = TRUE; + LONG lRet; + + hKeyRoot = FindRegRoot(pChildWnd->hTreeWnd, 0, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR)); + lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey); + if (lRet != ERROR_SUCCESS) hKey = 0; + item = ListView_GetNextItem(pChildWnd->hListWnd, -1, LVNI_FOCUSED); + if (item != -1) ListView_GetItemText(pChildWnd->hListWnd, item, 0, valueName, sizeof(valueName)/sizeof(TCHAR)); + switch (LOWORD(wParam)) { /* Parse the menu selections:*/ case ID_REGISTRY_IMPORTREGISTRYFILE: @@ -451,6 +464,10 @@ case ID_REGISTRY_PRINT: PrintRegistryHive(hWnd, _T("")); break; + case ID_EDIT_MODIFY: + if (ModifyValue(hWnd, hKey, valueName)) + RefreshListView(pChildWnd->hListWnd, hKeyRoot, keyPath); + break; case ID_EDIT_COPYKEYNAME: CopyKeyName(hWnd, _T("")); break; @@ -486,9 +503,11 @@ #endif break; default: - return FALSE; - } - return TRUE; + result = FALSE; + } + + RegCloseKey(hKey); + return result; } /******************************************************************************** Index: programs/regedit/main.c =================================================================== RCS file: /var/cvs/wine/programs/regedit/main.c,v retrieving revision 1.3 diff -u -r1.3 main.c --- programs/regedit/main.c 26 Nov 2003 04:09:00 -0000 1.3 +++ programs/regedit/main.c 1 Dec 2003 21:30:23 -0000 @@ -100,6 +100,8 @@ d(GetMessageA) d(GetSubMenu) d(GetSystemMetrics) + d(GetWindowTextA) + d(GetWindowTextLengthA) d(InvertRect) d(IsWindowVisible) d(LoadAcceleratorsA) @@ -110,6 +112,7 @@ d(LoadMenuA) d(LoadStringA) d(MessageBeep) + d(MessageBoxA) d(MoveWindow) d(OpenClipboard) d(PostQuitMessage) @@ -121,6 +124,7 @@ d(SendMessageA) d(SetCapture) d(SetCursor) + d(SetDlgItemTextA) d(SetFocus) d(SetWindowLongA) d(SetWindowTextA) Index: programs/regedit/main.h =================================================================== RCS file: /var/cvs/wine/programs/regedit/main.h,v retrieving revision 1.4 diff -u -r1.4 main.h --- programs/regedit/main.h 26 Nov 2003 04:09:00 -0000 1.4 +++ programs/regedit/main.h 2 Dec 2003 03:38:27 -0000 @@ -37,6 +37,7 @@ #define SPLIT_WIDTH 5 #define MAX_NAME_LEN 500 +#define COUNT_OF(a) (sizeof(a)/sizeof(a[0])) /******************************************************************************/ @@ -59,6 +60,7 @@ WINDOWPLACEMENT pos; TCHAR szPath[MAX_PATH]; } ChildWnd; +extern ChildWnd* pChildWnd; /******************************************************************************* * Global Variables: @@ -126,6 +128,8 @@ d(GetStockObject) d(GetSubMenu) d(GetSystemMetrics) +d(GetWindowTextA) +d(GetWindowTextLengthA) d(ImageList_Add) d(ImageList_Create) d(ImageList_GetImageCount) @@ -140,6 +144,7 @@ d(LoadMenuA) d(LoadStringA) d(MessageBeep) +d(MessageBoxA) d(MoveWindow) d(OpenClipboard) d(PostQuitMessage) @@ -152,6 +157,7 @@ d(SendMessageA) d(SetCapture) d(SetCursor) +d(SetDlgItemTextA) d(SetFocus) d(SetWindowLongA) d(SetWindowTextA) @@ -197,6 +203,8 @@ #define GetStockObject pGetStockObject #define GetSubMenu pGetSubMenu #define GetSystemMetrics pGetSystemMetrics +#define GetWindowTextA pGetWindowTextA +#define GetWindowTextLengthA pGetWindowTextLengthA #define ImageList_Add pImageList_Add #define ImageList_Create pImageList_Create #define ImageList_GetImageCount pImageList_GetImageCount @@ -211,6 +219,7 @@ #define LoadMenuA pLoadMenuA #define LoadStringA pLoadStringA #define MessageBeep pMessageBeep +#define MessageBoxA pMessageBoxA #define MoveWindow pMoveWindow #define OpenClipboard pOpenClipboard #define PostQuitMessage pPostQuitMessage @@ -223,6 +232,7 @@ #define SendMessageA pSendMessageA #define SetCapture pSetCapture #define SetCursor pSetCursor +#define SetDlgItemTextA pSetDlgItemTextA #define SetFocus pSetFocus #define SetWindowLongA pSetWindowLongA #define SetWindowTextA pSetWindowTextA @@ -256,5 +266,8 @@ extern HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id); extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv); extern HKEY FindRegRoot(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max); + +/* edit.c */ +BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName); #endif /* __MAIN_H__ */ Index: programs/regedit/resource.h =================================================================== RCS file: /var/cvs/wine/programs/regedit/resource.h,v retrieving revision 1.1 diff -u -r1.1 resource.h --- programs/regedit/resource.h 7 Aug 2003 03:10:13 -0000 1.1 +++ programs/regedit/resource.h 1 Dec 2003 18:11:06 -0000 @@ -102,4 +102,13 @@ #define ID_REGISTRY_PRINTERSETUP 32833 #define ID_REGISTRY_SAVESUBTREEAS 32834 #define IDS_LICENSE 32835 +#define IDS_ERROR 32836 +#define IDS_BAD_VALUE 32837 +#define IDS_UNSUPPORTED_TYPE 32838 +#define IDS_TOO_BIG_VALUE 32839 + +#define IDD_EDIT_STRING 2000 +#define IDC_VALUE_NAME 2001 +#define IDC_VALUE_DATA 2002 + #define IDC_STATIC -1 Index: programs/regedit/treeview.c =================================================================== RCS file: /var/cvs/wine/programs/regedit/treeview.c,v retrieving revision 1.2 diff -u -r1.2 treeview.c --- programs/regedit/treeview.c 8 Aug 2003 21:03:39 -0000 1.2 +++ programs/regedit/treeview.c 1 Dec 2003 06:55:30 -0000 @@ -48,6 +48,9 @@ { HKEY hKey = NULL; TVITEM item; + + if (!hItem) hItem = TreeView_GetSelection(hwndTV); + item.mask = TVIF_PARAM; item.hItem = TreeView_GetParent(hwndTV, hItem); --- /dev/null 2003-01-30 05:24:37.000000000 -0500 +++ programs/regedit/edit.c 2003-12-01 22:37:39.000000000 -0500 @@ -0,0 +1,136 @@ +/* + * Registry editing UI functions. + * + * Copyright (C) 2003 Dimitrie O. Paun + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ + +#include <windows.h> +#include <tchar.h> +#include <commctrl.h> +#include <commdlg.h> +#include <cderr.h> +#include <stdlib.h> +#include <stdio.h> +#include <shellapi.h> + +#include "main.h" +#include "regproc.h" +#include "resource.h" + +static TCHAR* editValueName; +static TCHAR* stringValueData; + +void error(HWND hwnd, INT resId, ...) +{ + 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))) + lstrcpy(title, "Error"); + + if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt))) + lstrcpy(errfmt, "Unknown error string!"); + + va_start(ap, resId); + _vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap); + va_end(ap); + + MessageBox(hwnd, errstr, title, MB_OK | MB_ICONERROR); +} + +INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + TCHAR* valueData; + HWND hwndValue; + int len; + + switch(uMsg) { + case WM_INITDIALOG: + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); + SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); + return TRUE; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) { + if ((len = GetWindowTextLength(hwndValue))) { + if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) { + stringValueData = valueData; + if (!GetWindowText(hwndValue, stringValueData, len + 1)) + *stringValueData = 0; + } + } + } + /* Fall through */ + case IDCANCEL: + EndDialog(hwndDlg, wParam); + return TRUE; + } + } + return FALSE; +} + +BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName) +{ + DWORD valueDataLen; + DWORD type; + LONG lRet; + BOOL result = FALSE; + + if (!hKey || !valueName) return FALSE; + + editValueName = valueName; + + lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &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) { + 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); + } else { + error(hwnd, IDS_UNSUPPORTED_TYPE, type); + } + +done: + HeapFree(GetProcessHeap(), 0, stringValueData); + stringValueData = NULL; + + return result; +} -- Dimi.