SOL9 Sample: RegistryViewer
|
1 Screenshot
2 Source code
/*
* RegistryViewer.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.18
#include <sol\ApplicationView.h>
#include <shellapi.h>
#include <sol\TreeView.h>
#include "resource.h"
namespace SOL {
// RegistryTree class
class RegistryTree :public TreeView {
public:
RegistryTree() :TreeView() { }
public:
RegistryTree(View* parent, const TCHAR* name, Args& args)
:TreeView(parent, name, args) { }
public:
virtual Boolean create(View* parent, const TCHAR* name, Args& args) {
return TreeView::create(parent, name, args);
}
public:
// Build a registry tree structure
void build(HTREEITEM parent, HKEY hkey, const TCHAR* subkeyName, int n)
{
HKEY hsubkey;
HTREEITEM item = (HTREEITEM)TVI_FIRST;
if (::RegOpenKey(hkey, subkeyName, &hsubkey) == ERROR_SUCCESS) {
TCHAR buff[MAX_PATH];
int indx = 0;
while(::RegEnumKey(hsubkey, indx, buff, CountOf(buff)) == ERROR_SUCCESS) { //2012/06/26
indx++;
if(*buff == '.') {
continue;
}
item = addItem(parent, item, buff);
build(item, hsubkey, buff, n+1);
}
::RegCloseKey(hsubkey);
}
}
};
// RegistryViewer UI application.
class RegistryViewer :public ApplicationView {
private:
RegistryTree treev;
public:
RegistryViewer(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name, args)
{
Args ar;
ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
ar.set(XmNstyle, (ulong)TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT);
treev.create(this, NULL, ar);
add(treev);
addCallback(XmNmenuCallback, ID_CLASSES_ROOT, this,
(Callback)&RegistryViewer::listUp, NULL);
addCallback(XmNmenuCallback, ID_CURRENT_USER, this,
(Callback)&RegistryViewer::listUp, NULL);
addCallback(XmNmenuCallback, ID_LOCAL_MACHINE, this,
(Callback)&RegistryViewer::listUp, NULL);
addCallback(XmNmenuCallback, ID_USERS, this,
(Callback)&RegistryViewer::listUp, NULL);
addCallback(XmNmenuCallback, ID_CURRENT_CONFIG, this,
(Callback)&RegistryViewer::listUp, NULL);
addCallback(XmNmenuCallback, ID_EXIT, this,
(Callback)&RegistryViewer::exit, NULL);
}
private:
void listUp(Action& action)
{
HKEY hkey;
Event& event = action.getEvent();
int menuID = event.getMenuId();
treev.deleteAllItems();
TCHAR* name = _T("");
HKEY regkey = NULL;
if (menuID == ID_CLASSES_ROOT) {
regkey = HKEY_CLASSES_ROOT;
name = _T("HKEY_CLASSES_ROOT");
}
if (menuID == ID_CURRENT_USER) {
regkey = HKEY_CURRENT_USER;
name = _T("HKEY_CURRENT_USER");
}
if (menuID == ID_LOCAL_MACHINE) {
regkey = HKEY_LOCAL_MACHINE;
name = _T("HKEY_LOCAL_MACHINE");
}
if (menuID == ID_USERS) {
regkey = HKEY_USERS;
name = _T("HKEY_USERS");
}
if (menuID == ID_CURRENT_CONFIG) {
regkey = HKEY_CURRENT_CONFIG;
name = _T("HKEY_CURRENT_CONFIG");
}
if (::RegOpenKey(regkey, NULL, &hkey) == ERROR_SUCCESS) {
TCHAR top[_MAX_PATH];
strcpy_s(top, CountOf(top), name);
HTREEITEM root = treev.addItem(NULL, TVI_ROOT, top);
treev.build(root, hkey, NULL, 0);
treev.sortChildren(root, TRUE);
treev.expand(root, TVE_EXPAND);
::RegCloseKey(hkey);
TCHAR caption[_MAX_PATH];
_stprintf_s(caption, CountOf(caption), _T("%s- RegistryViewer"), name);
setText(caption);
}
}
};
}
//////////////////////////////////////////
// Program Main
void Main(int argc, TCHAR** argv)
{
ModuleFileName module(argv[0]);
const TCHAR* name = module.getFileName();
try {
Application applet(name, argc, argv);
Args args;
RegistryViewer viewer(applet, name, args);
viewer.realize();
applet.run();
} catch (Exception& ex) {
caught(ex);
} catch (...) {
caught(UnknownException());
}
}
Last modified: 1 Feb 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.