regedit: Convert key creation to unicode.

This commit is contained in:
Alexander Nicolaysen Sørnes 2008-08-21 23:49:34 +02:00 committed by Alexandre Julliard
parent f208025228
commit a6a4109dd4
4 changed files with 27 additions and 18 deletions

View File

@ -242,33 +242,33 @@ done:
return NULL; return NULL;
} }
BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPTSTR keyName) BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR keyName)
{ {
BOOL result = FALSE; BOOL result = FALSE;
LONG lRet = ERROR_SUCCESS; LONG lRet = ERROR_SUCCESS;
HKEY retKey = NULL; HKEY retKey = NULL;
TCHAR newKey[MAX_NEW_KEY_LEN - 4]; WCHAR newKey[MAX_NEW_KEY_LEN - 4];
int keyNum; int keyNum;
HKEY hKey; HKEY hKey;
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_CREATE_SUB_KEY, &hKey); lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_CREATE_SUB_KEY, &hKey);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
error_code_messagebox(hwnd, lRet); error_code_messagebox(hwnd, lRet);
goto done; goto done;
} }
if (!LoadString(GetModuleHandle(0), IDS_NEWKEY, newKey, COUNT_OF(newKey))) goto done; if (!LoadStringW(GetModuleHandle(0), IDS_NEWKEY, newKey, COUNT_OF(newKey))) goto done;
/* try to find out a name for the newly create key (max 100 times) */ /* try to find out a name for the newly create key (max 100 times) */
for (keyNum = 1; keyNum < 100; keyNum++) { for (keyNum = 1; keyNum < 100; keyNum++) {
wsprintf(keyName, newKey, keyNum); wsprintfW(keyName, newKey, keyNum);
lRet = RegOpenKey(hKey, keyName, &retKey); lRet = RegOpenKeyW(hKey, keyName, &retKey);
if (lRet != ERROR_SUCCESS) break; if (lRet != ERROR_SUCCESS) break;
RegCloseKey(retKey); RegCloseKey(retKey);
} }
if (lRet == ERROR_SUCCESS) goto done; if (lRet == ERROR_SUCCESS) goto done;
lRet = RegCreateKey(hKey, keyName, &retKey); lRet = RegCreateKeyW(hKey, keyName, &retKey);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
error_code_messagebox(hwnd, lRet); error_code_messagebox(hwnd, lRet);
goto done; goto done;

View File

@ -761,10 +761,15 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break; break;
} }
case ID_EDIT_NEW_KEY: case ID_EDIT_NEW_KEY:
if (CreateKey(hWnd, hKeyRoot, keyPath, newKey)) { {
if (InsertNode(g_pChildWnd->hTreeWnd, 0, newKey)) WCHAR newKeyW[MAX_NEW_KEY_LEN];
StartKeyRename(g_pChildWnd->hTreeWnd); WCHAR* keyPathW = GetWideString(keyPath);
} if (CreateKey(hWnd, hKeyRoot, keyPathW, newKeyW)) {
if (InsertNode(g_pChildWnd->hTreeWnd, 0, newKeyW))
StartKeyRename(g_pChildWnd->hTreeWnd);
}
HeapFree(GetProcessHeap(), 0, keyPathW);
}
break; break;
case ID_EDIT_NEW_STRINGVALUE: case ID_EDIT_NEW_STRINGVALUE:
valueType = REG_SZ; valueType = REG_SZ;

View File

@ -134,13 +134,13 @@ extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv);
extern LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); extern LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
extern LPWSTR GetItemPathW(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); extern LPWSTR GetItemPathW(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
extern BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem); extern BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem);
extern HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name); extern HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR name);
extern HWND StartKeyRename(HWND hwndTV); extern HWND StartKeyRename(HWND hwndTV);
extern HTREEITEM FindPathInTree(HWND hwndTV, LPCTSTR lpKeyName); extern HTREEITEM FindPathInTree(HWND hwndTV, LPCTSTR lpKeyName);
extern HTREEITEM FindNext(HWND hwndTV, HTREEITEM hItem, LPCTSTR sstring, int mode, int *row); extern HTREEITEM FindNext(HWND hwndTV, HTREEITEM hItem, LPCTSTR sstring, int mode, int *row);
/* edit.c */ /* edit.c */
extern BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPTSTR newKeyName); extern BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR newKeyName);
extern BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPTSTR valueName); extern BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPTSTR valueName);
extern BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName); extern BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName);
extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath); extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath);

View File

@ -518,7 +518,7 @@ BOOL RefreshTreeView(HWND hwndTV)
return TRUE; return TRUE;
} }
HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name) HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR name)
{ {
TCHAR buf[MAX_NEW_KEY_LEN]; TCHAR buf[MAX_NEW_KEY_LEN];
HTREEITEM hNewItem = 0; HTREEITEM hNewItem = 0;
@ -527,7 +527,9 @@ HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name)
if (!hItem) hItem = TreeView_GetSelection(hwndTV); if (!hItem) hItem = TreeView_GetSelection(hwndTV);
if (!hItem) return FALSE; if (!hItem) return FALSE;
if (TreeView_GetItemState(hwndTV, hItem, TVIS_EXPANDEDONCE)) { if (TreeView_GetItemState(hwndTV, hItem, TVIS_EXPANDEDONCE)) {
hNewItem = AddEntryToTree(hwndTV, hItem, name, 0, 0); char* nameA = GetMultiByteString(name);
hNewItem = AddEntryToTree(hwndTV, hItem, nameA, 0, 0);
HeapFree(GetProcessHeap(), 0, nameA);
} else { } else {
item.mask = TVIF_CHILDREN | TVIF_HANDLE; item.mask = TVIF_CHILDREN | TVIF_HANDLE;
item.hItem = hItem; item.hItem = hItem;
@ -535,19 +537,21 @@ HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name)
item.cChildren = 1; item.cChildren = 1;
if (!TreeView_SetItem(hwndTV, &item)) return FALSE; if (!TreeView_SetItem(hwndTV, &item)) return FALSE;
} }
SendMessage(hwndTV, TVM_EXPAND, TVE_EXPAND, (LPARAM)hItem ); SendMessageW(hwndTV, TVM_EXPAND, TVE_EXPAND, (LPARAM)hItem );
if (!hNewItem) { if (!hNewItem) {
char* nameA = GetMultiByteString(name);
for(hNewItem = TreeView_GetChild(hwndTV, hItem); hNewItem; hNewItem = TreeView_GetNextSibling(hwndTV, hNewItem)) { for(hNewItem = TreeView_GetChild(hwndTV, hItem); hNewItem; hNewItem = TreeView_GetNextSibling(hwndTV, hNewItem)) {
item.mask = TVIF_HANDLE | TVIF_TEXT; item.mask = TVIF_HANDLE | TVIF_TEXT;
item.hItem = hNewItem; item.hItem = hNewItem;
item.pszText = buf; item.pszText = buf;
item.cchTextMax = COUNT_OF(buf); item.cchTextMax = COUNT_OF(buf);
if (!TreeView_GetItem(hwndTV, &item)) continue; if (!TreeView_GetItem(hwndTV, &item)) continue;
if (lstrcmp(name, item.pszText) == 0) break; if (lstrcmp(nameA, item.pszText) == 0) break;
} }
HeapFree(GetProcessHeap(), 0, nameA);
} }
if (hNewItem) if (hNewItem)
SendMessage(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hNewItem); SendMessageW(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hNewItem);
return hNewItem; return hNewItem;
} }