Updated with cleanup of treeview module.

svn path=/trunk/; revision=3256
This commit is contained in:
Robert Dickenson 2002-07-18 18:16:42 +00:00
parent fb4e8713ea
commit 53dd918713
10 changed files with 236 additions and 334 deletions

View file

@ -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) static void draw_splitbar(HWND hWnd, int x)
{ {
RECT rt; RECT rt;
@ -58,8 +80,6 @@ static void draw_splitbar(HWND hWnd, int x)
ReleaseDC(hWnd, hdc); ReleaseDC(hWnd, hdc);
} }
#define _NO_EXTENSIONS
static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy) static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
{ {
HDWP hdwp = BeginDeferWindowPos(2); HDWP hdwp = BeginDeferWindowPos(2);
@ -137,8 +157,8 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams; pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
ASSERT(pChildWnd); ASSERT(pChildWnd);
pChildWnd->nSplitPos = 250; pChildWnd->nSplitPos = 250;
pChildWnd->hTreeWnd = CreateTreeView(hWnd, TREE_WINDOW, &pChildWnd->root); pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->root.path, TREE_WINDOW);
pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW, &pChildWnd->root); pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, &pChildWnd->root*/);
break; break;
case WM_COMMAND: case WM_COMMAND:
if (!_CmdWndProc(hWnd, message, wParam, lParam)) { if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
@ -170,16 +190,13 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
GetClientRect(hWnd, &rt); GetClientRect(hWnd, &rt);
if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) { if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
last_split = pChildWnd->nSplitPos; last_split = pChildWnd->nSplitPos;
#ifdef _NO_EXTENSIONS
draw_splitbar(hWnd, last_split); draw_splitbar(hWnd, last_split);
#endif
SetCapture(hWnd); SetCapture(hWnd);
} }
break;} break;}
case WM_LBUTTONUP: case WM_LBUTTONUP:
if (GetCapture() == hWnd) { if (GetCapture() == hWnd) {
#ifdef _NO_EXTENSIONS
RECT rt; RECT rt;
int x = LOWORD(lParam); int x = LOWORD(lParam);
draw_splitbar(hWnd, last_split); draw_splitbar(hWnd, last_split);
@ -187,26 +204,20 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
GetClientRect(hWnd, &rt); GetClientRect(hWnd, &rt);
pChildWnd->nSplitPos = x; pChildWnd->nSplitPos = x;
ResizeWnd(pChildWnd, rt.right, rt.bottom); ResizeWnd(pChildWnd, rt.right, rt.bottom);
#endif
ReleaseCapture(); ReleaseCapture();
} }
break; break;
#ifdef _NO_EXTENSIONS
case WM_CAPTURECHANGED: case WM_CAPTURECHANGED:
if (GetCapture()==hWnd && last_split>=0) if (GetCapture()==hWnd && last_split>=0)
draw_splitbar(hWnd, last_split); draw_splitbar(hWnd, last_split);
break; break;
#endif
case WM_KEYDOWN: case WM_KEYDOWN:
if (wParam == VK_ESCAPE) if (wParam == VK_ESCAPE)
if (GetCapture() == hWnd) { if (GetCapture() == hWnd) {
RECT rt; RECT rt;
#ifdef _NO_EXTENSIONS
draw_splitbar(hWnd, last_split); draw_splitbar(hWnd, last_split);
#else
pChildWnd->nSplitPos = last_split;
#endif
GetClientRect(hWnd, &rt); GetClientRect(hWnd, &rt);
ResizeWnd(pChildWnd, rt.right, rt.bottom); ResizeWnd(pChildWnd, rt.right, rt.bottom);
last_split = -1; last_split = -1;
@ -219,7 +230,6 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
if (GetCapture() == hWnd) { if (GetCapture() == hWnd) {
RECT rt; RECT rt;
int x = LOWORD(lParam); int x = LOWORD(lParam);
#ifdef _NO_EXTENSIONS
HDC hdc = GetDC(hWnd); HDC hdc = GetDC(hWnd);
GetClientRect(hWnd, &rt); GetClientRect(hWnd, &rt);
rt.left = last_split-SPLIT_WIDTH/2; 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; rt.right = x+SPLIT_WIDTH/2+1;
InvertRect(hdc, &rt); InvertRect(hdc, &rt);
ReleaseDC(hWnd, hdc); 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; 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: case WM_SETFOCUS:
// SetCurrentDirectory(szPath);
if (pChildWnd != NULL) { if (pChildWnd != NULL) {
SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd); 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: case WM_NOTIFY:
if ((int)wParam == TREE_WINDOW) { if ((int)wParam == TREE_WINDOW) {
if ((((LPNMHDR)lParam)->code) == TVN_SELCHANGED) { switch (((LPNMHDR)lParam)->code) {
Entry* entry = (Entry*)((NMTREEVIEW*)lParam)->itemNew.lParam; case TVN_ITEMEXPANDING:
if (entry != NULL) { return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
if (!entry->scanned) { case TVN_SELCHANGED:
//scan_entry(pChildWnd, entry); {
} else { 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);
}
// RefreshList(pChildWnd->hListWnd, entry); // RefreshList(pChildWnd->hListWnd, entry);
} break;
//RefreshList(pChildWnd->hListWnd, entry->down); default:
RefreshList(pChildWnd->hListWnd, entry);
}
}
if (!SendMessage(pChildWnd->hTreeWnd, message, wParam, lParam)) {
goto def; goto def;
} }
} } else
if ((int)wParam == LIST_WINDOW) { if ((int)wParam == LIST_WINDOW) {
if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) { if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) {
goto def; goto def;

View file

@ -66,20 +66,20 @@ static void resize_frame_rect(HWND hWnd, PRECT prect)
} }
*/ */
if (IsWindowVisible(hStatusBar)) { if (IsWindowVisible(hStatusBar)) {
SetupStatusBar(TRUE); SetupStatusBar(hWnd, TRUE);
GetClientRect(hStatusBar, &rt); GetClientRect(hStatusBar, &rt);
prect->bottom -= rt.bottom; prect->bottom -= rt.bottom;
} }
MoveWindow(hChildWnd, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE); 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) static void resize_frame(HWND hWnd, int cx, int cy)
{ {
RECT rect = {0, 0, cx, cy}; RECT rect = {0, 0, cx, cy};
resize_frame_rect(hWnd, &rect); resize_frame_rect(hWnd, &rect);
} }
*/
void resize_frame_client(HWND hWnd) void resize_frame_client(HWND hWnd)
{ {
RECT rect; RECT rect;
@ -102,19 +102,9 @@ static void OnEnterMenuLoop(HWND hWnd)
static void OnExitMenuLoop(HWND hWnd) static void OnExitMenuLoop(HWND hWnd)
{ {
RECT rc;
int nParts[3];
// TCHAR text[260];
bInMenuLoop = FALSE; bInMenuLoop = FALSE;
// Update the status bar pane sizes // Update the status bar pane sizes
GetClientRect(hWnd, &rc); SetupStatusBar(hWnd, TRUE);
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);
UpdateStatusBar(); UpdateStatusBar();
} }
@ -139,21 +129,16 @@ static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)str); SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)str);
} }
void SetupStatusBar(BOOL bResize) void SetupStatusBar(HWND hWnd, BOOL bResize)
{ {
int nParts[4]; RECT rc;
// int parts[] = {300, 500}; int nParts;
// SendMessage(Globals.hStatusBar, WM_SIZE, 0, 0); GetClientRect(hWnd, &rc);
// SendMessage(Globals.hStatusBar, SB_SETPARTS, 2, (LPARAM)&parts); nParts = rc.right;
// nParts = -1;
// Create the status bar panes
nParts[0] = 150;
nParts[1] = 220;
nParts[2] = 100;
nParts[3] = 100;
if (bResize) if (bResize)
SendMessage(hStatusBar, WM_SIZE, 0, 0); SendMessage(hStatusBar, WM_SIZE, 0, 0);
SendMessage(hStatusBar, SB_SETPARTS, 4, (long)nParts); SendMessage(hStatusBar, SB_SETPARTS, 1, (LPARAM)&nParts);
} }
void UpdateStatusBar(void) void UpdateStatusBar(void)
@ -163,10 +148,11 @@ void UpdateStatusBar(void)
// size = sizeof(text)/sizeof(TCHAR); // size = sizeof(text)/sizeof(TCHAR);
// GetUserName(text, &size); // 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); size = sizeof(text)/sizeof(TCHAR);
GetComputerName(text, &size); 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) static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)

