mirror of
https://github.com/reactos/reactos.git
synced 2024-12-25 16:50:57 +00:00
Updated with cleanup of treeview module.
svn path=/trunk/; revision=3256
This commit is contained in:
parent
fb4e8713ea
commit
53dd918713
10 changed files with 236 additions and 334 deletions
|
@ -46,6 +46,28 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void MakeFullRegPath(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max)
|
||||
{
|
||||
TVITEM item;
|
||||
item.mask = TVIF_PARAM;
|
||||
item.hItem = hItem;
|
||||
if (TreeView_GetItem(hwndTV, &item)) {
|
||||
if (item.hItem != TreeView_GetRoot(hwndTV)) {
|
||||
// recurse
|
||||
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)
|
||||
{
|
||||
RECT rt;
|
||||
|
@ -58,8 +80,6 @@ static void draw_splitbar(HWND hWnd, int x)
|
|||
ReleaseDC(hWnd, hdc);
|
||||
}
|
||||
|
||||
#define _NO_EXTENSIONS
|
||||
|
||||
static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
|
||||
{
|
||||
HDWP hdwp = BeginDeferWindowPos(2);
|
||||
|
@ -137,8 +157,8 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
|
||||
ASSERT(pChildWnd);
|
||||
pChildWnd->nSplitPos = 250;
|
||||
pChildWnd->hTreeWnd = CreateTreeView(hWnd, TREE_WINDOW, &pChildWnd->root);
|
||||
pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW, &pChildWnd->root);
|
||||
pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->root.path, TREE_WINDOW);
|
||||
pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, &pChildWnd->root*/);
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
|
||||
|
@ -170,16 +190,13 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
GetClientRect(hWnd, &rt);
|
||||
if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
|
||||
last_split = pChildWnd->nSplitPos;
|
||||
#ifdef _NO_EXTENSIONS
|
||||
draw_splitbar(hWnd, last_split);
|
||||
#endif
|
||||
SetCapture(hWnd);
|
||||
}
|
||||
break;}
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
if (GetCapture() == hWnd) {
|
||||
#ifdef _NO_EXTENSIONS
|
||||
RECT rt;
|
||||
int x = LOWORD(lParam);
|
||||
draw_splitbar(hWnd, last_split);
|
||||
|
@ -187,26 +204,20 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
GetClientRect(hWnd, &rt);
|
||||
pChildWnd->nSplitPos = x;
|
||||
ResizeWnd(pChildWnd, rt.right, rt.bottom);
|
||||
#endif
|
||||
ReleaseCapture();
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef _NO_EXTENSIONS
|
||||
case WM_CAPTURECHANGED:
|
||||
if (GetCapture()==hWnd && last_split>=0)
|
||||
draw_splitbar(hWnd, last_split);
|
||||
break;
|
||||
#endif
|
||||
case WM_KEYDOWN:
|
||||
|
||||
case WM_KEYDOWN:
|
||||
if (wParam == VK_ESCAPE)
|
||||
if (GetCapture() == hWnd) {
|
||||
RECT rt;
|
||||
#ifdef _NO_EXTENSIONS
|
||||
draw_splitbar(hWnd, last_split);
|
||||
#else
|
||||
pChildWnd->nSplitPos = last_split;
|
||||
#endif
|
||||
GetClientRect(hWnd, &rt);
|
||||
ResizeWnd(pChildWnd, rt.right, rt.bottom);
|
||||
last_split = -1;
|
||||
|
@ -219,7 +230,6 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
if (GetCapture() == hWnd) {
|
||||
RECT rt;
|
||||
int x = LOWORD(lParam);
|
||||
#ifdef _NO_EXTENSIONS
|
||||
HDC hdc = GetDC(hWnd);
|
||||
GetClientRect(hWnd, &rt);
|
||||
rt.left = last_split-SPLIT_WIDTH/2;
|
||||
|
@ -230,33 +240,10 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
rt.right = x+SPLIT_WIDTH/2+1;
|
||||
InvertRect(hdc, &rt);
|
||||
ReleaseDC(hWnd, hdc);
|
||||
#else
|
||||
GetClientRect(hWnd, &rt);
|
||||
if (x>=0 && x<rt.right) {
|
||||
pChildWnd->nSplitPos = x;
|
||||
//resize_tree(pChildWnd, rt.right, rt.bottom);
|
||||
rt.left = x-SPLIT_WIDTH/2;
|
||||
rt.right = x+SPLIT_WIDTH/2+1;
|
||||
InvalidateRect(hWnd, &rt, FALSE);
|
||||
UpdateWindow(hTreeWnd);
|
||||
UpdateWindow(hWnd);
|
||||
UpdateWindow(hListWnd);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
#ifndef _NO_EXTENSIONS
|
||||
case WM_GETMINMAXINFO:
|
||||
DefWindowProc(hWnd, message, wParam, lParam);
|
||||
{LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
|
||||
lpmmi->ptMaxTrackSize.x <<= 1;//2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN
|
||||
lpmmi->ptMaxTrackSize.y <<= 1;//2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN
|
||||
break;}
|
||||
#endif
|
||||
|
||||
case WM_SETFOCUS:
|
||||
// SetCurrentDirectory(szPath);
|
||||
if (pChildWnd != NULL) {
|
||||
SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
|
||||
}
|
||||
|
@ -267,22 +254,23 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
|
||||
case WM_NOTIFY:
|
||||
if ((int)wParam == TREE_WINDOW) {
|
||||
if ((((LPNMHDR)lParam)->code) == TVN_SELCHANGED) {
|
||||
Entry* entry = (Entry*)((NMTREEVIEW*)lParam)->itemNew.lParam;
|
||||
if (entry != NULL) {
|
||||
if (!entry->scanned) {
|
||||
//scan_entry(pChildWnd, entry);
|
||||
} else {
|
||||
//RefreshList(pChildWnd->hListWnd, entry);
|
||||
}
|
||||
//RefreshList(pChildWnd->hListWnd, entry->down);
|
||||
RefreshList(pChildWnd->hListWnd, entry);
|
||||
switch (((LPNMHDR)lParam)->code) {
|
||||
case TVN_ITEMEXPANDING:
|
||||
return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
|
||||
case TVN_SELCHANGED:
|
||||
{
|
||||
TCHAR keyPath[1000];
|
||||
int keyPathLen = 0;
|
||||
keyPath[0] = _T('\0');
|
||||
MakeFullRegPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, keyPath, &keyPathLen, sizeof(keyPath));
|
||||
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)keyPath);
|
||||
}
|
||||
}
|
||||
if (!SendMessage(pChildWnd->hTreeWnd, message, wParam, lParam)) {
|
||||
// RefreshList(pChildWnd->hListWnd, entry);
|
||||
break;
|
||||
default:
|
||||
goto def;
|
||||
}
|
||||
}
|
||||
} else
|
||||
if ((int)wParam == LIST_WINDOW) {
|
||||
if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) {
|
||||
goto def;
|
||||
|
|
|
@ -66,20 +66,20 @@ static void resize_frame_rect(HWND hWnd, PRECT prect)
|
|||
}
|
||||
*/
|
||||
if (IsWindowVisible(hStatusBar)) {
|
||||
SetupStatusBar(TRUE);
|
||||
SetupStatusBar(hWnd, TRUE);
|
||||
GetClientRect(hStatusBar, &rt);
|
||||
prect->bottom -= rt.bottom;
|
||||
}
|
||||
MoveWindow(hChildWnd, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
static void resize_frame(HWND hWnd, int cx, int cy)
|
||||
{
|
||||
RECT rect = {0, 0, cx, cy};
|
||||
|
||||
resize_frame_rect(hWnd, &rect);
|
||||
}
|
||||
|
||||
*/
|
||||
void resize_frame_client(HWND hWnd)
|
||||
{
|
||||
RECT rect;
|
||||
|
@ -102,19 +102,9 @@ static void OnEnterMenuLoop(HWND hWnd)
|
|||
|
||||
static void OnExitMenuLoop(HWND hWnd)
|
||||
{
|
||||
RECT rc;
|
||||
int nParts[3];
|
||||
// TCHAR text[260];
|
||||
|
||||
bInMenuLoop = FALSE;
|
||||
// Update the status bar pane sizes
|
||||
GetClientRect(hWnd, &rc);
|
||||
nParts[0] = 100;
|
||||
nParts[1] = 210;
|
||||
nParts[2] = rc.right;
|
||||
SendMessage(hStatusBar, SB_SETPARTS, 3, (long)nParts);
|
||||
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)_T(""));
|
||||
SetupStatusBar(TRUE);
|
||||
SetupStatusBar(hWnd, TRUE);
|
||||
UpdateStatusBar();
|
||||
}
|
||||
|
||||
|
@ -139,21 +129,16 @@ static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
|
|||
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)str);
|
||||
}
|
||||
|
||||
void SetupStatusBar(BOOL bResize)
|
||||
void SetupStatusBar(HWND hWnd, BOOL bResize)
|
||||
{
|
||||
int nParts[4];
|
||||
// int parts[] = {300, 500};
|
||||
// SendMessage(Globals.hStatusBar, WM_SIZE, 0, 0);
|
||||
// SendMessage(Globals.hStatusBar, SB_SETPARTS, 2, (LPARAM)&parts);
|
||||
|
||||
// Create the status bar panes
|
||||
nParts[0] = 150;
|
||||
nParts[1] = 220;
|
||||
nParts[2] = 100;
|
||||
nParts[3] = 100;
|
||||
RECT rc;
|
||||
int nParts;
|
||||
GetClientRect(hWnd, &rc);
|
||||
nParts = rc.right;
|
||||
// nParts = -1;
|
||||
if (bResize)
|
||||
SendMessage(hStatusBar, WM_SIZE, 0, 0);
|
||||
SendMessage(hStatusBar, SB_SETPARTS, 4, (long)nParts);
|
||||
SendMessage(hStatusBar, SB_SETPARTS, 1, (LPARAM)&nParts);
|
||||
}
|
||||
|
||||
void UpdateStatusBar(void)
|
||||
|
@ -163,10 +148,11 @@ void UpdateStatusBar(void)
|
|||
|
||||
// size = sizeof(text)/sizeof(TCHAR);
|
||||
// GetUserName(text, &size);
|
||||
// SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)text);
|
||||
// SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)text);
|
||||
// SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)_T(""));
|
||||
size = sizeof(text)/sizeof(TCHAR);
|
||||
GetComputerName(text, &size);
|
||||
SendMessage(hStatusBar, SB_SETTEXT, 3, (LPARAM)text);
|
||||
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)text);
|
||||
}
|
||||
|
||||
static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
|
||||
|
|
|
@ -34,7 +34,7 @@ extern "C" {
|
|||
|
||||
LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
void SetupStatusBar(BOOL bResize);
|
||||
void SetupStatusBar(HWND hWnd, BOOL bResize);
|
||||
void UpdateStatusBar(void);
|
||||
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ static void CreateListColumns(HWND hWndListView)
|
|||
|
||||
static void OnGetDispInfo(NMLVDISPINFO* plvdi)
|
||||
{
|
||||
static TCHAR buffer[200];
|
||||
// static TCHAR buffer[200];
|
||||
|
||||
// FILETIME LastWriteTime;
|
||||
// TCHAR Class[MAX_NAME_LEN];
|
||||
|
@ -295,7 +295,7 @@ static LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPAR
|
|||
}
|
||||
|
||||
|
||||
HWND CreateListView(HWND hwndParent/*, Pane* pane*/, int id, Root* pRoot/*Entry* pEntry*/)
|
||||
HWND CreateListView(HWND hwndParent, int id)
|
||||
{
|
||||
RECT rcClient; // dimensions of client area
|
||||
HWND hwndLV; // handle to list view control
|
||||
|
@ -308,6 +308,7 @@ HWND CreateListView(HWND hwndParent/*, Pane* pane*/, int id, Root* pRoot/*Entry*
|
|||
WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT,
|
||||
0, 0, rcClient.right, rcClient.bottom,
|
||||
hwndParent, (HMENU)id, hInst, NULL);
|
||||
ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
|
||||
|
||||
// Initialize the image list, and add items to the control.
|
||||
/*
|
||||
|
@ -317,10 +318,9 @@ HWND CreateListView(HWND hwndParent/*, Pane* pane*/, int id, Root* pRoot/*Entry*
|
|||
return FALSE;
|
||||
}
|
||||
*/
|
||||
ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
|
||||
CreateListColumns(hwndLV);
|
||||
|
||||
SetWindowLong(hwndLV, GWL_USERDATA, (LPARAM)pRoot);
|
||||
// SetWindowLong(hwndLV, GWL_USERDATA, (LPARAM)pRoot);
|
||||
g_orgListWndProc = SubclassWindow(hwndLV, ListWndProc);
|
||||
//SendMessage(hwndLV, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
|
||||
|
||||
|
@ -332,14 +332,14 @@ HWND CreateListView(HWND hwndParent/*, Pane* pane*/, int id, Root* pRoot/*Entry*
|
|||
return hwndLV;
|
||||
}
|
||||
|
||||
void RefreshList(HWND hWnd, Entry* entry)
|
||||
void RefreshList(HWND hWnd/*, Entry* entry*/)
|
||||
{
|
||||
if (hWnd != NULL) {
|
||||
ListView_DeleteAllItems(hWnd);
|
||||
if (entry != NULL) {
|
||||
TRACE("RefreshList(...) entry name: %p\n", entry);
|
||||
InsertListEntries(hWnd, entry, -1);
|
||||
}
|
||||
// if (entry != NULL) {
|
||||
// TRACE("RefreshList(...) entry name: %p\n", entry);
|
||||
// InsertListEntries(hWnd, entry, -1);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,10 @@ extern "C" {
|
|||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
HWND CreateListView(HWND hwndParent, int id, Root* pRoot);
|
||||
void RefreshList(HWND hWnd, Entry* entry);
|
||||
//HWND CreateListView(HWND hwndParent, int id, Root* pRoot);
|
||||
//void RefreshList(HWND hWnd, Entry* entry);
|
||||
HWND CreateListView(HWND hwndParent, int id);
|
||||
void RefreshList(HWND hWnd);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -101,7 +101,8 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|||
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
|
||||
|
||||
};
|
||||
ATOM hChildWndClass = RegisterClassEx(&wcChild); // register child windows class
|
||||
// ATOM hChildWndClass = RegisterClassEx(&wcChild); // register child windows class
|
||||
RegisterClassEx(&wcChild); // register child windows class
|
||||
|
||||
/*
|
||||
WNDCLASSEX wcex;
|
||||
|
@ -143,11 +144,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|||
_T(""), hFrameWnd, STATUS_WINDOW);
|
||||
if (hStatusBar) {
|
||||
// Create the status bar panes
|
||||
int nParts[3];
|
||||
nParts[0] = 100;
|
||||
nParts[1] = 210;
|
||||
nParts[2] = 400;
|
||||
SendMessage(hStatusBar, SB_SETPARTS, 3, (long)nParts);
|
||||
SetupStatusBar(hFrameWnd, FALSE);
|
||||
CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
|
||||
}
|
||||
ShowWindow(hFrameWnd, nCmdShow);
|
||||
|
|
|
@ -32,7 +32,7 @@ extern "C" {
|
|||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "resource.h"
|
||||
#include "regproc.h"
|
||||
//#include "regproc.h"
|
||||
|
||||
|
||||
#define STATUS_WINDOW 2001
|
||||
|
@ -45,6 +45,8 @@ extern "C" {
|
|||
#define MAX_NAME_LEN 500
|
||||
|
||||
|
||||
//#include "entries.h"
|
||||
//#if 0
|
||||
typedef struct _Entry {
|
||||
struct _Entry* next;
|
||||
struct _Entry* down;
|
||||
|
@ -75,7 +77,7 @@ typedef struct {
|
|||
int nSplitPos;
|
||||
Root root;
|
||||
} ChildWnd;
|
||||
|
||||
//#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global Variables:
|
||||
|
|
|
@ -39,9 +39,9 @@ IDI_SMALL ICON DISCARDABLE "res/small.ico"
|
|||
// Bitmap
|
||||
//
|
||||
|
||||
IDB_OPEN_FILE BITMAP DISCARDABLE "res/folder1.bmp"
|
||||
IDB_CLOSED_FILE BITMAP DISCARDABLE "res/folder2.bmp"
|
||||
IDB_ROOT BITMAP DISCARDABLE "res/folder3.bmp"
|
||||
IDB_OPEN_FILE BITMAP DISCARDABLE "res/folder3.bmp"
|
||||
IDB_CLOSED_FILE BITMAP DISCARDABLE "res/folder1.bmp"
|
||||
IDB_ROOT BITMAP DISCARDABLE "res/folder2.bmp"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
@ -167,6 +167,49 @@ END
|
|||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,1
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x1L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "0c0904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "Absolutely no warranties whatsoever - Use at your own risk\0"
|
||||
VALUE "CompanyName", "ReactWare\0"
|
||||
VALUE "FileDescription", "ReactOS Registry Editor by Robert Dickenson\0"
|
||||
VALUE "FileVersion", "1, 0, 0, 1\0"
|
||||
VALUE "InternalName", "regedit\0"
|
||||
VALUE "LegalCopyright", "Copyright © 2002 Robert Dickenson\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "regedit.exe\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "ReactOS Registry Editor\0"
|
||||
VALUE "ProductVersion", "1, 0, 0, 1\0"
|
||||
VALUE "SpecialBuild", "Non-versioned Development Beta Release\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0xc09, 1200
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
|
|
|
@ -34,18 +34,13 @@
|
|||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <windowsx.h>
|
||||
#include <assert.h>
|
||||
#define ASSERT assert
|
||||
//#include <windowsx.h>
|
||||
#include "main.h"
|
||||
#include "treeview.h"
|
||||
|
||||
#include "trace.h"
|
||||
|
||||
|
||||
// Global variables and constants
|
||||
// Image_Open, Image_Closed, and Image_Root - integer variables for
|
||||
// indexes of the images.
|
||||
// Image_Open, Image_Closed, and Image_Root - integer variables for indexes of the images.
|
||||
// CX_BITMAP and CY_BITMAP - width and height of an icon.
|
||||
// NUM_BITMAPS - number of bitmaps to add to the image list.
|
||||
int Image_Open;
|
||||
|
@ -57,109 +52,92 @@ int Image_Root;
|
|||
#define NUM_BITMAPS 3
|
||||
|
||||
|
||||
static HTREEITEM AddEntryToTree(HWND hwndTV, Entry* entry, LPTSTR label)
|
||||
static HKEY FindRegRoot(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max)
|
||||
{
|
||||
HKEY hKey = NULL;
|
||||
TVITEM item;
|
||||
item.mask = TVIF_PARAM;
|
||||
item.hItem = TreeView_GetParent(hwndTV, hItem);
|
||||
|
||||
if (TreeView_GetItem(hwndTV, &item)) {
|
||||
if (item.lParam == 0) {
|
||||
// recurse
|
||||
hKey = FindRegRoot(hwndTV, item.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);
|
||||
}
|
||||
} else {
|
||||
// found root key with valid key value
|
||||
hKey = (HKEY)item.lParam;
|
||||
item.mask = TVIF_TEXT;
|
||||
item.hItem = hItem;
|
||||
// item.pszText = &keyPath[*pPathLen];
|
||||
item.pszText = keyPath;
|
||||
item.cchTextMax = max;
|
||||
if (TreeView_GetItem(hwndTV, &item)) {
|
||||
*pPathLen += _tcslen(item.pszText);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hKey;
|
||||
}
|
||||
|
||||
static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPTSTR label, HKEY hKey, DWORD dwChildren)
|
||||
{
|
||||
HTREEITEM hItem = 0;
|
||||
TVITEM tvi;
|
||||
TVINSERTSTRUCT tvins;
|
||||
static HTREEITEM hPrev = (HTREEITEM)TVI_FIRST;
|
||||
static HTREEITEM hPrevRootItem = NULL;
|
||||
static HTREEITEM hPrevLev2Item = NULL;
|
||||
|
||||
//TRACE("AddEntryToTree(level:%u - %s)\n", entry->level, entry->data.cFileName);
|
||||
|
||||
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
|
||||
/*
|
||||
// Set the text of the item.
|
||||
tvi.pszText = entry->data.cFileName;
|
||||
tvi.cchTextMax = lstrlen(entry->data.cFileName);
|
||||
// Assume the item is not a parent item, so give it an image.
|
||||
tvi.iImage = Image_Root;
|
||||
tvi.iSelectedImage = Image_Root;
|
||||
tvi.cChildren = 1;
|
||||
// Save the heading level in the item's application-defined data area.
|
||||
//tvi.lParam = (LPARAM)entry->level;
|
||||
*/
|
||||
if (label != NULL) {
|
||||
tvi.pszText = label;
|
||||
tvi.cchTextMax = _tcslen(label);
|
||||
} else {
|
||||
tvi.pszText = LPSTR_TEXTCALLBACK;
|
||||
tvi.cchTextMax = 0;
|
||||
}
|
||||
tvi.iImage = I_IMAGECALLBACK;
|
||||
tvi.iSelectedImage = I_IMAGECALLBACK;
|
||||
tvi.cChildren = I_CHILDRENCALLBACK;
|
||||
// Save the entry pointer in the item's application-defined data area.
|
||||
tvi.lParam = (LPARAM)entry;
|
||||
|
||||
tvi.pszText = label;
|
||||
tvi.cchTextMax = lstrlen(tvi.pszText);
|
||||
tvi.iImage = Image_Closed;
|
||||
tvi.iSelectedImage = Image_Open;
|
||||
tvi.cChildren = dwChildren;
|
||||
tvi.lParam = (LPARAM)hKey;
|
||||
tvins.item = tvi;
|
||||
tvins.hInsertAfter = hPrev;
|
||||
|
||||
// Set the parent item based on the specified level.
|
||||
if (entry->level == 0) {
|
||||
tvins.hParent = TVI_ROOT;
|
||||
} else if (entry->level == 1) {
|
||||
tvins.hParent = hPrevRootItem;
|
||||
} else {
|
||||
tvins.hParent = hPrevLev2Item;
|
||||
if (hPrevLev2Item) {
|
||||
tvins.hParent = entry->up->hTreeItem;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the item to the tree view control.
|
||||
hPrev = (HTREEITEM)SendMessage(hwndTV, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
|
||||
|
||||
// Save the handle to the item.
|
||||
if (entry->level == 0)
|
||||
hPrevRootItem = hPrev;
|
||||
else if (entry->level == 1)
|
||||
hPrevLev2Item = hPrev;
|
||||
hItem = hPrev;
|
||||
if (hKey) tvins.hInsertAfter = (HTREEITEM)TVI_LAST;
|
||||
else tvins.hInsertAfter = (HTREEITEM)TVI_SORT;
|
||||
tvins.hParent = hParent;
|
||||
hItem = (HTREEITEM)SendMessage(hwndTV, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
|
||||
return hItem;
|
||||
}
|
||||
|
||||
static Entry* CreateEntry(Entry* pParentEntry, HKEY hKey, LPCTSTR szKeyName)
|
||||
{
|
||||
Entry* pEntry = NULL;
|
||||
|
||||
pEntry = malloc(sizeof(Entry));
|
||||
memset(pEntry, 0, sizeof(Entry));
|
||||
//pEntry->up = pParentEntry;
|
||||
pEntry->level = 1;
|
||||
pEntry->hKey = hKey;
|
||||
_tcsncpy(pEntry->szName, szKeyName, MAX_NAME_LEN);
|
||||
// pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, szKeyName);
|
||||
return pEntry;
|
||||
}
|
||||
|
||||
static BOOL InitTreeViewItems(HWND hwndTV, Root* pRoot/*LPCTSTR pHostName*/)
|
||||
static BOOL InitTreeViewItems(HWND hwndTV, LPTSTR pHostName)
|
||||
{
|
||||
// HKEY hKey;
|
||||
// LONG errCode;
|
||||
Entry* pEntry = &pRoot->entry;
|
||||
HTREEITEM hRootItem;
|
||||
TVITEM tvi;
|
||||
TVINSERTSTRUCT tvins;
|
||||
HTREEITEM hRoot;
|
||||
|
||||
// TCHAR* pHostName = _T("My Computer");
|
||||
// HTREEITEM hRootItem = AddItemToTree(hwndTV, pHostName, 1);
|
||||
// pEntry = malloc(sizeof(Entry));
|
||||
// memset(pEntry, 0, sizeof(Entry));
|
||||
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
|
||||
// Set the text of the item.
|
||||
tvi.pszText = pHostName;
|
||||
tvi.cchTextMax = lstrlen(tvi.pszText);
|
||||
// Assume the item is not a parent item, so give it an image.
|
||||
tvi.iImage = Image_Root;
|
||||
tvi.iSelectedImage = Image_Root;
|
||||
tvi.cChildren = 5;
|
||||
// Save the heading level in the item's application-defined data area.
|
||||
tvi.lParam = (LPARAM)NULL;
|
||||
tvins.item = tvi;
|
||||
tvins.hInsertAfter = (HTREEITEM)TVI_FIRST;
|
||||
tvins.hParent = TVI_ROOT;
|
||||
// Add the item to the tree view control.
|
||||
hRoot = (HTREEITEM)SendMessage(hwndTV, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
|
||||
|
||||
pEntry->level = 0;
|
||||
pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, pRoot->path);
|
||||
hRootItem = pEntry->hTreeItem;
|
||||
AddEntryToTree(hwndTV, hRoot, _T("HKEY_CLASSES_ROOT"), HKEY_CLASSES_ROOT, 1);
|
||||
AddEntryToTree(hwndTV, hRoot, _T("HKEY_CURRENT_USER"), HKEY_CURRENT_USER, 1);
|
||||
AddEntryToTree(hwndTV, hRoot, _T("HKEY_LOCAL_MACHINE"), HKEY_LOCAL_MACHINE, 1);
|
||||
AddEntryToTree(hwndTV, hRoot, _T("HKEY_USERS"), HKEY_USERS, 1);
|
||||
AddEntryToTree(hwndTV, hRoot, _T("HKEY_CURRENT_CONFIG"), HKEY_CURRENT_CONFIG, 1);
|
||||
|
||||
pEntry = CreateEntry(&pRoot->entry, HKEY_CLASSES_ROOT, _T("HKEY_CLASSES_ROOT"));
|
||||
pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, NULL);
|
||||
pEntry = CreateEntry(&pRoot->entry, HKEY_CURRENT_USER, _T("HKEY_CURRENT_USER"));
|
||||
pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, NULL);
|
||||
pEntry = CreateEntry(&pRoot->entry, HKEY_LOCAL_MACHINE, _T("HKEY_LOCAL_MACHINE"));
|
||||
pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, NULL);
|
||||
pEntry = CreateEntry(&pRoot->entry, HKEY_USERS, _T("HKEY_USERS"));
|
||||
pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, NULL);
|
||||
pEntry = CreateEntry(&pRoot->entry, HKEY_CURRENT_CONFIG, _T("HKEY_CURRENT_CONFIG"));
|
||||
pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -201,165 +179,73 @@ static BOOL InitTreeViewImageLists(HWND hwndTV)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define NMTVDISPINFO TV_DISPINFO
|
||||
#define NMTVDISPINFO TV_DISPINFO
|
||||
#endif
|
||||
|
||||
static void OnGetDispInfo(NMTVDISPINFO* ptvdi)
|
||||
{
|
||||
Entry* pEntry = (Entry*)ptvdi->item.lParam;
|
||||
ASSERT(pEntry);
|
||||
|
||||
if (ptvdi->item.mask & TVIF_CHILDREN ) {
|
||||
ptvdi->item.cChildren = 5;
|
||||
}
|
||||
if (ptvdi->item.mask & TVIF_IMAGE) {
|
||||
ptvdi->item.iImage = Image_Root;
|
||||
}
|
||||
if (ptvdi->item.mask & TVIF_SELECTEDIMAGE) {
|
||||
ptvdi->item.iSelectedImage = Image_Closed;
|
||||
}
|
||||
if (ptvdi->item.mask & TVIF_TEXT) {
|
||||
/*
|
||||
ptvdi->item.pszText = _T("Unknown");
|
||||
ptvdi->item.cchTextMax = _tcslen(ptvdi->item.pszText);
|
||||
if (pEntry->bKey == TRUE) {
|
||||
DWORD nSubKeys;
|
||||
DWORD MaxSubKeyLen;
|
||||
DWORD MaxClassLen;
|
||||
DWORD ValueCount;
|
||||
DWORD MaxValueNameLen;
|
||||
DWORD MaxValueLen;
|
||||
DWORD SecurityDescriptorLen;
|
||||
|
||||
HKEY hKey = pEntry->hKey;
|
||||
LONG result = RegQueryInfoKey(pEntry->hKey, Class, &cClass, 0,
|
||||
&nSubKeys, &MaxSubKeyLen, &MaxClassLen, &ValueCount,
|
||||
&MaxValueNameLen, &MaxValueLen, &SecurityDescriptorLen,
|
||||
&LastWriteTime);
|
||||
if (result == ERROR_SUCCESS) {
|
||||
ptvdi->item.pszText = Class;
|
||||
ptvdi->item.cchTextMax = cClass;
|
||||
}
|
||||
}
|
||||
*/
|
||||
ptvdi->item.pszText = pEntry->szName;
|
||||
ptvdi->item.cchTextMax = lstrlen(pEntry->szName);
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL OnExpand(int flag, HTREEITEM* pti)
|
||||
BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW* pnmtv)
|
||||
{
|
||||
TRACE(_T("TreeWndProc(...) OnExpand()\n"));
|
||||
//TRACE("OnExpand(...) entry name: %s\n", entry->data.cFileName);
|
||||
/*
|
||||
TVE_COLLAPSE Collapses the list.
|
||||
TVE_COLLAPSERESET Collapses the list and removes the child items. The TVIS_EXPANDEDONCE state flag is reset. This flag must be used with the TVE_COLLAPSE flag.
|
||||
TVE_EXPAND Expands the list.
|
||||
TVE_EXPANDPARTIAL Version 4.70. Partially expands the list. In this state, the child items are visible and the parent item's plus symbol is displayed. This flag must be used in combination with the TVE_EXPAND flag.
|
||||
TVE_TOGGLE Collapses the list if it is expanded or expands it if it is collapsed.
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL OnExpanding(HWND hWnd, NMTREEVIEW* pnmtv)
|
||||
{
|
||||
static int expanding;
|
||||
HKEY hKey;
|
||||
LONG errCode;
|
||||
TCHAR keyPath[1000];
|
||||
int keyPathLen = 0;
|
||||
|
||||
Entry* entry = (Entry*)pnmtv->itemNew.lParam;
|
||||
TRACE(_T("TreeWndProc(...) OnExpanding() entry: %p\n"), entry);
|
||||
static int expanding;
|
||||
if (expanding) return FALSE;
|
||||
if (pnmtv->itemNew.state & TVIS_EXPANDEDONCE ) {
|
||||
return TRUE;
|
||||
}
|
||||
expanding = TRUE;
|
||||
if (entry) {
|
||||
errCode = RegOpenKeyEx(entry->hKey, NULL, 0, KEY_READ, &hKey);
|
||||
|
||||
// check if this is either the root or a subkey item...
|
||||
if ((HKEY)pnmtv->itemNew.lParam == NULL) {
|
||||
keyPath[0] = _T('\0');
|
||||
hKey = FindRegRoot(hwndTV, pnmtv->itemNew.hItem, keyPath, &keyPathLen, sizeof(keyPath));
|
||||
} else {
|
||||
hKey = (HKEY)pnmtv->itemNew.lParam;
|
||||
keyPath[0] = _T('\0');
|
||||
}
|
||||
|
||||
if (hKey != NULL) {
|
||||
HKEY hNewKey;
|
||||
LONG errCode = RegOpenKeyEx(hKey, keyPath, 0, KEY_READ, &hNewKey);
|
||||
if (errCode == ERROR_SUCCESS) {
|
||||
TCHAR Name[MAX_NAME_LEN];
|
||||
DWORD cName = MAX_NAME_LEN;
|
||||
FILETIME LastWriteTime;
|
||||
DWORD dwIndex = 0L;
|
||||
while (RegEnumKeyEx(hKey, dwIndex, Name, &cName, NULL, NULL, NULL, &LastWriteTime) == ERROR_SUCCESS) {
|
||||
Entry* pEntry = CreateEntry(entry, hKey, Name);
|
||||
pEntry->up = entry;
|
||||
pEntry->hKey = hKey;
|
||||
pEntry->bKey = TRUE;
|
||||
pEntry->level = 2;
|
||||
pEntry->hTreeItem = AddEntryToTree(hWnd, pEntry, NULL);
|
||||
ShowWindow(hwndTV, SW_HIDE);
|
||||
while (RegEnumKeyEx(hNewKey, dwIndex, Name, &cName, NULL, NULL, NULL, &LastWriteTime) == ERROR_SUCCESS) {
|
||||
DWORD dwCount = 0L;
|
||||
errCode = RegOpenKeyEx(hNewKey, Name, 0, KEY_READ, &hKey);
|
||||
if (errCode == ERROR_SUCCESS) {
|
||||
TCHAR SubName[MAX_NAME_LEN];
|
||||
DWORD cSubName = MAX_NAME_LEN;
|
||||
// if (RegEnumKeyEx(hKey, 0, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
|
||||
while (RegEnumKeyEx(hKey, dwCount, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
|
||||
++dwCount;
|
||||
}
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwCount);
|
||||
cName = MAX_NAME_LEN;
|
||||
++dwIndex;
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
ShowWindow(hwndTV, SW_SHOW);
|
||||
//UpdateStatus(hwndTV, pnmtv->itemNew.hItem);
|
||||
RegCloseKey(hNewKey);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
expanding = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
static BOOL OnSelChanged(NMTREEVIEW* pnmtv)
|
||||
{
|
||||
LPARAM parm = pnmtv->itemNew.lParam;
|
||||
ChildWnd* child = (ChildWnd*)pnmtv->itemNew.lParam;
|
||||
return TRUE;
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static WNDPROC g_orgTreeWndProc;
|
||||
|
||||
static LRESULT CALLBACK TreeWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// ChildWnd* child = (ChildWnd*)GetWindowLong(GetParent(hWnd), GWL_USERDATA);
|
||||
// ASSERT(child);
|
||||
|
||||
switch (message) {
|
||||
case WM_NOTIFY:
|
||||
switch (((LPNMHDR)lParam)->code) {
|
||||
case TVM_EXPAND:
|
||||
//return OnExpand((int)wParam, (HTREEITEM*)lParam);
|
||||
OnExpand((int)wParam, (HTREEITEM*)lParam);
|
||||
break;
|
||||
case TVN_GETDISPINFO:
|
||||
OnGetDispInfo((NMTVDISPINFO*)lParam);
|
||||
break;
|
||||
case TVN_ITEMEXPANDING:
|
||||
return OnExpanding(hWnd, (NMTREEVIEW*)lParam);
|
||||
break;
|
||||
// case TVN_SELCHANGED:
|
||||
// return OnSelChanged((NMTREEVIEW*)lParam);
|
||||
// break;
|
||||
#if 0
|
||||
case TVN_SINGLEEXPAND:
|
||||
TRACE("TreeWndProc(...) TVN_SINGLEEXPAND\n");
|
||||
//lpnmtv = (LPNMTREEVIEW)lParam;
|
||||
//return TVNRET_DEFAULT;
|
||||
// return TVNRET_SKIPOLD; // Skip default processing of the item being unselected.
|
||||
// return TVNRET_SKIPNEW; // Skip default processing of the item being selected.
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
// return 0;
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
if (wParam == VK_TAB) {
|
||||
//SetFocus(child->nFocusPanel ? child->left.hWnd: child->right.hWnd);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return CallWindowProc(g_orgTreeWndProc, hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
// CreateTreeView - creates a tree view control.
|
||||
// Returns the handle to the new control if successful, or NULL otherwise.
|
||||
// hwndParent - handle to the control's parent window.
|
||||
|
||||
HWND CreateTreeView(HWND hwndParent, int id, Root* pRoot)
|
||||
HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id)
|
||||
{
|
||||
RECT rcClient;
|
||||
HWND hwndTV;
|
||||
// Entry* entry = ;
|
||||
|
||||
// Get the dimensions of the parent window's client area, and create the tree view control.
|
||||
GetClientRect(hwndParent, &rcClient);
|
||||
|
@ -368,13 +254,10 @@ HWND CreateTreeView(HWND hwndParent, int id, Root* pRoot)
|
|||
0, 0, rcClient.right, rcClient.bottom,
|
||||
hwndParent, (HMENU)id, hInst, NULL);
|
||||
// Initialize the image list, and add items to the control.
|
||||
if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pRoot)) {
|
||||
if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName)) {
|
||||
DestroyWindow(hwndTV);
|
||||
return NULL;
|
||||
}
|
||||
SetWindowLong(hwndTV, GWL_USERDATA, (LPARAM)0);
|
||||
g_orgTreeWndProc = SubclassWindow(hwndTV, TreeWndProc);
|
||||
//SendMessage(hwndTV, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
|
||||
return hwndTV;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ extern "C" {
|
|||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
HWND CreateTreeView(HWND hwndParent, int id, Root* pRoot);
|
||||
HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id);
|
||||
BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Reference in a new issue