📄 listview.c
字号:
/*
* Regedit listviews
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* 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
*/
#include <regedit.h>
#define CX_ICON 16
#define CY_ICON 16
#define NUM_ICONS 2
int Image_String = 0;
int Image_Bin = 0;
typedef struct tagLINE_INFO
{
DWORD dwValType;
LPTSTR name;
void* val;
size_t val_len;
} LINE_INFO, *PLINE_INFO;
/*******************************************************************************
* Global and Local Variables:
*/
static DWORD g_columnToSort = ~0UL;
static BOOL g_invertSort = FALSE;
#define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
static const int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
static const int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
LPCTSTR GetValueName(HWND hwndLV, int iStartAt)
{
int item;
LVITEM LVItem;
PLINE_INFO lineinfo;
/*
if a new item is inserted, then no allocation,
otherwise the heap block will be lost!
*/
item = ListView_GetNextItem(hwndLV, iStartAt, LVNI_SELECTED);
if (item == -1) return NULL;
/*
Should be always TRUE anyways
*/
LVItem.iItem = item;
LVItem.iSubItem = 0;
LVItem.mask = LVIF_PARAM;
if (ListView_GetItem(hwndLV, &LVItem) == FALSE)
return NULL;
lineinfo = (PLINE_INFO)LVItem.lParam;
if (lineinfo == NULL)
return NULL;
return lineinfo->name;
}
BOOL IsDefaultValue(HWND hwndLV, int i)
{
PLINE_INFO lineinfo;
LVITEM Item;
Item.mask = LVIF_PARAM;
Item.iItem = i;
if(ListView_GetItem(hwndLV, &Item))
{
lineinfo = (PLINE_INFO)Item.lParam;
return lineinfo && (!lineinfo->name || !_tcscmp(lineinfo->name, _T("")));
}
return FALSE;
}
/*******************************************************************************
* Local module support methods
*/
static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValBuf, DWORD dwCount, int Position, BOOL ValExists)
{
PLINE_INFO linfo;
LVITEM item;
int index;
linfo = (PLINE_INFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINE_INFO) + dwCount);
linfo->dwValType = dwValType;
linfo->val_len = dwCount;
if(dwCount > 0)
{
memcpy(&linfo[1], ValBuf, dwCount);
}
linfo->name = _tcsdup(Name);
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
item.iItem = (Position == -1 ? 0: Position);
item.iSubItem = 0;
item.state = 0;
item.stateMask = 0;
item.pszText = Name;
item.cchTextMax = (int) _tcslen(item.pszText);
if (item.cchTextMax == 0)
item.pszText = LPSTR_TEXTCALLBACK;
item.iImage = 0;
item.lParam = (LPARAM)linfo;
switch(dwValType)
{
case REG_SZ:
case REG_EXPAND_SZ:
case REG_MULTI_SZ:
item.iImage = Image_String;
break;
default:
item.iImage = Image_Bin;
break;
}
/* item.lParam = (LPARAM)ValBuf; */
#if (_WIN32_IE >= 0x0300)
item.iIndent = 0;
#endif
index = ListView_InsertItem(hwndLV, &item);
if (index != -1) {
switch (dwValType) {
case REG_SZ:
case REG_EXPAND_SZ:
if(dwCount > 0)
{
ListView_SetItemText(hwndLV, index, 2, ValBuf);
}
else if(!ValExists)
{
TCHAR buffer[255];
/* load (value not set) string */
LoadString(hInst, IDS_VALUE_NOT_SET, buffer, sizeof(buffer)/sizeof(TCHAR));
ListView_SetItemText(hwndLV, index, 2, buffer);
}
break;
case REG_MULTI_SZ:
{
LPTSTR src, str;
if(dwCount >= 2)
{
src = (LPTSTR)ValBuf;
str = HeapAlloc(GetProcessHeap(), 0, dwCount);
if(str != NULL)
{
*str = _T('\0');
/* concatenate all srings */
while(*src != _T('\0'))
{
_tcscat(str, src);
_tcscat(str, _T(" "));
src += _tcslen(src) + 1;
}
ListView_SetItemText(hwndLV, index, 2, str);
HeapFree(GetProcessHeap(), 0, str);
}
else
ListView_SetItemText(hwndLV, index, 2, _T(""));
}
else
ListView_SetItemText(hwndLV, index, 2, _T(""));
}
break;
case REG_DWORD: {
TCHAR buf[200];
if(dwCount == sizeof(DWORD))
{
wsprintf(buf, _T("0x%08X (%d)"), *(DWORD*)ValBuf, *(DWORD*)ValBuf);
}
else
{
LoadString(hInst, IDS_INVALID_DWORD, buf, sizeof(buf)/sizeof(TCHAR));
}
ListView_SetItemText(hwndLV, index, 2, buf);
}
/* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */
break;
default:
{
unsigned int i;
LPBYTE pData = (LPBYTE)ValBuf;
LPTSTR strBinary;
if(dwCount > 0)
{
strBinary = HeapAlloc(GetProcessHeap(), 0, (dwCount * sizeof(TCHAR) * 3) + sizeof(TCHAR));
for (i = 0; i < dwCount; i++)
{
wsprintf( strBinary + i*3, _T("%02X "), pData[i] );
}
strBinary[dwCount * 3] = 0;
ListView_SetItemText(hwndLV, index, 2, strBinary);
HeapFree(GetProcessHeap(), 0, strBinary);
}
else
{
TCHAR szText[128];
LoadString(hInst, IDS_BINARY_EMPTY, szText, sizeof(szText)/sizeof(TCHAR));
ListView_SetItemText(hwndLV, index, 2, szText);
}
}
break;
}
}
}
static BOOL CreateListColumns(HWND hWndListView)
{
TCHAR szText[50];
int index;
LV_COLUMN lvC;
/* 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];
LoadString(hInst, IDS_LIST_COLUMN_FIRST + index, szText, sizeof(szText)/sizeof(TCHAR));
if (ListView_InsertColumn(hWndListView, index, &lvC) == -1) return FALSE;
}
return TRUE;
}
static BOOL InitListViewImageLists(HWND hwndLV)
{
HIMAGELIST himl; /* handle to image list */
HICON hico; /* handle to icon */
/* Create the image list. */
if ((himl = ImageList_Create(CX_ICON, CY_ICON,
ILC_MASK, 0, NUM_ICONS)) == NULL)
return FALSE;
hico = LoadIcon(hInst, MAKEINTRESOURCE(IDI_BIN));
Image_Bin = ImageList_AddIcon(himl, hico);
hico = LoadIcon(hInst, MAKEINTRESOURCE(IDI_STRING));
Image_String = ImageList_AddIcon(himl, hico);
/* Fail if not all of the images were added. */
if (ImageList_GetImageCount(himl) < NUM_ICONS)
{
return FALSE;
}
/* Associate the image list with the tree view control. */
(void)ListView_SetImageList(hwndLV, himl, LVSIL_SMALL);
return TRUE;
}
/* OnGetDispInfo - processes the LVN_GETDISPINFO notification message. */
static void OnGetDispInfo(NMLVDISPINFO* plvdi)
{
static TCHAR buffer[200];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -