From a6a4109dd446a6306bbe9c6ed88a1533d7c8be6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Thu, 21 Aug 2008 23:49:34 +0200 Subject: [PATCH] regedit: Convert key creation to unicode. --- programs/regedit/edit.c | 14 +++++++------- programs/regedit/framewnd.c | 13 +++++++++---- programs/regedit/main.h | 4 ++-- programs/regedit/treeview.c | 14 +++++++++----- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/programs/regedit/edit.c b/programs/regedit/edit.c index f9a5abffa11..1c26baa5ad4 100644 --- a/programs/regedit/edit.c +++ b/programs/regedit/edit.c @@ -242,33 +242,33 @@ done: 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; LONG lRet = ERROR_SUCCESS; HKEY retKey = NULL; - TCHAR newKey[MAX_NEW_KEY_LEN - 4]; + WCHAR newKey[MAX_NEW_KEY_LEN - 4]; int keyNum; 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) { error_code_messagebox(hwnd, lRet); 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) */ for (keyNum = 1; keyNum < 100; keyNum++) { - wsprintf(keyName, newKey, keyNum); - lRet = RegOpenKey(hKey, keyName, &retKey); + wsprintfW(keyName, newKey, keyNum); + lRet = RegOpenKeyW(hKey, keyName, &retKey); if (lRet != ERROR_SUCCESS) break; RegCloseKey(retKey); } if (lRet == ERROR_SUCCESS) goto done; - lRet = RegCreateKey(hKey, keyName, &retKey); + lRet = RegCreateKeyW(hKey, keyName, &retKey); if (lRet != ERROR_SUCCESS) { error_code_messagebox(hwnd, lRet); goto done; diff --git a/programs/regedit/framewnd.c b/programs/regedit/framewnd.c index 51c94cc955c..e8a6bf5edfe 100644 --- a/programs/regedit/framewnd.c +++ b/programs/regedit/framewnd.c @@ -761,10 +761,15 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; } case ID_EDIT_NEW_KEY: - if (CreateKey(hWnd, hKeyRoot, keyPath, newKey)) { - if (InsertNode(g_pChildWnd->hTreeWnd, 0, newKey)) - StartKeyRename(g_pChildWnd->hTreeWnd); - } + { + WCHAR newKeyW[MAX_NEW_KEY_LEN]; + 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; case ID_EDIT_NEW_STRINGVALUE: valueType = REG_SZ; diff --git a/programs/regedit/main.h b/programs/regedit/main.h index 6b5a098e203..885ab0d14f3 100644 --- a/programs/regedit/main.h +++ b/programs/regedit/main.h @@ -134,13 +134,13 @@ extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv); extern LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); extern LPWSTR GetItemPathW(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); 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 HTREEITEM FindPathInTree(HWND hwndTV, LPCTSTR lpKeyName); extern HTREEITEM FindNext(HWND hwndTV, HTREEITEM hItem, LPCTSTR sstring, int mode, int *row); /* 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 ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName); extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath); diff --git a/programs/regedit/treeview.c b/programs/regedit/treeview.c index 3261a66517c..61c13ad51c5 100644 --- a/programs/regedit/treeview.c +++ b/programs/regedit/treeview.c @@ -518,7 +518,7 @@ BOOL RefreshTreeView(HWND hwndTV) return TRUE; } -HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name) +HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR name) { TCHAR buf[MAX_NEW_KEY_LEN]; HTREEITEM hNewItem = 0; @@ -527,7 +527,9 @@ HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name) if (!hItem) hItem = TreeView_GetSelection(hwndTV); if (!hItem) return FALSE; 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 { item.mask = TVIF_CHILDREN | TVIF_HANDLE; item.hItem = hItem; @@ -535,19 +537,21 @@ HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name) item.cChildren = 1; 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) { + char* nameA = GetMultiByteString(name); for(hNewItem = TreeView_GetChild(hwndTV, hItem); hNewItem; hNewItem = TreeView_GetNextSibling(hwndTV, hNewItem)) { item.mask = TVIF_HANDLE | TVIF_TEXT; item.hItem = hNewItem; item.pszText = buf; item.cchTextMax = COUNT_OF(buf); 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) - SendMessage(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hNewItem); + SendMessageW(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hNewItem); return hNewItem; }