reactos/subsys/system/regedit
diff -u -r1.5 -r1.6
--- edit.c 1 Jan 2004 22:29:12 -0000 1.5
+++ edit.c 5 Apr 2004 12:00:11 -0000 1.6
@@ -28,13 +28,25 @@
#include <stdlib.h>
#include <stdio.h>
#include <shellapi.h>
+#include <ctype.h>
#include "main.h"
#include "regproc.h"
#include "resource.h"
+
+typedef enum _EDIT_MODE
+{
+ EDIT_MODE_DEC,
+ EDIT_MODE_HEX
+} EDIT_MODE;
+
+
static const TCHAR* editValueName;
static TCHAR* stringValueData;
+static DWORD dwordValueData;
+static EDIT_MODE dwordEditMode = EDIT_MODE_HEX;
+
void error(HWND hwnd, INT resId, ...)
{
@@ -79,30 +91,35 @@
SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA));
return FALSE;
case WM_COMMAND:
- switch (LOWORD(wParam)) {
+ switch (LOWORD(wParam))
+ {
case IDOK:
- if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
- if ((len = GetWindowTextLength(hwndValue))) {
- if(stringValueData)
- {
- if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) {
- stringValueData = valueData;
- if (!GetWindowText(hwndValue, stringValueData, len + 1))
- *stringValueData = 0;
- }
+ if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA)))
+ {
+ if ((len = GetWindowTextLength(hwndValue)))
+ {
+ if (stringValueData)
+ {
+ if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR))))
+ {
+ stringValueData = valueData;
+ if (!GetWindowText(hwndValue, stringValueData, len + 1))
+ *stringValueData = 0;
+ }
}
else
{
- if ((valueData = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(TCHAR)))) {
- stringValueData = valueData;
- if (!GetWindowText(hwndValue, stringValueData, len + 1))
- *stringValueData = 0;
- }
+ if ((valueData = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(TCHAR))))
+ {
+ stringValueData = valueData;
+ if (!GetWindowText(hwndValue, stringValueData, len + 1))
+ *stringValueData = 0;
+ }
}
}
else
{
- if(stringValueData)
+ if (stringValueData)
*stringValueData = 0;
}
}
@@ -116,6 +133,173 @@
return FALSE;
}
+
+LRESULT CALLBACK DwordEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ WNDPROC oldwndproc;
+
+ oldwndproc = (WNDPROC)GetWindowLong(hwnd, GWL_USERDATA);
+
+ switch (uMsg)
+ {
+ case WM_CHAR:
+ if (dwordEditMode == EDIT_MODE_DEC)
+ {
+ if (isdigit(wParam & 0xff))
+ {
+ break;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else if (dwordEditMode == EDIT_MODE_HEX)
+ {
+ if (isxdigit(wParam & 0xff))
+ {
+ break;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ return CallWindowProc(oldwndproc, hwnd, uMsg, wParam, lParam);
+}
+
+
+INT_PTR CALLBACK modify_dword_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ WNDPROC oldproc;
+ TCHAR* valueData;
+ HWND hwndValue;
+ int len;
+ TCHAR ValueString[32];
+ LPTSTR Remainder;
+ DWORD Base;
+ DWORD Value;
+
+ switch(uMsg) {
+ case WM_INITDIALOG:
+ dwordEditMode = EDIT_MODE_HEX;
+
+ /* subclass the edit control */
+ hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA);
+ oldproc = (WNDPROC)GetWindowLong(hwndValue, GWL_WNDPROC);
+ SetWindowLong(hwndValue, GWL_USERDATA, (LONG)oldproc);
+ SetWindowLong(hwndValue, GWL_WNDPROC, (LONG)DwordEditSubclassProc);
+
+ if(editValueName && strcmp(editValueName, _T("")))
+ {
+ SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
+ }
+ else
+ {
+ SetDlgItemText(hwndDlg, IDC_VALUE_NAME, _T("(Default)"));
+ }
+ CheckRadioButton (hwndDlg, IDC_FORMAT_HEX, IDC_FORMAT_DEC, IDC_FORMAT_HEX);
+ sprintf (ValueString, "%lx", dwordValueData);
+ SetDlgItemText(hwndDlg, IDC_VALUE_DATA, ValueString);
+ SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA));
+ return FALSE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case IDC_FORMAT_HEX:
+ if (HIWORD(wParam) == BN_CLICKED && dwordEditMode == EDIT_MODE_DEC)
+ {
+ dwordEditMode = EDIT_MODE_HEX;
+ if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA)))
+ {
+ if ((len = GetWindowTextLength(hwndValue)))
+ {
+ if (!GetWindowText(hwndValue, ValueString, 32))
+ {
+ Value = 0;
+ }
+ else
+ {
+ Value = strtoul (ValueString, &Remainder, 10);
+ }
+ }
+ else
+ {
+ Value = 0;
+ }
+ }
+ sprintf (ValueString, "%lx", Value);
+ SetDlgItemText(hwndDlg, IDC_VALUE_DATA, ValueString);
+ return TRUE;
+ }
+ break;
+
+ case IDC_FORMAT_DEC:
+ if (HIWORD(wParam) == BN_CLICKED && dwordEditMode == EDIT_MODE_HEX)
+ {
+ dwordEditMode = EDIT_MODE_DEC;
+ if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA)))
+ {
+ if ((len = GetWindowTextLength(hwndValue)))
+ {
+ if (!GetWindowText(hwndValue, ValueString, 32))
+ {
+ Value = 0;
+ }
+ else
+ {
+ Value = strtoul (ValueString, &Remainder, 16);
+ }
+ }
+ else
+ {
+ Value = 0;
+ }
+ }
+ sprintf (ValueString, "%lu", Value);
+ SetDlgItemText(hwndDlg, IDC_VALUE_DATA, ValueString);
+ return TRUE;
+ }
+ break;
+
+ case IDOK:
+ if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA)))
+ {
+ if ((len = GetWindowTextLength(hwndValue)))
+ {
+ if (!GetWindowText(hwndValue, ValueString, 32))
+ {
+ EndDialog(hwndDlg, IDCANCEL);
+ return TRUE;
+ }
+
+ Base = (dwordEditMode == EDIT_MODE_HEX) ? 16 : 10;
+ dwordValueData = strtoul (ValueString, &Remainder, Base);
+ }
+ else
+ {
+ EndDialog(hwndDlg, IDCANCEL);
+ return TRUE;
+ }
+ }
+ EndDialog(hwndDlg, IDOK);
+ return TRUE;
+
+ case IDCANCEL:
+ EndDialog(hwndDlg, IDCANCEL);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
{
DWORD valueDataLen;
@@ -123,59 +307,85 @@
LONG lRet;
BOOL result = FALSE;
- if (!hKey) return FALSE;
+ if (!hKey)
+ return FALSE;
editValueName = valueName;
lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &valueDataLen);
- if(lRet != ERROR_SUCCESS && (!strcmp(valueName, _T("")) || valueName == NULL))
+ if (lRet != ERROR_SUCCESS && (!_tcscmp(valueName, _T("")) || valueName == NULL))
{
lRet = ERROR_SUCCESS; /* Allow editing of (Default) values which don't exist */
type = REG_SZ;
valueDataLen = 0;
stringValueData = NULL;
}
-
- if (lRet != ERROR_SUCCESS) {
+
+ if (lRet != ERROR_SUCCESS)
+ {
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
- if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
- if(valueDataLen > 0)
+ if ((type == REG_SZ) || (type == REG_EXPAND_SZ))
+ {
+ if (valueDataLen > 0)
{
- 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 (!(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;
+ }
}
else
{
- stringValueData = NULL;
+ stringValueData = NULL;
}
- if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) {
- if(stringValueData)
+
+ if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK)
+ {
+ if (stringValueData)
{
- lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1);
+ lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1);
}
else
- lRet = RegSetValueEx(hKey, valueName, 0, type, NULL, 0);
- if (lRet == ERROR_SUCCESS) result = TRUE;
+ {
+ lRet = RegSetValueEx(hKey, valueName, 0, type, NULL, 0);
+ }
+ if (lRet == ERROR_SUCCESS)
+ result = TRUE;
}
- } else if ( type == REG_DWORD ) {
- MessageBox(hwnd, "Can't edit dwords for now", "Error", MB_OK | MB_ICONERROR);
- } else {
+ }
+ else if (type == REG_DWORD)
+ {
+ lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)&dwordValueData, &valueDataLen);
+ if (lRet != ERROR_SUCCESS)
+ {
+ error(hwnd, IDS_BAD_VALUE, valueName);
+ goto done;
+ }
+
+ if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_DWORD), hwnd, modify_dword_dlgproc) == IDOK)
+ {
+ lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)&dwordValueData, sizeof(DWORD));
+ if (lRet == ERROR_SUCCESS)
+ result = TRUE;
+ }
+ }
+ else
+ {
error(hwnd, IDS_UNSUPPORTED_TYPE, type);
}
done:
- if(stringValueData)
- HeapFree(GetProcessHeap(), 0, stringValueData);
+ if (stringValueData)
+ HeapFree(GetProcessHeap(), 0, stringValueData);
stringValueData = NULL;
return result;
reactos/subsys/system/regedit
diff -u -r1.4 -r1.5
--- En.rc 1 Jan 2004 22:29:12 -0000 1.4
+++ En.rc 5 Apr 2004 12:00:11 -0000 1.5
@@ -143,6 +143,23 @@
END
+IDD_EDIT_DWORD DIALOG 32, 24, 252, 104
+STYLE DS_SETFONT | DS_MODALFRAME | DS_NOIDLEMSG | DS_3DLOOK | DS_CONTEXTHELP |
+ WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+CAPTION "Edit DWORD"
+FONT 8, "MS Shell Dlg"
+BEGIN
+ LTEXT "Value &name:",IDC_STATIC,6,6,134,8
+ EDITTEXT IDC_VALUE_NAME,6,17,240,12,ES_AUTOHSCROLL | ES_READONLY
+ LTEXT "&Value data:",IDC_STATIC,6,35,161,8
+ EDITTEXT IDC_VALUE_DATA,6,46,116,12,ES_AUTOHSCROLL
+ GROUPBOX "Base",IDC_STATIC,130,35,116,39
+ AUTORADIOBUTTON "&Hexadecimal",IDC_FORMAT_HEX,141,46,60,10,WS_GROUP
+ AUTORADIOBUTTON "&Decimal",IDC_FORMAT_DEC,141,59,60,10
+ DEFPUSHBUTTON "OK",IDOK,142,82,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,196,82,50,14
+END
+
/*
* String Table
*/