View file

@ -34,7 +34,7 @@ extern "C" {
LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM);
void SetupStatusBar(BOOL bResize); void SetupStatusBar(HWND hWnd, BOOL bResize);
void UpdateStatusBar(void); void UpdateStatusBar(void);

View file

@ -130,7 +130,7 @@ static void CreateListColumns(HWND hWndListView)
static void OnGetDispInfo(NMLVDISPINFO* plvdi) static void OnGetDispInfo(NMLVDISPINFO* plvdi)
{ {
static TCHAR buffer[200]; // static TCHAR buffer[200];
// FILETIME LastWriteTime; // FILETIME LastWriteTime;
// TCHAR Class[MAX_NAME_LEN]; // 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 RECT rcClient; // dimensions of client area
HWND hwndLV; // handle to list view control 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, WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT,
0, 0, rcClient.right, rcClient.bottom, 0, 0, rcClient.right, rcClient.bottom,
hwndParent, (HMENU)id, hInst, NULL); hwndParent, (HMENU)id, hInst, NULL);
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.
/* /*
@ -317,10 +318,9 @@ HWND CreateListView(HWND hwndParent/*, Pane* pane*/, int id, Root* pRoot/*Entry*
return FALSE; return FALSE;
} }
*/ */
ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
CreateListColumns(hwndLV); CreateListColumns(hwndLV);
SetWindowLong(hwndLV, GWL_USERDATA, (LPARAM)pRoot); // SetWindowLong(hwndLV, GWL_USERDATA, (LPARAM)pRoot);
g_orgListWndProc = SubclassWindow(hwndLV, ListWndProc); g_orgListWndProc = SubclassWindow(hwndLV, ListWndProc);
//SendMessage(hwndLV, WM_SETFONT, (WPARAM)Globals.hFont, FALSE); //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; return hwndLV;
} }
void RefreshList(HWND hWnd, Entry* entry) void RefreshList(HWND hWnd/*, Entry* entry*/)
{ {
if (hWnd != NULL) { if (hWnd != NULL) {
ListView_DeleteAllItems(hWnd); ListView_DeleteAllItems(hWnd);
if (entry != NULL) { // if (entry != NULL) {
TRACE("RefreshList(...) entry name: %p\n", entry); // TRACE("RefreshList(...) entry name: %p\n", entry);
InsertListEntries(hWnd, entry, -1); // InsertListEntries(hWnd, entry, -1);
} // }
} }
} }

