Commit 16614538 authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard

Remove most string size limitations.

Better error handling. Less listview flicker. A bunch of style fixes and improvements.
parent bd13ab8d
...@@ -28,18 +28,14 @@ ...@@ -28,18 +28,14 @@
#include "main.h" #include "main.h"
extern HINSTANCE hInst;
static INT_PTR CALLBACK AboutDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) static INT_PTR CALLBACK AboutDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
HWND hLicenseEditWnd;
TCHAR strLicense[0x1000]; TCHAR strLicense[0x1000];
switch (message) { switch (message) {
case WM_INITDIALOG: case WM_INITDIALOG:
hLicenseEditWnd = GetDlgItem(hDlg, IDC_LICENSE_EDIT); LoadString(hInst, IDS_LICENSE, strLicense, COUNT_OF(strLicense));
LoadString(hInst, IDS_LICENSE, strLicense, 0x1000); SetDlgItemText(hDlg, IDC_LICENSE_EDIT, strLicense);
SetWindowText(hLicenseEditWnd, strLicense);
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) { if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) {
......
...@@ -20,38 +20,26 @@ ...@@ -20,38 +20,26 @@
#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
#include <windows.h> #include <windows.h>
#include <tchar.h>
#include <commctrl.h> #include <commctrl.h>
#include <tchar.h>
#include <stdio.h>
#include "main.h" #include "main.h"
ChildWnd* pChildWnd; ChildWnd* g_pChildWnd;
/******************************************************************************* /*******************************************************************************
* Local module support methods * Local module support methods
*/ */
/*FIXME: why do we need this, we should remove it, we have already FindRegRoot */ static LPCTSTR get_root_key_name(HKEY hRootKey)
static void MakeFullRegPath(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max)
{ {
TVITEM item; if (hRootKey == HKEY_CLASSES_ROOT) return _T("HKEY_CLASSES_ROOT");
item.mask = TVIF_PARAM; if (hRootKey == HKEY_CURRENT_USER) return _T("HKEY_CURRENT_USER");
item.hItem = hItem; if (hRootKey == HKEY_LOCAL_MACHINE) return _T("HKEY_LOCAL_MACHINE");
if (TreeView_GetItem(hwndTV, &item)) { if (hRootKey == HKEY_USERS) return _T("HKEY_USERS");
if (item.hItem != TreeView_GetRoot(hwndTV)) { if (hRootKey == HKEY_CURRENT_CONFIG) return _T("HKEY_CURRENT_CONFIG");
/* recurse */ return _T("UKNOWN HKEY, PLEASE REPORT");
MakeFullRegPath(hwndTV, TreeView_GetParent(hwndTV, hItem), keyPath, pPathLen, max);
keyPath[*pPathLen] = _T('\\');
++(*pPathLen);
}
item.mask = TVIF_TEXT;
item.hItem = hItem;
item.pszText = &keyPath[*pPathLen];
item.cchTextMax = max - *pPathLen;
if (TreeView_GetItem(hwndTV, &item)) {
*pPathLen += _tcslen(item.pszText);
}
}
} }
static void draw_splitbar(HWND hWnd, int x) static void draw_splitbar(HWND hWnd, int x)
...@@ -127,13 +115,15 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -127,13 +115,15 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
static int last_split; static int last_split;
/* ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA); */ ChildWnd* pChildWnd = g_pChildWnd;
switch (message) { switch (message) {
case WM_CREATE: case WM_CREATE:
pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams; g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
if (!pChildWnd) return 0; if (!pChildWnd) return 0;
_tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
pChildWnd->nSplitPos = 250; pChildWnd->nSplitPos = 250;
pChildWnd->hWnd = hWnd;
pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW); pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/); pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
break; break;
...@@ -157,6 +147,8 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa ...@@ -157,6 +147,8 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
} }
goto def; goto def;
case WM_DESTROY: case WM_DESTROY:
HeapFree(GetProcessHeap(), 0, pChildWnd);
pChildWnd = NULL;
PostQuitMessage(0); PostQuitMessage(0);
break; break;
case WM_LBUTTONDOWN: { case WM_LBUTTONDOWN: {
...@@ -234,17 +226,21 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa ...@@ -234,17 +226,21 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
case TVN_ITEMEXPANDING: case TVN_ITEMEXPANDING:
return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam); return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
case TVN_SELCHANGED: { case TVN_SELCHANGED: {
HKEY hKey; LPCTSTR keyPath, rootName;
TCHAR keyPath[1000]; LPTSTR fullPath;
int keyPathLen = 0; HKEY hRootKey;
keyPath[0] = _T('\0');
hKey = FindRegRoot(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR));
RefreshListView(pChildWnd->hListWnd, hKey, keyPath);
keyPathLen = 0; keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey);
keyPath[0] = _T('\0'); if (keyPath) {
MakeFullRegPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR)); RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath);
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)keyPath); rootName = get_root_key_name(hRootKey);
fullPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(rootName) + 1 + lstrlen(keyPath) + 1) * sizeof(TCHAR));
if (fullPath) {
_stprintf(fullPath, "%s\\%s", rootName, keyPath);
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
HeapFree(GetProcessHeap(), 0, fullPath);
}
}
} }
break; break;
default: default:
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "regproc.h" #include "regproc.h"
#include "resource.h" #include "resource.h"
static TCHAR* editValueName; static const TCHAR* editValueName;
static TCHAR* stringValueData; static TCHAR* stringValueData;
void error(HWND hwnd, INT resId, ...) void error(HWND hwnd, INT resId, ...)
...@@ -91,7 +91,7 @@ INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L ...@@ -91,7 +91,7 @@ INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
return FALSE; return FALSE;
} }
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName) BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
{ {
DWORD valueDataLen; DWORD valueDataLen;
DWORD type; DWORD type;
......
...@@ -38,8 +38,6 @@ ...@@ -38,8 +38,6 @@
static BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */ static BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */
static HWND hChildWnd;
/******************************************************************************* /*******************************************************************************
* Local module support methods * Local module support methods
*/ */
...@@ -60,7 +58,7 @@ static void resize_frame_rect(HWND hWnd, PRECT prect) ...@@ -60,7 +58,7 @@ static void resize_frame_rect(HWND hWnd, PRECT prect)
GetClientRect(hStatusBar, &rt); GetClientRect(hStatusBar, &rt);
prect->bottom -= rt.bottom; prect->bottom -= rt.bottom;
} }
MoveWindow(hChildWnd, prect->left, prect->top, prect->right, prect->bottom, TRUE); MoveWindow(g_pChildWnd->hWnd, prect->left, prect->top, prect->right, prect->bottom, TRUE);
} }
void resize_frame_client(HWND hWnd) void resize_frame_client(HWND hWnd)
...@@ -437,21 +435,20 @@ BOOL RefreshView(HWND hWnd) ...@@ -437,21 +435,20 @@ BOOL RefreshView(HWND hWnd)
*/ */
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
HKEY hKeyRoot, hKey; HKEY hKeyRoot = 0, hKey = 0;
TCHAR keyPath[1000] = { 0 }; LPCTSTR keyPath;
TCHAR valueName[255] = { 0 }; LPCTSTR valueName;
int keyPathLen = 0, item;
BOOL result = TRUE; BOOL result = TRUE;
LONG lRet; LONG lRet;
hKeyRoot = FindRegRoot(pChildWnd->hTreeWnd, 0, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR)); keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
valueName = GetValueName(g_pChildWnd->hListWnd);
if (keyPath) {
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey); lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey);
if (lRet != ERROR_SUCCESS) hKey = 0; 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)) { switch (LOWORD(wParam)) {
/* Parse the menu selections:*/
case ID_REGISTRY_IMPORTREGISTRYFILE: case ID_REGISTRY_IMPORTREGISTRYFILE:
ImportRegistryFile(hWnd); ImportRegistryFile(hWnd);
break; break;
...@@ -467,7 +464,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -467,7 +464,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break; break;
case ID_EDIT_MODIFY: case ID_EDIT_MODIFY:
if (ModifyValue(hWnd, hKey, valueName)) if (ModifyValue(hWnd, hKey, valueName))
RefreshListView(pChildWnd->hListWnd, hKeyRoot, keyPath); RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
break; break;
case ID_EDIT_COPYKEYNAME: case ID_EDIT_COPYKEYNAME:
CopyKeyName(hWnd, _T("")); CopyKeyName(hWnd, _T(""));
...@@ -486,22 +483,17 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -486,22 +483,17 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_VIEW_REFRESH: case ID_VIEW_REFRESH:
RefreshView(hWnd); RefreshView(hWnd);
break; break;
/* case ID_OPTIONS_TOOLBAR:*/ /*case ID_OPTIONS_TOOLBAR:*/
/* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/ /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
/* break;*/ /* break;*/
case ID_VIEW_STATUSBAR: case ID_VIEW_STATUSBAR:
toggle_child(hWnd, LOWORD(wParam), hStatusBar); toggle_child(hWnd, LOWORD(wParam), hStatusBar);
break; break;
case ID_HELP_HELPTOPICS: case ID_HELP_HELPTOPICS:
/* WinHelp(hWnd, _T("regedit"), HELP_CONTENTS, 0);*/
WinHelp(hWnd, _T("regedit"), HELP_FINDER, 0); WinHelp(hWnd, _T("regedit"), HELP_FINDER, 0);
break; break;
case ID_HELP_ABOUT: case ID_HELP_ABOUT:
#ifdef WINSHELLAPI
/* ShellAbout(hWnd, szTitle, _T(""), LoadIcon(hInst, (LPCTSTR)IDI_REGEDIT));*/
#else
ShowAboutBox(hWnd); ShowAboutBox(hWnd);
#endif
break; break;
default: default:
result = FALSE; result = FALSE;
...@@ -524,23 +516,15 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -524,23 +516,15 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
static ChildWnd* pChildWnd = NULL;
switch (message) { switch (message) {
case WM_CREATE: { case WM_CREATE:
pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd)); CreateWindowEx(0, szChildClass, _T("regedit child window"), WS_CHILD | WS_VISIBLE,
_tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
hChildWnd = CreateWindowEx(0, szChildClass, _T("regedit child window"),
/* WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE|WS_BORDER,*/
WS_CHILD|WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hWnd, (HMENU)0, hInst, pChildWnd); hWnd, (HMENU)0, hInst, 0);
}
break; break;
case WM_COMMAND: case WM_COMMAND:
if (!_CmdWndProc(hWnd, message, wParam, lParam)) { if (!_CmdWndProc(hWnd, message, wParam, lParam))
return DefWindowProc(hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam);
}
break; break;
case WM_SIZE: case WM_SIZE:
resize_frame_client(hWnd); resize_frame_client(hWnd);
...@@ -557,10 +541,6 @@ LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa ...@@ -557,10 +541,6 @@ LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam); OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
break; break;
case WM_DESTROY: case WM_DESTROY:
if (pChildWnd) {
HeapFree(GetProcessHeap(), 0, pChildWnd);
pChildWnd = NULL;
}
WinHelp(hWnd, _T("regedit"), HELP_QUIT, 0); WinHelp(hWnd, _T("regedit"), HELP_QUIT, 0);
PostQuitMessage(0); PostQuitMessage(0);
default: default:
......
...@@ -19,15 +19,13 @@ ...@@ -19,15 +19,13 @@
*/ */
#include <windows.h> #include <windows.h>
#include <windowsx.h>
#include <commctrl.h> #include <commctrl.h>
#include <stdlib.h> #include <stdlib.h>
#include <tchar.h> #include <tchar.h>
#include <process.h> #include <process.h>
#include <stdio.h> #include <stdio.h>
#include "commctrl.h"
#include <windowsx.h>
#include "main.h" #include "main.h"
typedef struct tagLINE_INFO typedef struct tagLINE_INFO
...@@ -45,11 +43,37 @@ typedef struct tagLINE_INFO ...@@ -45,11 +43,37 @@ typedef struct tagLINE_INFO
static WNDPROC g_orgListWndProc; static WNDPROC g_orgListWndProc;
static DWORD g_columnToSort = ~0UL; static DWORD g_columnToSort = ~0UL;
static BOOL g_invertSort = FALSE; static BOOL g_invertSort = FALSE;
static LPTSTR g_valueName;
#define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1) #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 }; static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
static int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT }; static int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
LPCTSTR GetValueName(HWND hwndLV)
{
int item, len, maxLen;
LPTSTR newStr;
if (!g_valueName) g_valueName = HeapAlloc(GetProcessHeap(), 0, 1024);
if (!g_valueName) return NULL;
*g_valueName = 0;
maxLen = HeapSize(GetProcessHeap(), 0, g_valueName);
if (maxLen == (SIZE_T) - 1) return NULL;
item = ListView_GetNextItem(hwndLV, -1, LVNI_FOCUSED);
if (item == -1) return NULL;
do {
ListView_GetItemText(hwndLV, item, 0, g_valueName, maxLen);
len = _tcslen(g_valueName);
if (len < maxLen - 1) break;
newStr = HeapReAlloc(GetProcessHeap(), 0, g_valueName, maxLen * 2);
if (!newStr) return NULL;
g_valueName = newStr;
maxLen *= 2;
} while (TRUE);
return g_valueName;
}
/******************************************************************************* /*******************************************************************************
* Local module support methods * Local module support methods
...@@ -118,7 +142,7 @@ static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValB ...@@ -118,7 +142,7 @@ static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValB
} }
} }
static void CreateListColumns(HWND hWndListView) static BOOL CreateListColumns(HWND hWndListView)
{ {
TCHAR szText[50]; TCHAR szText[50];
int index; int index;
...@@ -134,11 +158,9 @@ static void CreateListColumns(HWND hWndListView) ...@@ -134,11 +158,9 @@ static void CreateListColumns(HWND hWndListView)
lvC.cx = default_column_widths[index]; lvC.cx = default_column_widths[index];
lvC.fmt = column_alignment[index]; lvC.fmt = column_alignment[index];
LoadString(hInst, IDS_LIST_COLUMN_FIRST + index, szText, sizeof(szText)/sizeof(TCHAR)); LoadString(hInst, IDS_LIST_COLUMN_FIRST + index, szText, sizeof(szText)/sizeof(TCHAR));
if (ListView_InsertColumn(hWndListView, index, &lvC) == -1) { if (ListView_InsertColumn(hWndListView, index, &lvC) == -1) return FALSE;
/* TODO: handle failure condition... */
break;
}
} }
return TRUE;
} }
/* OnGetDispInfo - processes the LVN_GETDISPINFO notification message. */ /* OnGetDispInfo - processes the LVN_GETDISPINFO notification message. */
...@@ -168,9 +190,6 @@ static void OnGetDispInfo(NMLVDISPINFO* plvdi) ...@@ -168,9 +190,6 @@ static void OnGetDispInfo(NMLVDISPINFO* plvdi)
case REG_DWORD: case REG_DWORD:
plvdi->item.pszText = _T("REG_DWORD"); plvdi->item.pszText = _T("REG_DWORD");
break; break;
/* case REG_DWORD_LITTLE_ENDIAN: */
/* plvdi->item.pszText = _T("REG_DWORD_LITTLE_ENDIAN"); */
/* break; */
case REG_DWORD_BIG_ENDIAN: case REG_DWORD_BIG_ENDIAN:
plvdi->item.pszText = _T("REG_DWORD_BIG_ENDIAN"); plvdi->item.pszText = _T("REG_DWORD_BIG_ENDIAN");
break; break;
...@@ -212,8 +231,7 @@ static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSor ...@@ -212,8 +231,7 @@ static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSor
if (g_columnToSort == 1 && l->dwValType != r->dwValType) if (g_columnToSort == 1 && l->dwValType != r->dwValType)
return g_invertSort ? (int)r->dwValType - (int)l->dwValType : (int)l->dwValType - (int)r->dwValType; return g_invertSort ? (int)r->dwValType - (int)l->dwValType : (int)l->dwValType - (int)r->dwValType;
if (g_columnToSort == 2) if (g_columnToSort == 2) {
{
/* FIXME: Sort on value */ /* FIXME: Sort on value */
} }
return g_invertSort ? _tcscmp(r->name, l->name) : _tcscmp(l->name, r->name); return g_invertSort ? _tcscmp(r->name, l->name) : _tcscmp(l->name, r->name);
...@@ -249,8 +267,7 @@ static LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPAR ...@@ -249,8 +267,7 @@ static LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPAR
case LVN_COLUMNCLICK: case LVN_COLUMNCLICK:
if (g_columnToSort == ((LPNMLISTVIEW)lParam)->iSubItem) if (g_columnToSort == ((LPNMLISTVIEW)lParam)->iSubItem)
g_invertSort = !g_invertSort; g_invertSort = !g_invertSort;
else else {
{
g_columnToSort = ((LPNMLISTVIEW)lParam)->iSubItem; g_columnToSort = ((LPNMLISTVIEW)lParam)->iSubItem;
g_invertSort = FALSE; g_invertSort = FALSE;
} }
...@@ -332,29 +349,38 @@ HWND CreateListView(HWND hwndParent, int id) ...@@ -332,29 +349,38 @@ HWND CreateListView(HWND hwndParent, int id)
WS_VISIBLE | WS_CHILD | LVS_REPORT, WS_VISIBLE | WS_CHILD | LVS_REPORT,
0, 0, rcClient.right, rcClient.bottom, 0, 0, rcClient.right, rcClient.bottom,
hwndParent, (HMENU)id, hInst, NULL); hwndParent, (HMENU)id, hInst, NULL);
if (!hwndLV) return NULL;
ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT); ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
/* Initialize the image list, and add items to the control. */ /* Initialize the image list, and add items to the control. */
/* /*
if (!InitListViewImageLists(hwndLV) || if (!InitListViewImageLists(hwndLV)) goto fail;
!InitListViewItems(hwndLV, szName)) { if (!InitListViewItems(hwndLV, szName)) goto fail;
DestroyWindow(hwndLV);
return FALSE;
}
*/ */
CreateListColumns(hwndLV); if (!CreateListColumns(hwndLV)) goto fail;
g_orgListWndProc = SubclassWindow(hwndLV, ListWndProc); g_orgListWndProc = SubclassWindow(hwndLV, ListWndProc);
return hwndLV; return hwndLV;
fail:
DestroyWindow(hwndLV);
return NULL;
} }
BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPTSTR keyPath) BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath)
{ {
if (hwndLV != NULL) { DWORD max_sub_key_len;
DWORD max_val_name_len;
DWORD max_val_size;
DWORD val_count;
HKEY hNewKey;
LONG errCode;
INT count, i; INT count, i;
count = ListView_GetItemCount(hwndLV);
for (i = 0; i < count; i++)
{
LVITEM item; LVITEM item;
if (!hwndLV) return FALSE;
SendMessage(hwndLV, WM_SETREDRAW, FALSE, 0);
count = ListView_GetItemCount(hwndLV);
for (i = 0; i < count; i++) {
item.mask = LVIF_PARAM; item.mask = LVIF_PARAM;
item.iItem = i; item.iItem = i;
ListView_GetItem(hwndLV, &item); ListView_GetItem(hwndLV, &item);
...@@ -363,22 +389,15 @@ BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPTSTR keyPath) ...@@ -363,22 +389,15 @@ BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPTSTR keyPath)
} }
g_columnToSort = ~0UL; g_columnToSort = ~0UL;
ListView_DeleteAllItems(hwndLV); ListView_DeleteAllItems(hwndLV);
}
if (hKey != NULL) { errCode = RegOpenKeyEx(hKey, keyPath, 0, KEY_READ, &hNewKey);
HKEY hNewKey; if (errCode != ERROR_SUCCESS) return FALSE;
LONG errCode = RegOpenKeyEx(hKey, keyPath, 0, KEY_READ, &hNewKey);
if (errCode == ERROR_SUCCESS) {
DWORD max_sub_key_len;
DWORD max_val_name_len;
DWORD max_val_size;
DWORD val_count;
ShowWindow(hwndLV, SW_HIDE);
/* get size information and resize the buffers if necessary */ /* get size information and resize the buffers if necessary */
errCode = RegQueryInfoKey(hNewKey, NULL, NULL, NULL, NULL, errCode = RegQueryInfoKey(hNewKey, NULL, NULL, NULL, NULL, &max_sub_key_len, NULL,
&max_sub_key_len, NULL, &val_count, &max_val_name_len, &max_val_size, NULL, NULL); &val_count, &max_val_name_len, &max_val_size, NULL, NULL);
#define BUF_HEAD_SPACE 2 /* TODO: check why this is required with ROS ??? */ #define BUF_HEAD_SPACE 2 /* FIXME: check why this is required with ROS ??? */
if (errCode == ERROR_SUCCESS) { if (errCode == ERROR_SUCCESS) {
TCHAR* ValName = HeapAlloc(GetProcessHeap(), 0, ++max_val_name_len * sizeof(TCHAR) + BUF_HEAD_SPACE); TCHAR* ValName = HeapAlloc(GetProcessHeap(), 0, ++max_val_name_len * sizeof(TCHAR) + BUF_HEAD_SPACE);
...@@ -403,9 +422,8 @@ BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPTSTR keyPath) ...@@ -403,9 +422,8 @@ BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPTSTR keyPath)
HeapFree(GetProcessHeap(), 0, ValName); HeapFree(GetProcessHeap(), 0, ValName);
} }
ListView_SortItems(hwndLV, CompareFunc, hwndLV); ListView_SortItems(hwndLV, CompareFunc, hwndLV);
ShowWindow(hwndLV, SW_SHOW);
RegCloseKey(hNewKey); RegCloseKey(hNewKey);
} SendMessage(hwndLV, WM_SETREDRAW, TRUE, 0);
}
return TRUE; return TRUE;
} }
...@@ -46,6 +46,7 @@ UINT nClipboardFormat; ...@@ -46,6 +46,7 @@ UINT nClipboardFormat;
LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT"); LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT");
#define MAX_LOADSTRING 100
TCHAR szTitle[MAX_LOADSTRING]; TCHAR szTitle[MAX_LOADSTRING];
TCHAR szFrameClass[MAX_LOADSTRING]; TCHAR szFrameClass[MAX_LOADSTRING];
TCHAR szChildClass[MAX_LOADSTRING]; TCHAR szChildClass[MAX_LOADSTRING];
......
...@@ -28,12 +28,12 @@ ...@@ -28,12 +28,12 @@
#define TREE_WINDOW 2002 #define TREE_WINDOW 2002
#define LIST_WINDOW 2003 #define LIST_WINDOW 2003
#define MAX_LOADSTRING 100
#define SPLIT_WIDTH 5 #define SPLIT_WIDTH 5
#define MAX_NAME_LEN 500
#define COUNT_OF(a) (sizeof(a)/sizeof(a[0])) #define COUNT_OF(a) (sizeof(a)/sizeof(a[0]))
extern HINSTANCE hInst;
/******************************************************************************/ /******************************************************************************/
enum OPTION_FLAGS { enum OPTION_FLAGS {
...@@ -55,7 +55,7 @@ typedef struct { ...@@ -55,7 +55,7 @@ typedef struct {
WINDOWPLACEMENT pos; WINDOWPLACEMENT pos;
TCHAR szPath[MAX_PATH]; TCHAR szPath[MAX_PATH];
} ChildWnd; } ChildWnd;
extern ChildWnd* pChildWnd; extern ChildWnd* g_pChildWnd;
/******************************************************************************* /*******************************************************************************
* Global Variables: * Global Variables:
...@@ -84,14 +84,15 @@ extern void UpdateStatusBar(void); ...@@ -84,14 +84,15 @@ extern void UpdateStatusBar(void);
/* listview.c */ /* listview.c */
extern HWND CreateListView(HWND hwndParent, int id); extern HWND CreateListView(HWND hwndParent, int id);
extern BOOL RefreshListView(HWND hwndTV, HKEY hKey, LPTSTR keyPath); extern BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath);
extern LPCTSTR GetValueName(HWND hwndLV);
/* treeview.c */ /* treeview.c */
extern HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id); extern HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id);
extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv); extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv);
extern HKEY FindRegRoot(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max); extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
/* edit.c */ /* edit.c */
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName); BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
#endif /* __MAIN_H__ */ #endif /* __MAIN_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment