reactos/subsys/system/regedit
diff -u -r1.9 -r1.10
--- edit.c 20 Jun 2004 12:21:47 -0000 1.9
+++ edit.c 20 Jun 2004 13:35:03 -0000 1.10
@@ -33,6 +33,7 @@
#include "main.h"
#include "regproc.h"
#include "resource.h"
+#include "hexedit.h"
typedef enum _EDIT_MODE
@@ -44,7 +45,9 @@
static const TCHAR* editValueName;
static TCHAR* stringValueData;
+static PVOID binValueData;
static DWORD dwordValueData;
+static DWORD valueDataLen;
static EDIT_MODE dwordEditMode = EDIT_MODE_HEX;
@@ -260,68 +263,6 @@
return CallWindowProc(oldwndproc, hwnd, uMsg, wParam, lParam);
}
-INT_PTR CALLBACK modify_binary_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- TCHAR* valueData;
- HWND hwndValue;
- int len;
-
- switch(uMsg) {
- case WM_INITDIALOG:
- if(editValueName && _tcscmp(editValueName, _T("")))
- {
- SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
- }
- else
- {
- SetDlgItemText(hwndDlg, IDC_VALUE_NAME, _T("(Default)"));
- }
- SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData);
- SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA));
- return FALSE;
- case WM_COMMAND:
- 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;
- }
- }
- else
- {
- if ((valueData = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(TCHAR))))
- {
- stringValueData = valueData;
- if (!GetWindowText(hwndValue, stringValueData, len + 1))
- *stringValueData = 0;
- }
- }
- }
- else
- {
- if (stringValueData)
- *stringValueData = 0;
- }
- }
- EndDialog(hwndDlg, IDOK);
- break;
- case IDCANCEL:
- EndDialog(hwndDlg, IDCANCEL);
- return TRUE;
- }
- }
- return FALSE;
-}
-
INT_PTR CALLBACK modify_dword_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
@@ -448,9 +389,56 @@
return FALSE;
}
+
+INT_PTR CALLBACK modify_binary_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ PVOID valueData;
+ HWND hwndValue;
+ int len;
+
+ switch(uMsg) {
+ case WM_INITDIALOG:
+ if(editValueName && _tcscmp(editValueName, _T("")))
+ {
+ SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
+ }
+ else
+ {
+ SetDlgItemText(hwndDlg, IDC_VALUE_NAME, _T("(Default)"));
+ }
+ HexEdit_LoadBuffer(GetDlgItem(hwndDlg, IDC_VALUE_DATA), binValueData, valueDataLen);
+ SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA));
+ return FALSE;
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case IDOK:
+ if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA)))
+ {
+ len = HexEdit_GetBufferSize(hwndValue);
+ if (len != valueDataLen && len > 0)
+ {
+ binValueData = HeapReAlloc(GetProcessHeap(), 0, binValueData, len);
+ }
+ if (len > 0)
+ {
+ HexEdit_CopyBuffer(hwndValue, binValueData, len);
+ }
+ valueDataLen = len;
+ }
+ EndDialog(hwndDlg, IDOK);
+ break;
+ case IDCANCEL:
+ EndDialog(hwndDlg, IDCANCEL);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
{
- DWORD valueDataLen;
DWORD type;
LONG lRet;
BOOL result = FALSE;
@@ -467,6 +455,7 @@
type = REG_SZ;
valueDataLen = 0;
stringValueData = NULL;
+ binValueData = NULL;
}
if (lRet != ERROR_SUCCESS)
@@ -633,19 +622,28 @@
}
else if (type == REG_NONE || type == REG_BINARY)
{
- lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)&dwordValueData, &valueDataLen);
+ if(!(binValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen)))
+ {
+ error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
+ goto done;
+ }
+
+ lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)binValueData, &valueDataLen);
if (lRet != ERROR_SUCCESS)
{
- error(hwnd, IDS_BAD_VALUE, valueName);
+ HeapFree(GetProcessHeap(), 0, binValueData);
+ error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_BIN_DATA), hwnd, modify_binary_dlgproc) == IDOK)
{
- lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)&dwordValueData, sizeof(DWORD));
+ lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)binValueData, valueDataLen);
if (lRet == ERROR_SUCCESS)
result = TRUE;
}
+ if(binValueData != NULL)
+ HeapFree(GetProcessHeap(), 0, binValueData);
}
else
{
reactos/subsys/system/regedit
diff -u -r1.1 -r1.2
--- hexedit.c 20 Jun 2004 12:21:47 -0000 1.1
+++ hexedit.c 20 Jun 2004 13:35:03 -0000 1.2
@@ -29,8 +29,9 @@
{
HWND hWndSelf;
HWND hWndParent;
- HLOCAL hData;
+ HLOCAL hBuffer;
DWORD style;
+ DWORD MaxBuffer;
INT LineHeight;
INT CharWidth;
HFONT hFont;
@@ -77,6 +78,106 @@
SetCaretPos(hed->LeftMargin + (Col * hed->CharWidth), hed->TopMargin + (Line * hed->LineHeight));
}
+/*** Control specific messages ************************************************/
+
+static LRESULT
+HEXEDIT_HEM_LOADBUFFER(PHEXEDIT_DATA hed, PVOID Buffer, DWORD Size)
+{
+ if(Buffer != NULL && Size > 0)
+ {
+ LPVOID buf;
+
+ if(hed->MaxBuffer > 0 && Size > hed->MaxBuffer)
+ {
+ Size = hed->MaxBuffer;
+ }
+
+ if(hed->hBuffer)
+ {
+ if(Size > 0)
+ {
+ if(LocalSize(hed->hBuffer) != Size)
+ {
+ hed->hBuffer = LocalReAlloc(hed->hBuffer, Size, LMEM_MOVEABLE | LMEM_ZEROINIT);
+ }
+ }
+ else
+ {
+ hed->hBuffer = LocalFree(hed->hBuffer);
+
+ return 0;
+ }
+ }
+ else if(Size > 0)
+ {
+ hed->hBuffer = LocalAlloc(LHND, Size);
+ }
+
+ if(Size > 0)
+ {
+ buf = LocalLock(hed->hBuffer);
+ if(buf)
+ {
+ memcpy(buf, Buffer, Size);
+ }
+ else
+ Size = 0;
+ LocalUnlock(hed->hBuffer);
+ }
+
+ return Size;
+ }
+ else if(hed->hBuffer)
+ {
+ hed->hBuffer = LocalFree(hed->hBuffer);
+ }
+
+ return 0;
+}
+
+static LRESULT
+HEXEDIT_HEM_COPYBUFFER(PHEXEDIT_DATA hed, PVOID Buffer, DWORD Size)
+{
+ DWORD nCpy;
+
+ if(!hed->hBuffer)
+ {
+ return 0;
+ }
+
+ if(Buffer != NULL && Size > 0)
+ {
+ nCpy = min(Size, LocalSize(hed->hBuffer));
+ if(nCpy > 0)
+ {
+ PVOID buf;
+
+ buf = LocalLock(hed->hBuffer);
+ if(buf)
+ {
+ memcpy(Buffer, buf, nCpy);
+ }
+ else
+ nCpy = 0;
+ LocalUnlock(hed->hBuffer);
+ }
+ return nCpy;
+ }
+
+ return (LRESULT)LocalSize(hed->hBuffer);
+}
+
+static LRESULT
+HEXEDIT_HEM_SETMAXBUFFERSIZE(PHEXEDIT_DATA hed, DWORD nMaxSize)
+{
+ hed->MaxBuffer = nMaxSize;
+ if(hed->MaxBuffer > 0 && hed->hBuffer && LocalSize(hed->hBuffer) > hed->MaxBuffer)
+ {
+ /* truncate the buffer */
+ hed->hBuffer = LocalReAlloc(hed->hBuffer, hed->MaxBuffer, LMEM_MOVEABLE);
+ }
+}
+
/*** Message Proc *************************************************************/
static LRESULT
@@ -101,10 +202,10 @@
static LRESULT
HEXEDIT_WM_NCDESTROY(PHEXEDIT_DATA hed)
{
- if(hed->hData)
+ if(hed->hBuffer)
{
- while(LocalUnlock(hed->hData));
- LocalFree(hed->hData);
+ while(LocalUnlock(hed->hBuffer));
+ LocalFree(hed->hBuffer);
}
SetWindowLong(hed->hWndSelf, 0, 0);
@@ -176,6 +277,15 @@
hed = (PHEXEDIT_DATA)GetWindowLong(hWnd, 0);
switch(uMsg)
{
+ case HEM_LOADBUFFER:
+ return HEXEDIT_HEM_LOADBUFFER(hed, (PVOID)wParam, (DWORD)lParam);
+
+ case HEM_COPYBUFFER:
+ return HEXEDIT_HEM_COPYBUFFER(hed, (PVOID)wParam, (DWORD)lParam);
+
+ case HEM_SETMAXBUFFERSIZE:
+ return HEXEDIT_HEM_SETMAXBUFFERSIZE(hed, (DWORD)lParam);
+
case WM_SETFOCUS:
return HEXEDIT_WM_SETFOCUS(hed);
reactos/subsys/system/regedit
diff -u -r1.1 -r1.2
--- hexedit.h 20 Jun 2004 12:21:47 -0000 1.1
+++ hexedit.h 20 Jun 2004 13:35:03 -0000 1.2
@@ -11,6 +11,30 @@
/* styles */
#define HES_READONLY (0x800)
#define HES_LOWERCASE (0x10)
-#define HES_UPPERCASE (0x8)
+#define HES_UPPERCASE (0x8)
+#define HES_AUTOVSCROLL (0x40)
+#define HES_HIDEADDRESS (0x4)
+
+/* messages */
+#define HEM_BASE (WM_USER + 50)
+#define HEM_LOADBUFFER (HEM_BASE + 1)
+#define HEM_COPYBUFFER (HEM_BASE + 2)
+#define HEM_SETMAXBUFFERSIZE (HEM_BASE + 3)
+
+/* macros */
+#define HexEdit_LoadBuffer(hWnd, Buffer, Size) \
+ SendMessage((hWnd), HEM_LOADBUFFER, (WPARAM)(Buffer), (LPARAM)(Size))
+
+#define HexEdit_ClearBuffer(hWnd) \
+ SendMessage((hWnd), HEM_LOADBUFFER, 0, 0)
+
+#define HexEdit_CopyBuffer(hWnd, Buffer, nMax) \
+ SendMessage((hWnd), HEM_COPYBUFFER, (WPARAM)(Buffer), (LPARAM)(nMax))
+
+#define HexEdit_GetBufferSize(hWnd) \
+ SendMessage((hWnd), HEM_COPYBUFFER, 0, 0)
+
+#define HexEdit_SetMaxBufferSize(hWnd, Size) \
+ SendMessage((hWnd), HEM_SETMAXBUFFERSIZE, 0, (LPARAM)(Size))
#endif /* __HEXEDIT_H */