SOL9 Sample: SolNetFwRuleViewer
|
1 Screenshot
2 Source code
/*
* SolNetFwRuleViewer.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// 2012/09/27
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\ole\HTMLView.h>
#include <sol\FileVersionDialog.h>
#include <sol\Locale.h>
#include <sol\com\ApartmentThreadedModel.h>
#include <sol\com\MultiThreadedModel.h>
#include <sol\netfw\NetFwMgr.h>
#include <sol\netfw\NetFwPolicy2.h>
#include <sol\netfw\NetFwRules.h>
//#include <sol\netfw\NetFwPolicy.h>
//#include <sol\netfw\NetFwProfile.h>
#include <sol\FileWriter.h>
#include <sol\Locale.h>
#include <sol\WString.h>
#include "resource.h"
namespace SOL {
#define WM_REFRESH (WM_USER+2012)
/**
* class SolNetFwRuleViewer
*/
class SolNetFwRuleViewer :public ApplicationView {
private:
HTMLView htmlView;
FileVersionDialog fileVersion;
public:
/**
* Constructor
*/
SolNetFwRuleViewer(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name,
args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1))
.set(XmNstyle, WS_CLIPCHILDREN) )
{
Args ar;
ar.set(XmNstyle, WS_CHILD|WS_VISIBLE);
htmlView.create(this, _T(""), ar);
fileVersion.create(this);
addEventHandler(WM_KEYDOWN, this, (Handler)&SolNetFwRuleViewer::keyDown, NULL);
addCallback(XmNmenuCallback, IDM_REFRESH, this, (Callback)&SolNetFwRuleViewer::refresh, NULL);
addCallback(XmNmenuCallback, IDM_EXIT, this, (Callback)&SolNetFwRuleViewer::exit, NULL);
addCallback(XmNmenuCallback, IDM_VERSION, this, (Callback)&SolNetFwRuleViewer::version, NULL);
addEventHandler(WM_SIZE, this, (Handler)&SolNetFwRuleViewer::size, NULL);
addEventHandler(WM_CLOSE, this, (Handler)&SolNetFwRuleViewer::close, NULL);
addEventHandler(WM_BROWSER_DOCUMENTCOMPLETE, this, (Handler)&SolNetFwRuleViewer::complete, NULL);
addEventHandler(WM_REFRESH, this, (Handler)&SolNetFwRuleViewer::refresh, NULL);
restorePlacement();
}
public:
long refresh(Event& event)
{
Action action;
refresh(action);
return 0;
}
public:
void refresh(Action& action)
{
try {
TCHAR user[_MAX_PATH];
TCHAR xmlFileName[_MAX_PATH];
if(GetEnvironmentVariable(_T("UserProfile"), user, CountOf(user))) {
_stprintf_s(xmlFileName, CountOf(xmlFileName), _T("%s\\NetFwRule.xml"), user);
} else {
throw -1;
}
FileWriter writer(xmlFileName);
writer.write(L"<?xml version='1.0' ?>\n");
writer.write(L"<NetFwApplication name='%s'>\n", L"SolNetFwRuleViewer");
SOL::NetFwPolicy2 policy2;
NetFwRules rules = policy2.getRules();
writer.write(L"<NetFwPolicy2>\n");
rules.write(writer);
writer.write(L"</NetFwPolicy2>\n");
writer.write(L"</NetFwApplication>\n");
writer.close();
navigate(xmlFileName);
} catch (Exception& ) {
//ex.printf();
} catch (HRESULT ) {
//_tprintf(_T("Exception: HRESULT=%x\n"), hr);
}
}
public:
/**
* WM_KEYDOWN event handler.
*/
long keyDown(Event& event)
{
MSG msg;
msg.message = event.getMessage();
msg.lParam = event.getLParam();
msg.wParam = event.getWParam();
//Call HTMLView::transateAccelator
htmlView.translateAccelator(&msg);
return 0;
}
public:
/**
* WM_SIZE event handler.
*/
long size(Event& event)
{
LPARAM l = event.getLParam();
htmlView.reshape(0, 0, LOWORD(l), HIWORD(l));
return 0;
}
public:
/**
* Event handler for a user-defined WM_BROWSER_DOCUMENTCOMPLETE from SOL::BrowserEvent class.
*/
long complete(Event& event)
{
//Do nothing here.
return 0;
}
public:
// File menu [Version] callback.
void version(Action& action)
{
fileVersion.popupAt(action);
}
public:
long close(Event& event)
{
savePlacement();
return defaultProc(event);
}
public:
void navigate(const TCHAR* url)
{
try {
htmlView.navigate(url);
TCHAR caption[1024];
_stprintf_s(caption, CountOf(caption), _T("%s - SolNetFwRuleViewer"), (const TCHAR*)url);
setText(caption);
} catch (...) {
}
}
};
}
//////////////////////////////////////
// SolNetFwRuleViewer
// Program entry point.
void Main(int argc, TCHAR** argv)
{
ModuleFileName module(argv[0]);
const TCHAR* name = module.getFileName();
try {
Locale locale;
ApartmentThreadedModel model;
Application applet(name, argc, argv);
Args args;
args.set(XmNclassStyle, CS_DBLCLKS);
SolNetFwRuleViewer browser(applet, name, args);
browser.realize();
browser.post(WM_REFRESH);
applet.run();
} catch (Exception& ex) {
caught(ex);
} catch (...) {
caught(UnknownException());
}
}
Last modified: 1 Feb 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.