Skip to content
Snippets Groups Projects
Commit 9142f773 authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard
Browse files

Added support for editing strings.

parent 910896b7
No related branches found
No related tags found
No related merge requests found
......@@ -119,6 +119,20 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP
END
IDD_EDIT_STRING DIALOG DISCARDABLE 22, 17, 210, 75
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,119,8
EDITTEXT IDC_VALUE_DATA,5,40,200,12, WS_BORDER | WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,140,60,30,11,WS_GROUP
DEFPUSHBUTTON "Cancel",IDCANCEL,175,60,30,11,WS_GROUP
END
/*
* String Table
*/
......@@ -181,6 +195,14 @@ BEGIN
ID_EDIT_FINDNEXT "Finds next occurrence of text specified in previous search"
END
STRINGTABLE DISCARDABLE
BEGIN
IDS_ERROR "Error"
IDS_BAD_VALUE "Can't query value '%s'"
IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)"
IDS_TOO_BIG_VALUE "Value is too big (%ld)"
END
/*****************************************************************/
......
......@@ -11,6 +11,7 @@ EXTRADEFS = -DNO_LIBWINE_PORT
C_SRCS = \
about.c \
childwnd.c \
edit.c \
framewnd.c \
listview.c \
main.c \
......
......@@ -22,16 +22,16 @@
#include <windows.h>
#include <tchar.h>
#include <commctrl.h>
#include <assert.h>
#define ASSERT assert
#include "main.h"
ChildWnd* pChildWnd;
/*******************************************************************************
* Local module support methods
*/
/*FIXME: why do we need this, we should remove it, we have already FindRegRoot */
static void MakeFullRegPath(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max)
{
TVITEM item;
......@@ -128,12 +128,11 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
{
static int last_split;
/* ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA); */
static ChildWnd* pChildWnd;
switch (message) {
case WM_CREATE:
pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
ASSERT(pChildWnd);
if (!pChildWnd) return 0;
pChildWnd->nSplitPos = 250;
pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
......
/*
* Registry editing UI functions.
*
* Copyright (C) 2003 Dimitrie O. Paun
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
#include <windows.h>
#include <tchar.h>
#include <commctrl.h>
#include <commdlg.h>
#include <cderr.h>
#include <stdlib.h>
#include <stdio.h>
#include <shellapi.h>
#include "main.h"
#include "regproc.h"
#include "resource.h"
static TCHAR* editValueName;
static TCHAR* stringValueData;
void error(HWND hwnd, INT resId, ...)
{
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);
_vsntprintf(errstr, COUNT_OF(errstr), errfmt, 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)
{
TCHAR* valueData;
HWND hwndValue;
int len;
switch(uMsg) {
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
if ((len = GetWindowTextLength(hwndValue))) {
if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) {
stringValueData = valueData;
if (!GetWindowText(hwndValue, stringValueData, len + 1))
*stringValueData = 0;
}
}
}
/* Fall through */
case IDCANCEL:
EndDialog(hwndDlg, wParam);
return TRUE;
}
}
return FALSE;
}
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName)
{
DWORD valueDataLen;
DWORD type;
LONG lRet;
BOOL result = FALSE;
if (!hKey || !valueName) return FALSE;
editValueName = valueName;
lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &valueDataLen);
if (lRet != ERROR_SUCCESS) {
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
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 (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) {
lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1);
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 {
error(hwnd, IDS_UNSUPPORTED_TYPE, type);
}
done:
HeapFree(GetProcessHeap(), 0, stringValueData);
stringValueData = NULL;
return result;
}
......@@ -436,6 +436,19 @@ BOOL RefreshView(HWND hWnd)
*/
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HKEY hKeyRoot, hKey;
TCHAR keyPath[1000] = { 0 };
TCHAR valueName[255] = { 0 };
int keyPathLen = 0, item;
BOOL result = TRUE;
LONG lRet;
hKeyRoot = FindRegRoot(pChildWnd->hTreeWnd, 0, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR));
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey);
if (lRet != ERROR_SUCCESS) hKey = 0;
item = ListView_GetNextItem(pChildWnd->hListWnd, -1, LVNI_FOCUSED);
if (item != -1) ListView_GetItemText(pChildWnd->hListWnd, item, 0, valueName, sizeof(valueName)/sizeof(TCHAR));
switch (LOWORD(wParam)) {
/* Parse the menu selections:*/
case ID_REGISTRY_IMPORTREGISTRYFILE:
......@@ -451,6 +464,10 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_REGISTRY_PRINT:
PrintRegistryHive(hWnd, _T(""));
break;
case ID_EDIT_MODIFY:
if (ModifyValue(hWnd, hKey, valueName))
RefreshListView(pChildWnd->hListWnd, hKeyRoot, keyPath);
break;
case ID_EDIT_COPYKEYNAME:
CopyKeyName(hWnd, _T(""));
break;
......@@ -486,9 +503,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
#endif
break;
default:
return FALSE;
}
return TRUE;
result = FALSE;
}
RegCloseKey(hKey);
return result;
}
/********************************************************************************
......
......@@ -100,6 +100,8 @@ static BOOL DynamicBind( void )
d(GetMessageA)
d(GetSubMenu)
d(GetSystemMetrics)
d(GetWindowTextA)
d(GetWindowTextLengthA)
d(InvertRect)
d(IsWindowVisible)
d(LoadAcceleratorsA)
......@@ -110,6 +112,7 @@ static BOOL DynamicBind( void )
d(LoadMenuA)
d(LoadStringA)
d(MessageBeep)
d(MessageBoxA)
d(MoveWindow)
d(OpenClipboard)
d(PostQuitMessage)
......@@ -121,6 +124,7 @@ static BOOL DynamicBind( void )
d(SendMessageA)
d(SetCapture)
d(SetCursor)
d(SetDlgItemTextA)
d(SetFocus)
d(SetWindowLongA)
d(SetWindowTextA)
......
......@@ -37,6 +37,7 @@ extern "C" {
#define SPLIT_WIDTH 5
#define MAX_NAME_LEN 500
#define COUNT_OF(a) (sizeof(a)/sizeof(a[0]))
/******************************************************************************/
......@@ -59,6 +60,7 @@ typedef struct {
WINDOWPLACEMENT pos;
TCHAR szPath[MAX_PATH];
} ChildWnd;
extern ChildWnd* pChildWnd;
/*******************************************************************************
* Global Variables:
......@@ -126,6 +128,8 @@ d(GetSaveFileNameA)
d(GetStockObject)
d(GetSubMenu)
d(GetSystemMetrics)
d(GetWindowTextA)
d(GetWindowTextLengthA)
d(ImageList_Add)
d(ImageList_Create)
d(ImageList_GetImageCount)
......@@ -140,6 +144,7 @@ d(LoadImageA)
d(LoadMenuA)
d(LoadStringA)
d(MessageBeep)
d(MessageBoxA)
d(MoveWindow)
d(OpenClipboard)
d(PostQuitMessage)
......@@ -152,6 +157,7 @@ d(ScreenToClient)
d(SendMessageA)
d(SetCapture)
d(SetCursor)
d(SetDlgItemTextA)
d(SetFocus)
d(SetWindowLongA)
d(SetWindowTextA)
......@@ -197,6 +203,8 @@ d(wsprintfA)
#define GetStockObject pGetStockObject
#define GetSubMenu pGetSubMenu
#define GetSystemMetrics pGetSystemMetrics
#define GetWindowTextA pGetWindowTextA
#define GetWindowTextLengthA pGetWindowTextLengthA
#define ImageList_Add pImageList_Add
#define ImageList_Create pImageList_Create
#define ImageList_GetImageCount pImageList_GetImageCount
......@@ -211,6 +219,7 @@ d(wsprintfA)
#define LoadMenuA pLoadMenuA
#define LoadStringA pLoadStringA
#define MessageBeep pMessageBeep
#define MessageBoxA pMessageBoxA
#define MoveWindow pMoveWindow
#define OpenClipboard pOpenClipboard
#define PostQuitMessage pPostQuitMessage
......@@ -223,6 +232,7 @@ d(wsprintfA)
#define SendMessageA pSendMessageA
#define SetCapture pSetCapture
#define SetCursor pSetCursor
#define SetDlgItemTextA pSetDlgItemTextA
#define SetFocus pSetFocus
#define SetWindowLongA pSetWindowLongA
#define SetWindowTextA pSetWindowTextA
......@@ -257,4 +267,7 @@ extern HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id);
extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv);
extern HKEY FindRegRoot(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max);
/* edit.c */
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName);
#endif /* __MAIN_H__ */
......@@ -102,4 +102,13 @@
#define ID_REGISTRY_PRINTERSETUP 32833
#define ID_REGISTRY_SAVESUBTREEAS 32834
#define IDS_LICENSE 32835
#define IDS_ERROR 32836
#define IDS_BAD_VALUE 32837
#define IDS_UNSUPPORTED_TYPE 32838
#define IDS_TOO_BIG_VALUE 32839
#define IDD_EDIT_STRING 2000
#define IDC_VALUE_NAME 2001
#define IDC_VALUE_DATA 2002
#define IDC_STATIC -1
......@@ -48,6 +48,9 @@ HKEY FindRegRoot(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, in
{
HKEY hKey = NULL;
TVITEM item;
if (!hItem) hItem = TreeView_GetSelection(hwndTV);
item.mask = TVIF_PARAM;
item.hItem = TreeView_GetParent(hwndTV, hItem);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment