Regedit fix and enhancement

1.  Fixed a bug in suggestions if the selected key cycles
2.  Implemented "Copy Key Name"


svn path=/trunk/; revision=18766
This commit is contained in:
Nathan Woods 2005-10-24 23:46:55 +00:00
parent 0345348a28
commit 6d06e2139b
4 changed files with 49 additions and 30 deletions

View file

@ -138,7 +138,7 @@ BEGIN
MENUITEM "&Delete", ID_TREE_DELETE MENUITEM "&Delete", ID_TREE_DELETE
MENUITEM "&Rename", ID_TREE_RENAME MENUITEM "&Rename", ID_TREE_RENAME
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "&Copy Key Name", ID_EDIT_COPYKEYNAME, GRAYED MENUITEM "&Copy Key Name", ID_EDIT_COPYKEYNAME
END END
END END

View file

@ -143,6 +143,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
TreeView_DeleteItem(pChildWnd->hTreeWnd, hSelection); TreeView_DeleteItem(pChildWnd->hTreeWnd, hSelection);
} }
break; break;
case ID_EDIT_COPYKEYNAME:
hSelection = TreeView_GetSelection(pChildWnd->hTreeWnd);
keyPath = GetItemPath(pChildWnd->hTreeWnd, hSelection, &hRootKey);
CopyKeyName(hWnd, hRootKey, keyPath);
break;
case ID_EDIT_NEW_KEY: case ID_EDIT_NEW_KEY:
CreateNewKey(pChildWnd->hTreeWnd, TreeView_GetSelection(pChildWnd->hTreeWnd)); CreateNewKey(pChildWnd->hTreeWnd, TreeView_GetSelection(pChildWnd->hTreeWnd));
break; break;
@ -178,6 +183,8 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
* Key suggestion * Key suggestion
*/ */
#define MIN(a,b) ((a < b) ? (a) : (b))
static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions, static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions,
size_t iSuggestionsLength) size_t iSuggestionsLength)
{ {
@ -201,7 +208,9 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
if (RegQueryStringValue(hRootKey, pszKeyPath, NULL, if (RegQueryStringValue(hRootKey, pszKeyPath, NULL,
szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS) szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
{ {
if (szBuffer[0] != '\0') /* Sanity check this key; it cannot be empty, nor can it be a
* loop back */
if ((szBuffer[0] != '\0') && _tcsicmp(szBuffer, pszKeyPath))
{ {
if (RegOpenKey(hRootKey, szBuffer, &hOtherKey) == ERROR_SUCCESS) if (RegOpenKey(hRootKey, szBuffer, &hOtherKey) == ERROR_SUCCESS)
{ {
@ -211,7 +220,7 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
iSuggestionsLength -= i; iSuggestionsLength -= i;
lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength); lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength);
i = _tcslen(pszSuggestions) + 1; i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength);
pszSuggestions += i; pszSuggestions += i;
iSuggestionsLength -= i; iSuggestionsLength -= i;
RegCloseKey(hOtherKey); RegCloseKey(hOtherKey);
@ -223,7 +232,7 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
} }
} }
} }
while(bFound); while(bFound && (iSuggestionsLength > 0));
/* Check CLSID key */ /* Check CLSID key */
if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS) if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS)
@ -237,7 +246,7 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
iSuggestionsLength -= i; iSuggestionsLength -= i;
lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength); lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength);
i = _tcslen(pszSuggestions) + 1; i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength);
pszSuggestions += i; pszSuggestions += i;
iSuggestionsLength -= i; iSuggestionsLength -= i;
} }

View file

@ -470,34 +470,43 @@ BOOL PrintRegistryHive(HWND hWnd, LPTSTR path)
return TRUE; return TRUE;
} }
static BOOL CopyKeyName(HWND hWnd, LPCTSTR keyName) BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName)
{ {
BOOL result; BOOL bClipboardOpened = FALSE;
BOOL bSuccess = FALSE;
TCHAR szBuffer[512];
HGLOBAL hGlobal;
LPTSTR s;
result = OpenClipboard(hWnd); if (!OpenClipboard(hWnd))
if (result) { goto done;
result = EmptyClipboard(); bClipboardOpened = TRUE;
if (result) {
/*HANDLE hClipData;*/ if (!EmptyClipboard())
/*hClipData = SetClipboardData(UINT uFormat, HANDLE hMem);*/ goto done;
} else { if (!RegKeyGetName(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), hRootKey, keyName))
/* error emptying clipboard*/ goto done;
/* DWORD dwError = GetLastError(); */
; hGlobal = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(szBuffer) + 1) * sizeof(TCHAR));
} if (!hGlobal)
if (!CloseClipboard()) { goto done;
/* error closing clipboard*/
/* DWORD dwError = GetLastError(); */ s = GlobalLock(hGlobal);
; _tcscpy(s, szBuffer);
} GlobalUnlock(hGlobal);
} else {
/* error opening clipboard*/ #ifdef UNICODE
/* DWORD dwError = GetLastError(); */ SetClipboardData(CF_UNICODETEXT, hGlobal);
; #else
} SetClipboardData(CF_TEXT, hGlobal);
return result; #endif
bSuccess = TRUE;
done:
if (bClipboardOpened)
CloseClipboard();
return bSuccess;
} }
static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType) static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType)
@ -860,7 +869,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break; break;
} }
case ID_EDIT_COPYKEYNAME: case ID_EDIT_COPYKEYNAME:
CopyKeyName(hWnd, _T("")); CopyKeyName(hWnd, hKeyRoot, keyPath);
break; break;
case ID_EDIT_PERMISSIONS: case ID_EDIT_PERMISSIONS:
if(keyPath != NULL && _tcslen(keyPath) > 0) if(keyPath != NULL && _tcslen(keyPath) > 0)

View file

@ -89,6 +89,7 @@ extern LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM);
extern LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM); extern LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM);
extern void SetupStatusBar(HWND hWnd, BOOL bResize); extern void SetupStatusBar(HWND hWnd, BOOL bResize);
extern void UpdateStatusBar(void); extern void UpdateStatusBar(void);
extern BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName);
/* listview.c */ /* listview.c */
extern HWND CreateListView(HWND hwndParent, int id); extern HWND CreateListView(HWND hwndParent, int id);