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 "&Rename", ID_TREE_RENAME
MENUITEM SEPARATOR
MENUITEM "&Copy Key Name", ID_EDIT_COPYKEYNAME, GRAYED
MENUITEM "&Copy Key Name", ID_EDIT_COPYKEYNAME
END
END

View file

@ -143,6 +143,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
TreeView_DeleteItem(pChildWnd->hTreeWnd, hSelection);
}
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:
CreateNewKey(pChildWnd->hTreeWnd, TreeView_GetSelection(pChildWnd->hTreeWnd));
break;
@ -178,6 +183,8 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
* Key suggestion
*/
#define MIN(a,b) ((a < b) ? (a) : (b))
static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions,
size_t iSuggestionsLength)
{
@ -201,7 +208,9 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
if (RegQueryStringValue(hRootKey, pszKeyPath, NULL,
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)
{
@ -211,7 +220,7 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
iSuggestionsLength -= i;
lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength);
i = _tcslen(pszSuggestions) + 1;
i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength);
pszSuggestions += i;
iSuggestionsLength -= i;
RegCloseKey(hOtherKey);
@ -223,7 +232,7 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
}
}
}
while(bFound);
while(bFound && (iSuggestionsLength > 0));
/* Check CLSID key */
if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS)
@ -237,7 +246,7 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
iSuggestionsLength -= i;
lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength);
i = _tcslen(pszSuggestions) + 1;
i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength);
pszSuggestions += i;
iSuggestionsLength -= i;
}

View file

@ -470,34 +470,43 @@ BOOL PrintRegistryHive(HWND hWnd, LPTSTR path)
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 (result) {
result = EmptyClipboard();
if (result) {
if (!OpenClipboard(hWnd))
goto done;
bClipboardOpened = TRUE;
/*HANDLE hClipData;*/
/*hClipData = SetClipboardData(UINT uFormat, HANDLE hMem);*/
if (!EmptyClipboard())
goto done;
} else {
/* error emptying clipboard*/
/* DWORD dwError = GetLastError(); */
;
}
if (!CloseClipboard()) {
/* error closing clipboard*/
/* DWORD dwError = GetLastError(); */
;
}
} else {
/* error opening clipboard*/
/* DWORD dwError = GetLastError(); */
;
}
return result;
if (!RegKeyGetName(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), hRootKey, keyName))
goto done;
hGlobal = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(szBuffer) + 1) * sizeof(TCHAR));
if (!hGlobal)
goto done;
s = GlobalLock(hGlobal);
_tcscpy(s, szBuffer);
GlobalUnlock(hGlobal);
#ifdef UNICODE
SetClipboardData(CF_UNICODETEXT, hGlobal);
#else
SetClipboardData(CF_TEXT, hGlobal);
#endif
bSuccess = TRUE;
done:
if (bClipboardOpened)
CloseClipboard();
return bSuccess;
}
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;
}
case ID_EDIT_COPYKEYNAME:
CopyKeyName(hWnd, _T(""));
CopyKeyName(hWnd, hKeyRoot, keyPath);
break;
case ID_EDIT_PERMISSIONS:
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 void SetupStatusBar(HWND hWnd, BOOL bResize);
extern void UpdateStatusBar(void);
extern BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName);
/* listview.c */
extern HWND CreateListView(HWND hwndParent, int id);