New registry key adding patch

Zimler Attila hijaszu at hlfslinux.hu
Thu Jan 1 13:35:01 CST 2004


Dimitrie O. Paun wrote:

>You use LoadString() to load the string (look at how we load
>error strings in edit.c even though there it's simple since
>the buffer is fixed size for now).
>  
>
Am I loaded correctly the string? Could you verify it for me? If yes, I 
will send the patch for including in the CVS tree. If yes, could you 
tell me also, which is the next task, I could do?

Attila
-------------- next part --------------
Index: programs/regedit/En.rc
===================================================================
RCS file: /home/wine/wine/programs/regedit/En.rc,v
retrieving revision 1.3
diff -u -u -r1.3 En.rc
--- programs/regedit/En.rc	3 Dec 2003 20:25:24 -0000	1.3
+++ programs/regedit/En.rc	1 Jan 2004 18:27:02 -0000
@@ -201,6 +201,7 @@
     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_NEWKEY              "new key"
 END
 
 /*****************************************************************/
Index: programs/regedit/edit.c
===================================================================
RCS file: /home/wine/wine/programs/regedit/edit.c,v
retrieving revision 1.3
diff -u -u -r1.3 edit.c
--- programs/regedit/edit.c	12 Dec 2003 04:08:59 -0000	1.3
+++ programs/regedit/edit.c	1 Jan 2004 18:27:02 -0000
@@ -91,6 +91,40 @@
     return FALSE;
 }
 
+BOOL CreateKey(HKEY hKey)
+{
+    LONG lRet;
+    HKEY retKey;
+    TCHAR keyName[32];
+    static TCHAR newKey[28] = ""; /* should be max keyName len - 4 */
+    HINSTANCE hInstance;
+    unsigned int keyNum = 1;
+         
+    /* If we have illegal parameter return with operation failure */
+    if (!hKey) return FALSE;
+
+    /* Load localized "new key" string. -4 is because we need max 4 character
+	to numbering. */
+    if (newKey[0] == 0) {
+	hInstance = GetModuleHandle(0);
+	if (!LoadString(hInstance, IDS_NEWKEY, newKey, COUNT_OF(newKey)))
+    	    lstrcpy(newKey, "new key");
+    }
+    lstrcpy(keyName, newKey);
+
+    /* try to find out a name for the newly create key.
+	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);
+    }
+    if (lRet == ERROR_SUCCESS) return FALSE;
+    
+    lRet = RegCreateKey(hKey, keyName, &retKey);
+    return lRet == ERROR_SUCCESS;
+}
+
 BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
 {
     DWORD valueDataLen;
Index: programs/regedit/framewnd.c
===================================================================
RCS file: /home/wine/wine/programs/regedit/framewnd.c,v
retrieving revision 1.5
diff -u -u -r1.5 framewnd.c
--- programs/regedit/framewnd.c	12 Dec 2003 04:08:59 -0000	1.5
+++ programs/regedit/framewnd.c	1 Jan 2004 18:27:02 -0000
@@ -469,6 +469,9 @@
     case ID_EDIT_COPYKEYNAME:
         CopyKeyName(hWnd, _T(""));
         break;
+    case ID_EDIT_NEW_KEY:
+	CreateKey(hKey);
+	break;
     case ID_REGISTRY_PRINTERSETUP:
         /*PRINTDLG pd;*/
         /*PrintDlg(&pd);*/
Index: programs/regedit/main.h
===================================================================
RCS file: /home/wine/wine/programs/regedit/main.h,v
retrieving revision 1.8
diff -u -u -r1.8 main.h
--- programs/regedit/main.h	12 Dec 2003 04:08:59 -0000	1.8
+++ programs/regedit/main.h	1 Jan 2004 18:27:02 -0000
@@ -93,6 +93,7 @@
 extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
 
 /* edit.c */
+BOOL CreateKey(HKEY hKey);
 BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
 
 #endif /* __MAIN_H__ */
Index: programs/regedit/resource.h
===================================================================
RCS file: /home/wine/wine/programs/regedit/resource.h,v
retrieving revision 1.2
diff -u -u -r1.2 resource.h
--- programs/regedit/resource.h	3 Dec 2003 20:25:24 -0000	1.2
+++ programs/regedit/resource.h	1 Jan 2004 18:27:02 -0000
@@ -106,6 +106,7 @@
 #define IDS_BAD_VALUE			32837
 #define IDS_UNSUPPORTED_TYPE		32838
 #define IDS_TOO_BIG_VALUE		32839
+#define IDS_NEWKEY			32840
 
 #define IDD_EDIT_STRING			2000
 #define IDC_VALUE_NAME			2001


More information about the wine-devel mailing list