Add value delete, and dword edit support.
This commit is contained in:
parent
41b7218466
commit
4352892f60
@ -132,6 +132,21 @@ BEGIN
|
|||||||
DEFPUSHBUTTON "Cancel",IDCANCEL,175,60,30,11,WS_GROUP
|
DEFPUSHBUTTON "Cancel",IDCANCEL,175,60,30,11,WS_GROUP
|
||||||
END
|
END
|
||||||
|
|
||||||
|
IDD_EDIT_DWORD DIALOG DISCARDABLE 22, 17, 210, 100
|
||||||
|
STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
|
||||||
|
CAPTION "Edit String"
|
||||||
|
FONT 8, "System"
|
||||||
|
BEGIN
|
||||||
|
LTEXT "Value name:",IDC_STATIC,5,5,119,8
|
||||||
|
EDITTEXT IDC_VALUE_NAME,5,15,200,12, WS_BORDER | WS_TABSTOP | WS_DISABLED
|
||||||
|
LTEXT "Value data:",IDC_STATIC,5,30,90,8
|
||||||
|
EDITTEXT IDC_VALUE_DATA,5,40,90,12, WS_BORDER | WS_TABSTOP
|
||||||
|
GROUPBOX "Base", IDC_DWORD_BASE, 120, 30, 85, 37, BS_GROUPBOX
|
||||||
|
AUTORADIOBUTTON "Hexadecimal", IDC_DWORD_HEX, 130, 40, 60, 10, WS_TABSTOP
|
||||||
|
AUTORADIOBUTTON "Decimal", IDC_DWORD_DEC, 130, 52, 60, 10, WS_TABSTOP
|
||||||
|
DEFPUSHBUTTON "OK",IDOK,140,80,30,11,WS_GROUP
|
||||||
|
DEFPUSHBUTTON "Cancel",IDCANCEL,175,80,30,11,WS_GROUP
|
||||||
|
END
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* String Table
|
* String Table
|
||||||
@ -201,6 +216,8 @@ BEGIN
|
|||||||
IDS_BAD_VALUE "Can't query value '%s'"
|
IDS_BAD_VALUE "Can't query value '%s'"
|
||||||
IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)"
|
IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)"
|
||||||
IDS_TOO_BIG_VALUE "Value is too big (%ld)"
|
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"
|
||||||
END
|
END
|
||||||
|
|
||||||
|
@ -35,31 +35,58 @@
|
|||||||
|
|
||||||
static const TCHAR* editValueName;
|
static const TCHAR* editValueName;
|
||||||
static TCHAR* stringValueData;
|
static TCHAR* stringValueData;
|
||||||
|
static BOOL isDecimal;
|
||||||
|
|
||||||
|
INT vmessagebox(HWND hwnd, INT buttons, INT titleId, INT resId, va_list ap)
|
||||||
|
{
|
||||||
|
TCHAR title[256];
|
||||||
|
TCHAR errfmt[1024];
|
||||||
|
TCHAR errstr[1024];
|
||||||
|
|
||||||
|
if (!LoadString(hInst, titleId, title, COUNT_OF(title)))
|
||||||
|
lstrcpy(title, "Error");
|
||||||
|
|
||||||
|
if (!LoadString(hInst, resId, errfmt, COUNT_OF(errfmt)))
|
||||||
|
lstrcpy(errfmt, "Unknown error string!");
|
||||||
|
|
||||||
|
_vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap);
|
||||||
|
|
||||||
|
return MessageBox(hwnd, errstr, title, buttons);
|
||||||
|
}
|
||||||
|
|
||||||
|
INT messagebox(HWND hwnd, INT buttons, INT titleId, INT resId, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
INT result;
|
||||||
|
|
||||||
|
va_start(ap, resId);
|
||||||
|
result = vmessagebox(hwnd, buttons, titleId, resId, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void error(HWND hwnd, INT resId, ...)
|
void error(HWND hwnd, INT resId, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
TCHAR title[256];
|
|
||||||
TCHAR errfmt[1024];
|
|
||||||
TCHAR errstr[1024];
|
|
||||||
HINSTANCE hInstance;
|
|
||||||
|
|
||||||
hInstance = GetModuleHandle(0);
|
|
||||||
|
|
||||||
if (!LoadString(hInstance, IDS_ERROR, title, COUNT_OF(title)))
|
|
||||||
lstrcpy(title, "Error");
|
|
||||||
|
|
||||||
if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt)))
|
|
||||||
lstrcpy(errfmt, "Unknown error string!");
|
|
||||||
|
|
||||||
va_start(ap, resId);
|
va_start(ap, resId);
|
||||||
_vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap);
|
vmessagebox(hwnd, MB_OK | MB_ICONERROR, IDS_ERROR, resId, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
MessageBox(hwnd, errstr, title, MB_OK | MB_ICONERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
BOOL change_dword_base(HWND hwndDlg, BOOL toHex)
|
||||||
|
{
|
||||||
|
TCHAR buf[128];
|
||||||
|
DWORD val;
|
||||||
|
|
||||||
|
if (!GetDlgItemText(hwndDlg, IDC_VALUE_DATA, buf, COUNT_OF(buf))) return FALSE;
|
||||||
|
if (!_stscanf(buf, toHex ? "%ld" : "%lx", &val)) return FALSE;
|
||||||
|
wsprintf(buf, toHex ? "%lx" : "%ld", val);
|
||||||
|
return SetDlgItemText(hwndDlg, IDC_VALUE_DATA, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
TCHAR* valueData;
|
TCHAR* valueData;
|
||||||
HWND hwndValue;
|
HWND hwndValue;
|
||||||
@ -69,9 +96,16 @@ INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
|
|||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
|
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
|
||||||
SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData);
|
SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData);
|
||||||
|
CheckRadioButton(hwndDlg, IDC_DWORD_HEX, IDC_DWORD_DEC, isDecimal ? IDC_DWORD_DEC : IDC_DWORD_HEX);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
switch (LOWORD(wParam)) {
|
switch (LOWORD(wParam)) {
|
||||||
|
case IDC_DWORD_HEX:
|
||||||
|
if (isDecimal && change_dword_base(hwndDlg, TRUE)) isDecimal = FALSE;
|
||||||
|
break;
|
||||||
|
case IDC_DWORD_DEC:
|
||||||
|
if (!isDecimal && change_dword_base(hwndDlg, FALSE)) isDecimal = TRUE;
|
||||||
|
break;
|
||||||
case IDOK:
|
case IDOK:
|
||||||
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
|
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
|
||||||
if ((len = GetWindowTextLength(hwndValue))) {
|
if ((len = GetWindowTextLength(hwndValue))) {
|
||||||
@ -108,7 +142,7 @@ BOOL CreateKey(HKEY hKey)
|
|||||||
if (newKey[0] == 0) {
|
if (newKey[0] == 0) {
|
||||||
hInstance = GetModuleHandle(0);
|
hInstance = GetModuleHandle(0);
|
||||||
if (!LoadString(hInstance, IDS_NEWKEY, newKey, COUNT_OF(newKey)))
|
if (!LoadString(hInstance, IDS_NEWKEY, newKey, COUNT_OF(newKey)))
|
||||||
lstrcpy(newKey, "new key");
|
lstrcpy(newKey, "New Key");
|
||||||
}
|
}
|
||||||
lstrcpy(keyName, newKey);
|
lstrcpy(keyName, newKey);
|
||||||
|
|
||||||
@ -116,8 +150,8 @@ BOOL CreateKey(HKEY hKey)
|
|||||||
We try it max 100 times. */
|
We try it max 100 times. */
|
||||||
lRet = RegOpenKey(hKey, keyName, &retKey);
|
lRet = RegOpenKey(hKey, keyName, &retKey);
|
||||||
while (lRet == ERROR_SUCCESS && keyNum < 100) {
|
while (lRet == ERROR_SUCCESS && keyNum < 100) {
|
||||||
sprintf(keyName, "%s %u", newKey, ++keyNum);
|
wsprintf(keyName, "%s %u", newKey, ++keyNum);
|
||||||
lRet = RegOpenKey(hKey, keyName, &retKey);
|
lRet = RegOpenKey(hKey, keyName, &retKey);
|
||||||
}
|
}
|
||||||
if (lRet == ERROR_SUCCESS) return FALSE;
|
if (lRet == ERROR_SUCCESS) return FALSE;
|
||||||
|
|
||||||
@ -141,23 +175,31 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
|
|||||||
error(hwnd, IDS_BAD_VALUE, valueName);
|
error(hwnd, IDS_BAD_VALUE, valueName);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
if ( type == REG_DWORD ) valueDataLen = 128;
|
||||||
|
if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) {
|
||||||
|
error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
lRet = RegQueryValueEx(hKey, valueName, 0, 0, stringValueData, &valueDataLen);
|
||||||
|
if (lRet != ERROR_SUCCESS) {
|
||||||
|
error(hwnd, IDS_BAD_VALUE, valueName);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
|
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
|
||||||
if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) {
|
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) {
|
||||||
error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
lRet = RegQueryValueEx(hKey, valueName, 0, 0, stringValueData, &valueDataLen);
|
|
||||||
if (lRet != ERROR_SUCCESS) {
|
|
||||||
error(hwnd, IDS_BAD_VALUE, valueName);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) {
|
|
||||||
lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1);
|
lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1);
|
||||||
if (lRet == ERROR_SUCCESS) result = TRUE;
|
if (lRet == ERROR_SUCCESS) result = TRUE;
|
||||||
}
|
}
|
||||||
} else if ( type == REG_DWORD ) {
|
} else if ( type == REG_DWORD ) {
|
||||||
MessageBox(hwnd, "Can't edit dwords for now", "Error", MB_OK | MB_ICONERROR);
|
wsprintf(stringValueData, isDecimal ? "%ld" : "%lx", *((DWORD*)stringValueData));
|
||||||
|
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_DWORD), hwnd, modify_dlgproc) == IDOK) {
|
||||||
|
DWORD val;
|
||||||
|
if (_stscanf(stringValueData, isDecimal ? "%ld" : "%lx", &val)) {
|
||||||
|
lRet = RegSetValueEx(hKey, valueName, 0, type, (BYTE*)&val, sizeof(val));
|
||||||
|
if (lRet == ERROR_SUCCESS) result = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error(hwnd, IDS_UNSUPPORTED_TYPE, type);
|
error(hwnd, IDS_UNSUPPORTED_TYPE, type);
|
||||||
}
|
}
|
||||||
@ -168,3 +210,19 @@ done:
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
|
||||||
|
{
|
||||||
|
LONG lRet;
|
||||||
|
|
||||||
|
if (!hKey || !valueName) return FALSE;
|
||||||
|
|
||||||
|
if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, valueName) != IDYES)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
lRet = RegDeleteValue(hKey, valueName);
|
||||||
|
if (lRet != ERROR_SUCCESS) {
|
||||||
|
error(hwnd, IDS_BAD_VALUE, valueName);
|
||||||
|
}
|
||||||
|
return lRet == ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
@ -441,12 +441,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
BOOL result = TRUE;
|
BOOL result = TRUE;
|
||||||
LONG lRet;
|
LONG lRet;
|
||||||
|
|
||||||
keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
|
if ((keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot))) {
|
||||||
valueName = GetValueName(g_pChildWnd->hListWnd);
|
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_ALL_ACCESS, &hKey);
|
||||||
if (keyPath) {
|
|
||||||
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey);
|
|
||||||
if (lRet != ERROR_SUCCESS) hKey = 0;
|
if (lRet != ERROR_SUCCESS) hKey = 0;
|
||||||
}
|
}
|
||||||
|
valueName = GetValueName(g_pChildWnd->hListWnd);
|
||||||
|
|
||||||
switch (LOWORD(wParam)) {
|
switch (LOWORD(wParam)) {
|
||||||
case ID_REGISTRY_IMPORTREGISTRYFILE:
|
case ID_REGISTRY_IMPORTREGISTRYFILE:
|
||||||
@ -462,6 +461,10 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case ID_REGISTRY_PRINT:
|
case ID_REGISTRY_PRINT:
|
||||||
PrintRegistryHive(hWnd, _T(""));
|
PrintRegistryHive(hWnd, _T(""));
|
||||||
break;
|
break;
|
||||||
|
case ID_EDIT_DELETE:
|
||||||
|
if (DeleteValue(hWnd, hKey, valueName))
|
||||||
|
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
|
||||||
|
break;
|
||||||
case ID_EDIT_MODIFY:
|
case ID_EDIT_MODIFY:
|
||||||
if (ModifyValue(hWnd, hKey, valueName))
|
if (ModifyValue(hWnd, hKey, valueName))
|
||||||
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
|
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
|
||||||
|
@ -93,7 +93,8 @@ extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv);
|
|||||||
extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
|
extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
|
||||||
|
|
||||||
/* edit.c */
|
/* edit.c */
|
||||||
BOOL CreateKey(HKEY hKey);
|
extern BOOL CreateKey(HKEY hKey);
|
||||||
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
|
extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
|
||||||
|
extern BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
|
||||||
|
|
||||||
#endif /* __MAIN_H__ */
|
#endif /* __MAIN_H__ */
|
||||||
|
@ -106,7 +106,13 @@
|
|||||||
#define IDS_BAD_VALUE 32837
|
#define IDS_BAD_VALUE 32837
|
||||||
#define IDS_UNSUPPORTED_TYPE 32838
|
#define IDS_UNSUPPORTED_TYPE 32838
|
||||||
#define IDS_TOO_BIG_VALUE 32839
|
#define IDS_TOO_BIG_VALUE 32839
|
||||||
#define IDS_NEWKEY 32840
|
#define IDS_DELETE_BOX_TITLE 32840
|
||||||
|
#define IDS_DELETE_BOX_TEXT 32841
|
||||||
|
#define IDD_EDIT_DWORD 32850
|
||||||
|
#define IDC_DWORD_BASE 32852
|
||||||
|
#define IDC_DWORD_HEX 32853
|
||||||
|
#define IDC_DWORD_DEC 32854
|
||||||
|
#define IDS_NEWKEY 32860
|
||||||
|
|
||||||
#define IDD_EDIT_STRING 2000
|
#define IDD_EDIT_STRING 2000
|
||||||
#define IDC_VALUE_NAME 2001
|
#define IDC_VALUE_NAME 2001
|
||||||
|
@ -99,7 +99,6 @@ LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
|
|||||||
if (!hItem) hItem = TreeView_GetSelection(hwndTV);
|
if (!hItem) hItem = TreeView_GetSelection(hwndTV);
|
||||||
if (!hItem) return NULL;
|
if (!hItem) return NULL;
|
||||||
if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL;
|
if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL;
|
||||||
printf("hRoot=%p, keyPath='%s'\n", *phRootKey, pathBuffer);
|
|
||||||
return pathBuffer;
|
return pathBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +234,6 @@ BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW* pnmtv)
|
|||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
}
|
}
|
||||||
if (errCode != ERROR_SUCCESS) dwSubCount = 0;
|
if (errCode != ERROR_SUCCESS) dwSubCount = 0;
|
||||||
printf("dwSubCount=%ld, Name=%s\n", dwSubCount, Name);
|
|
||||||
AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwSubCount);
|
AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwSubCount);
|
||||||
}
|
}
|
||||||
RegCloseKey(hNewKey);
|
RegCloseKey(hNewKey);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user