View file

@ -32,8 +32,10 @@ extern "C" {
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
HWND CreateListView(HWND hwndParent, int id, Root* pRoot); //HWND CreateListView(HWND hwndParent, int id, Root* pRoot);
void RefreshList(HWND hWnd, Entry* entry); //void RefreshList(HWND hWnd, Entry* entry);
HWND CreateListView(HWND hwndParent, int id);
void RefreshList(HWND hWnd);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -101,7 +101,8 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED) 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; WNDCLASSEX wcex;
@ -143,11 +144,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
_T(""), hFrameWnd, STATUS_WINDOW); _T(""), hFrameWnd, STATUS_WINDOW);
if (hStatusBar) { if (hStatusBar) {
// Create the status bar panes // Create the status bar panes
int nParts[3]; SetupStatusBar(hFrameWnd, FALSE);
nParts[0] = 100;
nParts[1] = 210;
nParts[2] = 400;
SendMessage(hStatusBar, SB_SETPARTS, 3, (long)nParts);
CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED); CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
} }
ShowWindow(hFrameWnd, nCmdShow); ShowWindow(hFrameWnd, nCmdShow);

View file

@ -32,7 +32,7 @@ extern "C" {
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include "resource.h" #include "resource.h"
#include "regproc.h" //#include "regproc.h"
#define STATUS_WINDOW 2001 #define STATUS_WINDOW 2001
@ -45,6 +45,8 @@ extern "C" {
#define MAX_NAME_LEN 500 #define MAX_NAME_LEN 500
//#include "entries.h"
//#if 0
typedef struct _Entry { typedef struct _Entry {
struct _Entry* next; struct _Entry* next;
struct _Entry* down; struct _Entry* down;
@ -75,7 +77,7 @@ typedef struct {
int nSplitPos; int nSplitPos;
Root root; Root root;
} ChildWnd; } ChildWnd;
//#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Global Variables: // Global Variables:

View file

@ -39,9 +39,9 @@ IDI_SMALL ICON DISCARDABLE "res/small.ico"
// Bitmap // Bitmap
// //
IDB_OPEN_FILE BITMAP DISCARDABLE "res/folder1.bmp" IDB_OPEN_FILE BITMAP DISCARDABLE "res/folder3.bmp"
IDB_CLOSED_FILE BITMAP DISCARDABLE "res/folder2.bmp" IDB_CLOSED_FILE BITMAP DISCARDABLE "res/folder1.bmp"
IDB_ROOT BITMAP DISCARDABLE "res/folder3.bmp" IDB_ROOT BITMAP DISCARDABLE "res/folder2.bmp"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
@ -167,6 +167,49 @@ END
#endif // APSTUDIO_INVOKED #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 // String Table

View file

@ -34,18 +34,13 @@
#include <stdio.h> #include <stdio.h>
#endif #endif
#include <windowsx.h> //#include <windowsx.h>
#include <assert.h>
#define ASSERT assert
#include "main.h" #include "main.h"
#include "treeview.h" #include "treeview.h"
#include "trace.h"
// Global variables and constants // Global variables and constants
// Image_Open, Image_Closed, and Image_Root - integer variables for // Image_Open, Image_Closed, and Image_Root - integer variables for indexes of the images.
// indexes of the images.
// CX_BITMAP and CY_BITMAP - width and height of an icon. // CX_BITMAP and CY_BITMAP - width and height of an icon.
// NUM_BITMAPS - number of bitmaps to add to the image list. // NUM_BITMAPS - number of bitmaps to add to the image list.
int Image_Open; int Image_Open;
@ -57,109 +52,92 @@ int Image_Root;
#define NUM_BITMAPS 3 #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; HTREEITEM hItem = 0;
TVITEM tvi; TVITEM tvi;
TVINSERTSTRUCT tvins; 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; 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.pszText = label;
tvi.cchTextMax = _tcslen(label); tvi.cchTextMax = lstrlen(tvi.pszText);
} else { tvi.iImage = Image_Closed;
tvi.pszText = LPSTR_TEXTCALLBACK; tvi.iSelectedImage = Image_Open;
tvi.cchTextMax = 0; tvi.cChildren = dwChildren;
} tvi.lParam = (LPARAM)hKey;
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;
tvins.item = tvi; tvins.item = tvi;
tvins.hInsertAfter = hPrev; if (hKey) tvins.hInsertAfter = (HTREEITEM)TVI_LAST;
else tvins.hInsertAfter = (HTREEITEM)TVI_SORT;
// Set the parent item based on the specified level. tvins.hParent = hParent;
if (entry->level == 0) { hItem = (HTREEITEM)SendMessage(hwndTV, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
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;
return hItem; return hItem;
} }
static Entry* CreateEntry(Entry* pParentEntry, HKEY hKey, LPCTSTR szKeyName)
static BOOL InitTreeViewItems(HWND hwndTV, LPTSTR pHostName)
{ {
Entry* pEntry = NULL; TVITEM tvi;
TVINSERTSTRUCT tvins;
HTREEITEM hRoot;
pEntry = malloc(sizeof(Entry)); tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
memset(pEntry, 0, sizeof(Entry)); // Set the text of the item.
//pEntry->up = pParentEntry; tvi.pszText = pHostName;
pEntry->level = 1; tvi.cchTextMax = lstrlen(tvi.pszText);
pEntry->hKey = hKey; // Assume the item is not a parent item, so give it an image.
_tcsncpy(pEntry->szName, szKeyName, MAX_NAME_LEN); tvi.iImage = Image_Root;
// pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, szKeyName); tvi.iSelectedImage = Image_Root;
return pEntry; 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);
static BOOL InitTreeViewItems(HWND hwndTV, Root* pRoot/*LPCTSTR pHostName*/) AddEntryToTree(hwndTV, hRoot, _T("HKEY_CLASSES_ROOT"), HKEY_CLASSES_ROOT, 1);
{ AddEntryToTree(hwndTV, hRoot, _T("HKEY_CURRENT_USER"), HKEY_CURRENT_USER, 1);
// HKEY hKey; AddEntryToTree(hwndTV, hRoot, _T("HKEY_LOCAL_MACHINE"), HKEY_LOCAL_MACHINE, 1);
// LONG errCode; AddEntryToTree(hwndTV, hRoot, _T("HKEY_USERS"), HKEY_USERS, 1);
Entry* pEntry = &pRoot->entry; AddEntryToTree(hwndTV, hRoot, _T("HKEY_CURRENT_CONFIG"), HKEY_CURRENT_CONFIG, 1);
HTREEITEM hRootItem;
// TCHAR* pHostName = _T("My Computer");
// HTREEITEM hRootItem = AddItemToTree(hwndTV, pHostName, 1);
// pEntry = malloc(sizeof(Entry));
// memset(pEntry, 0, sizeof(Entry));
pEntry->level = 0;
pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, pRoot->path);
hRootItem = pEntry->hTreeItem;
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; return TRUE;
} }
@ -201,165 +179,73 @@ static BOOL InitTreeViewImageLists(HWND hwndTV)
return TRUE; return TRUE;
} }
#ifndef _MSC_VER BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW* pnmtv)
#define NMTVDISPINFO TV_DISPINFO
#define NMTVDISPINFO TV_DISPINFO
#endif
static void OnGetDispInfo(NMTVDISPINFO* ptvdi)
{ {
Entry* pEntry = (Entry*)ptvdi->item.lParam; HKEY hKey;
ASSERT(pEntry); TCHAR keyPath[1000];
int keyPathLen = 0;
if (ptvdi->item.mask & TVIF_CHILDREN ) { static int expanding;
ptvdi->item.cChildren = 5; if (expanding) return FALSE;
} if (pnmtv->itemNew.state & TVIS_EXPANDEDONCE ) {
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)
{
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; return TRUE;
} }
static BOOL OnExpanding(HWND hWnd, NMTREEVIEW* pnmtv)
{
static int expanding;
HKEY hKey;
LONG errCode;
Entry* entry = (Entry*)pnmtv->itemNew.lParam;
TRACE(_T("TreeWndProc(...) OnExpanding() entry: %p\n"), entry);
if (expanding) return FALSE;
expanding = 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) { if (errCode == ERROR_SUCCESS) {
TCHAR Name[MAX_NAME_LEN]; TCHAR Name[MAX_NAME_LEN];
DWORD cName = MAX_NAME_LEN; DWORD cName = MAX_NAME_LEN;
FILETIME LastWriteTime; FILETIME LastWriteTime;
DWORD dwIndex = 0L; DWORD dwIndex = 0L;
while (RegEnumKeyEx(hKey, dwIndex, Name, &cName, NULL, NULL, NULL, &LastWriteTime) == ERROR_SUCCESS) { ShowWindow(hwndTV, SW_HIDE);
Entry* pEntry = CreateEntry(entry, hKey, Name); while (RegEnumKeyEx(hNewKey, dwIndex, Name, &cName, NULL, NULL, NULL, &LastWriteTime) == ERROR_SUCCESS) {
pEntry->up = entry; DWORD dwCount = 0L;
pEntry->hKey = hKey; errCode = RegOpenKeyEx(hNewKey, Name, 0, KEY_READ, &hKey);
pEntry->bKey = TRUE; if (errCode == ERROR_SUCCESS) {
pEntry->level = 2; TCHAR SubName[MAX_NAME_LEN];
pEntry->hTreeItem = AddEntryToTree(hWnd, pEntry, NULL); 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; cName = MAX_NAME_LEN;
++dwIndex; ++dwIndex;
} }
RegCloseKey(hKey); ShowWindow(hwndTV, SW_SHOW);
//UpdateStatus(hwndTV, pnmtv->itemNew.hItem);
RegCloseKey(hNewKey);
} }
} else {
} }
expanding = FALSE; expanding = FALSE;
return TRUE; 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. // CreateTreeView - creates a tree view control.
// Returns the handle to the new control if successful, or NULL otherwise. // Returns the handle to the new control if successful, or NULL otherwise.
// hwndParent - handle to the control's parent window. // 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; RECT rcClient;
HWND hwndTV; HWND hwndTV;
// Entry* entry = ;
// Get the dimensions of the parent window's client area, and create the tree view control. // Get the dimensions of the parent window's client area, and create the tree view control.
GetClientRect(hwndParent, &rcClient); GetClientRect(hwndParent, &rcClient);
@ -368,13 +254,10 @@ HWND CreateTreeView(HWND hwndParent, int id, Root* pRoot)
0, 0, rcClient.right, rcClient.bottom, 0, 0, rcClient.right, rcClient.bottom,
hwndParent, (HMENU)id, hInst, NULL); hwndParent, (HMENU)id, hInst, NULL);
// Initialize the image list, and add items to the control. // Initialize the image list, and add items to the control.
if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pRoot)) { if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName)) {
DestroyWindow(hwndTV); DestroyWindow(hwndTV);
return NULL; return NULL;
} }
SetWindowLong(hwndTV, GWL_USERDATA, (LPARAM)0);
g_orgTreeWndProc = SubclassWindow(hwndTV, TreeWndProc);
//SendMessage(hwndTV, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
return hwndTV; return hwndTV;
} }

View file

@ -32,7 +32,8 @@ extern "C" {
#endif // _MSC_VER > 1000 #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 #ifdef __cplusplus