Add new value support. Misc improvements and cleanups.

oldstable
Dimitrie O. Paun 2004-01-06 20:38:56 +00:00 committed by Alexandre Julliard
parent ccd749684f
commit b3130b9f6d
5 changed files with 58 additions and 19 deletions

View File

@ -218,7 +218,8 @@ BEGIN
IDS_TOO_BIG_VALUE "Value is too big (%ld)"
IDS_DELETE_BOX_TITLE "Confirm Value Delete"
IDS_DELETE_BOX_TEXT "Are you sure you want to delete value '%s'?"
IDS_NEWKEY "New Key"
IDS_NEWKEY "New Key #%d"
IDS_NEWVALUE "New Value #%d"
END
/*****************************************************************/

View File

@ -127,36 +127,31 @@ INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
BOOL CreateKey(HKEY hKey)
{
LONG lRet;
LONG lRet = ERROR_SUCCESS;
HKEY retKey;
TCHAR keyName[32];
static TCHAR newKey[28] = ""; /* should be max keyName len - 4 */
HINSTANCE hInstance;
unsigned int keyNum = 1;
TCHAR newKey[COUNT_OF(keyName) - 4];
int keyNum;
/* 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);
if (!LoadString(GetModuleHandle(0), IDS_NEWKEY, newKey, COUNT_OF(newKey))) return FALSE;
/* 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) {
wsprintf(keyName, "%s %u", newKey, ++keyNum);
/* 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);
if (lRet != ERROR_SUCCESS) break;
RegCloseKey(retKey);
}
if (lRet == ERROR_SUCCESS) return FALSE;
lRet = RegCreateKey(hKey, keyName, &retKey);
return lRet == ERROR_SUCCESS;
if (lRet != ERROR_SUCCESS) return FALSE;
RegCloseKey(retKey);
return TRUE;
}
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
@ -226,3 +221,30 @@ BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
}
return lRet == ERROR_SUCCESS;
}
BOOL CreateValue(HWND hwnd, HKEY hKey, DWORD valueType)
{
LONG lRet = ERROR_SUCCESS;
TCHAR valueName[32];
TCHAR newValue[COUNT_OF(valueName) - 4];
DWORD valueDword = 0;
int valueNum;
/* If we have illegal parameter return with operation failure */
if (!hKey) return FALSE;
if (!LoadString(GetModuleHandle(0), IDS_NEWVALUE, newValue, COUNT_OF(newValue))) return FALSE;
/* try to find out a name for the newly create key (max 100 times) */
for (valueNum = 1; valueNum < 100; valueNum++) {
wsprintf(valueName, newValue, valueNum);
lRet = RegQueryValueEx(hKey, valueName, 0, 0, 0, 0);
if (lRet != ERROR_SUCCESS) break;
}
if (lRet == ERROR_SUCCESS) return FALSE;
lRet = RegSetValueEx(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD));
if (lRet != ERROR_SUCCESS) return FALSE;
return TRUE;
}

View File

@ -440,6 +440,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LPCTSTR valueName;
BOOL result = TRUE;
LONG lRet;
DWORD valueType;
if ((keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot))) {
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_ALL_ACCESS, &hKey);
@ -475,6 +476,19 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_EDIT_NEW_KEY:
CreateKey(hKey);
break;
case ID_EDIT_NEW_STRINGVALUE:
valueType = REG_SZ;
goto create_value;
case ID_EDIT_NEW_BINARYVALUE:
valueType = REG_BINARY;
goto create_value;
case ID_EDIT_NEW_DWORDVALUE:
valueType = REG_DWORD;
/* fall through */
create_value:
if (CreateValue(hWnd, hKey, valueType))
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
break;
case ID_REGISTRY_PRINTERSETUP:
/*PRINTDLG pd;*/
/*PrintDlg(&pd);*/

View File

@ -94,6 +94,7 @@ extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
/* edit.c */
extern BOOL CreateKey(HKEY hKey);
extern BOOL CreateValue(HWND hwnd, HKEY hKey, DWORD valueType);
extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
extern BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);

View File

@ -113,6 +113,7 @@
#define IDC_DWORD_HEX 32853
#define IDC_DWORD_DEC 32854
#define IDS_NEWKEY 32860
#define IDS_NEWVALUE 32861
#define IDD_EDIT_STRING 2000
#define IDC_VALUE_NAME 2001