2003-08-07 03:10:13 +00:00
|
|
|
/*
|
|
|
|
* Regedit listviews
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
2008-08-31 14:49:43 +00:00
|
|
|
* Copyright (C) 2008 Alexander N. Sørnes <alex@thehandofagony.com>
|
2003-08-07 03:10:13 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-07 03:10:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
2016-03-29 10:56:20 +00:00
|
|
|
#include <winternl.h>
|
2003-08-07 03:10:13 +00:00
|
|
|
#include <commctrl.h>
|
|
|
|
|
|
|
|
#include "main.h"
|
2017-07-12 11:09:49 +00:00
|
|
|
|
2005-03-21 10:29:32 +00:00
|
|
|
static INT Image_String;
|
|
|
|
static INT Image_Binary;
|
|
|
|
|
2003-08-07 03:10:13 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Global and Local Variables:
|
|
|
|
*/
|
|
|
|
|
2017-07-12 11:09:49 +00:00
|
|
|
DWORD g_columnToSort = ~0U;
|
|
|
|
BOOL g_invertSort = FALSE;
|
|
|
|
WCHAR *g_currentPath;
|
|
|
|
HKEY g_currentRootKey;
|
|
|
|
static WCHAR g_szValueNotSet[64];
|
2003-08-07 03:10:13 +00:00
|
|
|
|
|
|
|
#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 column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
|
|
|
|
|
2008-08-31 14:58:27 +00:00
|
|
|
LPWSTR GetItemText(HWND hwndLV, UINT item)
|
2008-08-27 18:40:31 +00:00
|
|
|
{
|
2017-07-28 13:22:10 +00:00
|
|
|
WCHAR *curStr;
|
2008-08-27 18:40:31 +00:00
|
|
|
unsigned int maxLen = 128;
|
2012-04-27 02:51:08 +00:00
|
|
|
if (item == 0) return NULL; /* first item is ALWAYS a default */
|
2008-08-27 18:40:31 +00:00
|
|
|
|
2022-07-07 11:55:37 +00:00
|
|
|
curStr = malloc(maxLen * sizeof(WCHAR));
|
2008-08-27 18:40:31 +00:00
|
|
|
do {
|
2012-04-27 02:51:08 +00:00
|
|
|
ListView_GetItemTextW(hwndLV, item, 0, curStr, maxLen);
|
2008-08-27 18:40:31 +00:00
|
|
|
if (lstrlenW(curStr) < maxLen - 1) return curStr;
|
2012-04-27 02:51:08 +00:00
|
|
|
maxLen *= 2;
|
2022-07-07 11:55:37 +00:00
|
|
|
curStr = realloc(curStr, maxLen * sizeof(WCHAR));
|
2008-08-27 18:40:31 +00:00
|
|
|
} while (TRUE);
|
2022-07-07 11:55:37 +00:00
|
|
|
free(curStr);
|
2008-08-27 18:40:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-16 12:20:46 +00:00
|
|
|
WCHAR *GetValueName(HWND hwndLV)
|
2003-12-12 04:08:59 +00:00
|
|
|
{
|
2004-01-16 23:02:44 +00:00
|
|
|
INT item;
|
2003-12-12 04:08:59 +00:00
|
|
|
|
2011-04-16 08:07:27 +00:00
|
|
|
item = SendMessageW(hwndLV, LVM_GETNEXTITEM, -1, MAKELPARAM(LVNI_FOCUSED, 0));
|
2003-12-12 04:08:59 +00:00
|
|
|
if (item == -1) return NULL;
|
2004-01-16 23:02:44 +00:00
|
|
|
|
2019-10-31 10:22:07 +00:00
|
|
|
return GetItemText(hwndLV, item);
|
2003-12-12 04:08:59 +00:00
|
|
|
}
|
2003-08-07 03:10:13 +00:00
|
|
|
|
2017-07-12 11:08:54 +00:00
|
|
|
BOOL update_listview_path(const WCHAR *path)
|
|
|
|
{
|
2022-07-07 11:55:37 +00:00
|
|
|
free(g_currentPath);
|
2017-07-12 11:08:54 +00:00
|
|
|
|
2023-09-24 18:24:10 +00:00
|
|
|
g_currentPath = wcsdup(path);
|
2017-07-12 11:08:54 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-03-21 10:29:32 +00:00
|
|
|
/* convert '\0' separated string list into ',' separated string list */
|
2008-08-26 18:57:23 +00:00
|
|
|
static void MakeMULTISZDisplayable(LPWSTR multi)
|
2005-03-21 10:29:32 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
for (; *multi; multi++)
|
|
|
|
;
|
|
|
|
if (*(multi+1))
|
|
|
|
{
|
|
|
|
*multi = ',';
|
|
|
|
multi++;
|
|
|
|
}
|
|
|
|
} while (*multi);
|
|
|
|
}
|
|
|
|
|
2003-08-07 03:10:13 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Local module support methods
|
|
|
|
*/
|
2017-05-29 08:20:44 +00:00
|
|
|
void format_value_data(HWND hwndLV, int index, DWORD type, void *data, DWORD size)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, data ? data : g_szValueNotSet);
|
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
|
|
|
case REG_DWORD_BIG_ENDIAN:
|
|
|
|
{
|
|
|
|
DWORD value = *(DWORD *)data;
|
|
|
|
WCHAR buf[64];
|
|
|
|
if (type == REG_DWORD_BIG_ENDIAN)
|
|
|
|
value = RtlUlongByteSwap(value);
|
2022-04-14 13:01:36 +00:00
|
|
|
wsprintfW(buf, L"0x%08x (%u)", value, value);
|
2017-05-29 08:20:44 +00:00
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, buf);
|
|
|
|
break;
|
|
|
|
}
|
2022-06-23 15:51:22 +00:00
|
|
|
case REG_QWORD:
|
|
|
|
{
|
|
|
|
UINT64 value = *(UINT64 *)data;
|
|
|
|
WCHAR buf[64];
|
2022-06-29 11:32:26 +00:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), L"0x%08I64x (%I64u)", value, value);
|
2022-06-23 15:51:22 +00:00
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, buf);
|
|
|
|
break;
|
|
|
|
}
|
2017-06-21 12:19:27 +00:00
|
|
|
case REG_MULTI_SZ:
|
|
|
|
MakeMULTISZDisplayable(data);
|
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, data);
|
|
|
|
break;
|
2017-05-29 08:20:44 +00:00
|
|
|
case REG_BINARY:
|
|
|
|
case REG_NONE:
|
2017-06-21 12:19:27 +00:00
|
|
|
default:
|
2017-05-29 08:20:44 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
BYTE *pData = data;
|
2022-07-07 11:55:37 +00:00
|
|
|
WCHAR *strBinary = malloc(size * sizeof(WCHAR) * 3 + sizeof(WCHAR));
|
2017-05-29 08:20:44 +00:00
|
|
|
for (i = 0; i < size; i++)
|
2022-04-14 13:01:36 +00:00
|
|
|
wsprintfW( strBinary + i*3, L"%02X ", pData[i] );
|
2017-05-29 08:20:44 +00:00
|
|
|
strBinary[size * 3] = 0;
|
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, strBinary);
|
2022-07-07 11:55:37 +00:00
|
|
|
free(strBinary);
|
2017-05-29 08:20:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 13:06:59 +00:00
|
|
|
int AddEntryToList(HWND hwndLV, WCHAR *Name, DWORD dwValType, void *ValBuf, DWORD dwCount, int pos)
|
2003-08-07 03:10:13 +00:00
|
|
|
{
|
2017-07-28 13:22:27 +00:00
|
|
|
LINE_INFO *linfo;
|
2017-06-28 12:49:55 +00:00
|
|
|
LVITEMW item = { 0 };
|
2003-08-07 03:10:13 +00:00
|
|
|
int index;
|
|
|
|
|
2022-07-07 11:55:37 +00:00
|
|
|
linfo = malloc(sizeof(LINE_INFO));
|
2003-12-10 02:10:52 +00:00
|
|
|
linfo->dwValType = dwValType;
|
|
|
|
linfo->val_len = dwCount;
|
2023-09-24 18:24:10 +00:00
|
|
|
linfo->name = wcsdup(Name);
|
2017-07-28 13:22:27 +00:00
|
|
|
|
|
|
|
if (ValBuf && dwCount)
|
2008-08-26 18:57:23 +00:00
|
|
|
{
|
2022-07-07 11:55:37 +00:00
|
|
|
linfo->val = malloc(dwCount);
|
2017-07-30 10:45:53 +00:00
|
|
|
memcpy(linfo->val, ValBuf, dwCount);
|
2008-08-26 18:57:23 +00:00
|
|
|
}
|
2017-07-28 13:22:27 +00:00
|
|
|
else linfo->val = NULL;
|
2003-12-10 02:10:52 +00:00
|
|
|
|
2005-03-21 10:29:32 +00:00
|
|
|
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
|
2017-06-16 13:06:59 +00:00
|
|
|
item.iItem = (pos == -1) ? SendMessageW(hwndLV, LVM_GETITEMCOUNT, 0, 0) : pos;
|
2004-05-04 02:55:28 +00:00
|
|
|
item.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
|
2008-08-26 18:57:23 +00:00
|
|
|
item.pszText = Name ? Name : LPSTR_TEXTCALLBACKW;
|
|
|
|
item.cchTextMax = Name ? lstrlenW(item.pszText) : 0;
|
2017-05-22 13:02:52 +00:00
|
|
|
|
2005-03-21 10:29:32 +00:00
|
|
|
switch (dwValType)
|
|
|
|
{
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
case REG_MULTI_SZ:
|
|
|
|
item.iImage = Image_String;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
item.iImage = Image_Binary;
|
|
|
|
break;
|
|
|
|
}
|
2003-12-10 02:10:52 +00:00
|
|
|
item.lParam = (LPARAM)linfo;
|
|
|
|
|
2017-05-29 08:20:44 +00:00
|
|
|
if ((index = ListView_InsertItemW(hwndLV, &item)) != -1)
|
|
|
|
format_value_data(hwndLV, index, dwValType, ValBuf, dwCount);
|
2017-05-29 08:20:34 +00:00
|
|
|
return index;
|
2003-08-07 03:10:13 +00:00
|
|
|
}
|
|
|
|
|
2005-03-21 10:29:32 +00:00
|
|
|
static BOOL InitListViewImageList(HWND hWndListView)
|
|
|
|
{
|
|
|
|
HIMAGELIST himl;
|
|
|
|
HICON hicon;
|
|
|
|
INT cx = GetSystemMetrics(SM_CXSMICON);
|
|
|
|
INT cy = GetSystemMetrics(SM_CYSMICON);
|
|
|
|
|
|
|
|
himl = ImageList_Create(cx, cy, ILC_MASK, 0, 2);
|
|
|
|
if (!himl)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-08-31 12:53:30 +00:00
|
|
|
hicon = LoadImageW(hInst, MAKEINTRESOURCEW(IDI_STRING),
|
2005-03-21 10:29:32 +00:00
|
|
|
IMAGE_ICON, cx, cy, LR_DEFAULTCOLOR);
|
|
|
|
Image_String = ImageList_AddIcon(himl, hicon);
|
|
|
|
|
2008-08-31 12:53:30 +00:00
|
|
|
hicon = LoadImageW(hInst, MAKEINTRESOURCEW(IDI_BIN),
|
2005-03-21 10:29:32 +00:00
|
|
|
IMAGE_ICON, cx, cy, LR_DEFAULTCOLOR);
|
|
|
|
Image_Binary = ImageList_AddIcon(himl, hicon);
|
|
|
|
|
2008-08-31 12:53:30 +00:00
|
|
|
SendMessageW( hWndListView, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM) himl );
|
2005-03-21 10:29:32 +00:00
|
|
|
|
|
|
|
/* fail if some of the icons failed to load */
|
|
|
|
if (ImageList_GetImageCount(himl) < 2)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-12-12 04:08:59 +00:00
|
|
|
static BOOL CreateListColumns(HWND hWndListView)
|
2003-08-07 03:10:13 +00:00
|
|
|
{
|
2008-08-31 12:53:30 +00:00
|
|
|
WCHAR szText[50];
|
2003-08-07 03:10:13 +00:00
|
|
|
int index;
|
2008-08-31 12:53:30 +00:00
|
|
|
LVCOLUMNW lvC;
|
2003-08-07 03:10:13 +00:00
|
|
|
|
|
|
|
/* Create columns. */
|
|
|
|
lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
|
|
|
|
lvC.pszText = szText;
|
|
|
|
|
|
|
|
/* Load the column labels from the resource file. */
|
|
|
|
for (index = 0; index < MAX_LIST_COLUMNS; index++) {
|
|
|
|
lvC.iSubItem = index;
|
|
|
|
lvC.cx = default_column_widths[index];
|
|
|
|
lvC.fmt = column_alignment[index];
|
2018-05-21 13:34:56 +00:00
|
|
|
LoadStringW(hInst, IDS_LIST_COLUMN_FIRST + index, szText, ARRAY_SIZE(szText));
|
2008-08-31 12:53:30 +00:00
|
|
|
if (ListView_InsertColumnW(hWndListView, index, &lvC) == -1) return FALSE;
|
2003-08-07 03:10:13 +00:00
|
|
|
}
|
2003-12-12 04:08:59 +00:00
|
|
|
return TRUE;
|
2003-08-07 03:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* OnGetDispInfo - processes the LVN_GETDISPINFO notification message. */
|
2017-07-12 11:09:49 +00:00
|
|
|
void OnGetDispInfo(NMLVDISPINFOW *plvdi)
|
2003-08-07 03:10:13 +00:00
|
|
|
{
|
2008-08-31 14:49:43 +00:00
|
|
|
static WCHAR buffer[200];
|
2022-04-14 13:01:36 +00:00
|
|
|
static WCHAR reg_szT[] = L"REG_SZ",
|
|
|
|
reg_expand_szT[] = L"REG_EXPAND_SZ",
|
|
|
|
reg_binaryT[] = L"REG_BINARY",
|
|
|
|
reg_dwordT[] = L"REG_DWORD",
|
|
|
|
reg_dword_big_endianT[] = L"REG_DWORD_BIG_ENDIAN",
|
2022-06-23 15:51:22 +00:00
|
|
|
reg_qwordT[] = L"REG_QWORD",
|
2022-04-14 13:01:36 +00:00
|
|
|
reg_multi_szT[] = L"REG_MULTI_SZ",
|
|
|
|
reg_linkT[] = L"REG_LINK",
|
|
|
|
reg_resource_listT[] = L"REG_RESOURCE_LIST",
|
|
|
|
reg_noneT[] = L"REG_NONE",
|
|
|
|
emptyT[] = L"";
|
2003-08-07 03:10:13 +00:00
|
|
|
|
|
|
|
plvdi->item.pszText = NULL;
|
|
|
|
plvdi->item.cchTextMax = 0;
|
|
|
|
|
|
|
|
switch (plvdi->item.iSubItem) {
|
|
|
|
case 0:
|
2008-08-31 14:49:43 +00:00
|
|
|
plvdi->item.pszText = g_pszDefaultValueName;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2017-06-21 12:19:06 +00:00
|
|
|
{
|
|
|
|
DWORD data_type = ((LINE_INFO *)plvdi->item.lParam)->dwValType;
|
|
|
|
|
|
|
|
switch (data_type) {
|
2003-08-07 03:10:13 +00:00
|
|
|
case REG_SZ:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_szT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case REG_EXPAND_SZ:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_expand_szT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case REG_BINARY:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_binaryT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_dwordT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
2022-06-23 15:51:22 +00:00
|
|
|
case REG_QWORD:
|
|
|
|
plvdi->item.pszText = reg_qwordT;
|
|
|
|
break;
|
2003-08-07 03:10:13 +00:00
|
|
|
case REG_DWORD_BIG_ENDIAN:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_dword_big_endianT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case REG_MULTI_SZ:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_multi_szT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case REG_LINK:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_linkT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case REG_RESOURCE_LIST:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_resource_listT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case REG_NONE:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = reg_noneT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
2006-08-23 12:11:39 +00:00
|
|
|
{
|
2022-04-14 13:01:36 +00:00
|
|
|
wsprintfW(buffer, L"0x%x", data_type);
|
2003-08-07 03:10:13 +00:00
|
|
|
plvdi->item.pszText = buffer;
|
|
|
|
break;
|
2006-08-23 12:11:39 +00:00
|
|
|
}
|
2003-08-07 03:10:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-06-21 12:19:06 +00:00
|
|
|
}
|
2003-08-07 03:10:13 +00:00
|
|
|
case 2:
|
2006-08-23 12:11:39 +00:00
|
|
|
plvdi->item.pszText = g_szValueNotSet;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2006-06-29 22:18:08 +00:00
|
|
|
plvdi->item.pszText = emptyT;
|
2003-08-07 03:10:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 11:09:49 +00:00
|
|
|
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
|
2003-08-07 03:10:13 +00:00
|
|
|
{
|
2003-12-10 02:10:52 +00:00
|
|
|
LINE_INFO*l, *r;
|
|
|
|
l = (LINE_INFO*)lParam1;
|
|
|
|
r = (LINE_INFO*)lParam2;
|
2004-05-04 02:55:28 +00:00
|
|
|
if (!l->name) return -1;
|
|
|
|
if (!r->name) return +1;
|
2003-12-10 02:10:52 +00:00
|
|
|
|
2008-04-09 12:22:42 +00:00
|
|
|
if (g_columnToSort == ~0U)
|
2003-12-10 02:10:52 +00:00
|
|
|
g_columnToSort = 0;
|
|
|
|
|
2015-09-14 21:02:32 +00:00
|
|
|
if (g_columnToSort == 1)
|
2003-12-10 02:10:52 +00:00
|
|
|
return g_invertSort ? (int)r->dwValType - (int)l->dwValType : (int)l->dwValType - (int)r->dwValType;
|
2003-12-12 04:08:59 +00:00
|
|
|
if (g_columnToSort == 2) {
|
2003-12-10 02:10:52 +00:00
|
|
|
/* FIXME: Sort on value */
|
2015-09-14 21:01:21 +00:00
|
|
|
return 0;
|
2003-12-10 02:10:52 +00:00
|
|
|
}
|
2008-08-26 20:52:09 +00:00
|
|
|
return g_invertSort ? lstrcmpiW(r->name, l->name) : lstrcmpiW(l->name, r->name);
|
2003-08-07 03:10:13 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 20:19:38 +00:00
|
|
|
HWND StartValueRename(HWND hwndLV)
|
2004-01-13 23:18:12 +00:00
|
|
|
{
|
|
|
|
int item;
|
|
|
|
|
2011-04-16 08:07:27 +00:00
|
|
|
item = SendMessageW(hwndLV, LVM_GETNEXTITEM, -1, MAKELPARAM(LVNI_FOCUSED | LVNI_SELECTED, 0));
|
2004-05-04 02:55:28 +00:00
|
|
|
if (item < 1) { /* cannot rename default key */
|
|
|
|
MessageBeep(MB_ICONHAND);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-04-16 08:07:27 +00:00
|
|
|
return (HWND)SendMessageW(hwndLV, LVM_EDITLABELW, item, 0);
|
2004-01-13 23:18:12 +00:00
|
|
|
}
|
2003-08-07 03:10:13 +00:00
|
|
|
|
2008-04-09 12:22:42 +00:00
|
|
|
HWND CreateListView(HWND hwndParent, UINT id)
|
2003-08-07 03:10:13 +00:00
|
|
|
{
|
|
|
|
RECT rcClient;
|
|
|
|
HWND hwndLV;
|
|
|
|
|
2006-08-23 12:11:39 +00:00
|
|
|
/* prepare strings */
|
2018-05-21 13:34:49 +00:00
|
|
|
LoadStringW(hInst, IDS_REGISTRY_VALUE_NOT_SET, g_szValueNotSet, ARRAY_SIZE(g_szValueNotSet));
|
2006-08-23 12:11:39 +00:00
|
|
|
|
2003-08-07 03:10:13 +00:00
|
|
|
/* Get the dimensions of the parent window's client area, and create the list view control. */
|
|
|
|
GetClientRect(hwndParent, &rcClient);
|
2022-04-14 13:01:36 +00:00
|
|
|
hwndLV = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, L"List View",
|
2022-12-21 16:50:38 +00:00
|
|
|
WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS |
|
|
|
|
LVS_REPORT | LVS_EDITLABELS,
|
2003-12-08 22:48:07 +00:00
|
|
|
0, 0, rcClient.right, rcClient.bottom,
|
2009-01-15 08:47:14 +00:00
|
|
|
hwndParent, ULongToHandle(id), hInst, NULL);
|
2003-12-12 04:08:59 +00:00
|
|
|
if (!hwndLV) return NULL;
|
2008-08-31 14:49:43 +00:00
|
|
|
SendMessageW(hwndLV, LVM_SETUNICODEFORMAT, TRUE, 0);
|
2008-08-31 12:53:30 +00:00
|
|
|
SendMessageW(hwndLV, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
|
2003-08-07 03:10:13 +00:00
|
|
|
|
2005-03-21 10:29:32 +00:00
|
|
|
/* Initialize the image list */
|
|
|
|
if (!InitListViewImageList(hwndLV)) goto fail;
|
2003-12-12 04:08:59 +00:00
|
|
|
if (!CreateListColumns(hwndLV)) goto fail;
|
2003-08-07 03:10:13 +00:00
|
|
|
return hwndLV;
|
2003-12-12 04:08:59 +00:00
|
|
|
fail:
|
|
|
|
DestroyWindow(hwndLV);
|
|
|
|
return NULL;
|
2003-08-07 03:10:13 +00:00
|
|
|
}
|
|
|
|
|
2008-08-27 18:40:31 +00:00
|
|
|
BOOL RefreshListView(HWND hwndLV, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR highlightValue)
|
2003-08-07 03:10:13 +00:00
|
|
|
{
|
2004-01-16 23:02:44 +00:00
|
|
|
BOOL result = FALSE;
|
2003-12-12 04:08:59 +00:00
|
|
|
DWORD max_sub_key_len;
|
2004-01-16 23:02:44 +00:00
|
|
|
DWORD max_val_name_len, valNameLen;
|
|
|
|
DWORD max_val_size, valSize;
|
|
|
|
DWORD val_count, index, valType;
|
2008-08-26 18:57:23 +00:00
|
|
|
WCHAR* valName = 0;
|
2004-01-16 23:02:44 +00:00
|
|
|
BYTE* valBuf = 0;
|
|
|
|
HKEY hKey = 0;
|
2003-12-12 04:08:59 +00:00
|
|
|
LONG errCode;
|
2008-08-26 18:57:23 +00:00
|
|
|
LVITEMW item;
|
2003-08-07 03:10:13 +00:00
|
|
|
|
2003-12-12 04:08:59 +00:00
|
|
|
if (!hwndLV) return FALSE;
|
|
|
|
|
2008-08-26 18:57:23 +00:00
|
|
|
SendMessageW(hwndLV, WM_SETREDRAW, FALSE, 0);
|
|
|
|
|
2008-08-27 18:40:31 +00:00
|
|
|
errCode = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ, &hKey);
|
2004-01-16 23:02:44 +00:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
|
2008-04-09 12:22:42 +00:00
|
|
|
g_columnToSort = ~0U;
|
2017-06-28 12:49:54 +00:00
|
|
|
SendMessageW(hwndLV, LVM_DELETEALLITEMS, 0, 0);
|
2003-12-12 04:08:59 +00:00
|
|
|
|
|
|
|
/* get size information and resize the buffers if necessary */
|
2008-08-26 18:57:23 +00:00
|
|
|
errCode = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, &max_sub_key_len, NULL,
|
2003-12-12 04:08:59 +00:00
|
|
|
&val_count, &max_val_name_len, &max_val_size, NULL, NULL);
|
2004-01-16 23:02:44 +00:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
|
|
|
|
/* account for the terminator char */
|
|
|
|
max_val_name_len++;
|
|
|
|
max_val_size++;
|
|
|
|
|
2022-07-07 11:55:37 +00:00
|
|
|
valName = malloc(max_val_name_len * sizeof(WCHAR));
|
|
|
|
valBuf = malloc(max_val_size);
|
2009-01-29 07:47:42 +00:00
|
|
|
|
2017-05-01 09:30:31 +00:00
|
|
|
valSize = max_val_size;
|
2008-08-26 18:57:23 +00:00
|
|
|
if (RegQueryValueExW(hKey, NULL, NULL, &valType, valBuf, &valSize) == ERROR_FILE_NOT_FOUND) {
|
2017-06-16 13:06:59 +00:00
|
|
|
AddEntryToList(hwndLV, NULL, REG_SZ, NULL, 0, -1);
|
2004-05-04 02:55:28 +00:00
|
|
|
}
|
2004-01-16 23:02:44 +00:00
|
|
|
for(index = 0; index < val_count; index++) {
|
|
|
|
valNameLen = max_val_name_len;
|
|
|
|
valSize = max_val_size;
|
|
|
|
valType = 0;
|
2008-08-26 18:57:23 +00:00
|
|
|
errCode = RegEnumValueW(hKey, index, valName, &valNameLen, NULL, &valType, valBuf, &valSize);
|
2004-01-16 23:02:44 +00:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
valBuf[valSize] = 0;
|
2017-06-16 13:06:59 +00:00
|
|
|
AddEntryToList(hwndLV, valName[0] ? valName : NULL, valType, valBuf, valSize, -1);
|
2017-05-22 13:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&item, 0, sizeof(item));
|
|
|
|
if (!highlightValue)
|
|
|
|
{
|
|
|
|
item.state = item.stateMask = LVIS_FOCUSED;
|
|
|
|
SendMessageW(hwndLV, LVM_SETITEMSTATE, 0, (LPARAM)&item);
|
2003-08-07 03:10:13 +00:00
|
|
|
}
|
2017-05-22 13:02:52 +00:00
|
|
|
|
2008-08-26 18:57:23 +00:00
|
|
|
SendMessageW(hwndLV, LVM_SORTITEMS, (WPARAM)hwndLV, (LPARAM)CompareFunc);
|
2004-01-16 23:02:44 +00:00
|
|
|
|
|
|
|
g_currentRootKey = hKeyRoot;
|
2017-07-12 11:08:54 +00:00
|
|
|
if (keyPath != g_currentPath && !update_listview_path(keyPath))
|
|
|
|
goto done;
|
2004-01-16 23:02:44 +00:00
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
done:
|
2022-07-07 11:55:37 +00:00
|
|
|
free(valBuf);
|
|
|
|
free(valName);
|
2008-08-26 18:57:23 +00:00
|
|
|
SendMessageW(hwndLV, WM_SETREDRAW, TRUE, 0);
|
2004-01-16 23:02:44 +00:00
|
|
|
if (hKey) RegCloseKey(hKey);
|
2003-12-12 04:08:59 +00:00
|
|
|
|
2004-01-16 23:02:44 +00:00
|
|
|
return result;
|
2003-08-07 03:10:13 +00:00
|
|
|
}
|