📄 portmon.cpp
字号:
// PortMon.cpp : 定义应用程序的类行为。
//
#include "stdafx.h"
#include "PortMon.h"
#include "MainFrm.h"
#include "sinstance.h"
#include "PortMonDoc.h"
#include "PortMonView.h"
#include ".\portmon.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CPortMonApp
BEGIN_MESSAGE_MAP(CPortMonApp, CWinApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// 基于文件的标准文档命令
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
// CPortMonApp 构造
CPortMonApp::CPortMonApp() : CBCGPWorkspace( TRUE )
, m_Registry(FALSE, FALSE)
, m_bShowNetProc(TRUE)
, m_nIntervals(3)
, m_bAnimation(TRUE)
, m_bTrayMode(TRUE)
{
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的一个 CPortMonApp 对象
CPortMonApp theApp;
// CPortMonApp 初始化
BOOL CPortMonApp::InitInstance()
{
// 运行实例检查
CInstanceChecker instChecker(AfxGetAppName());
if (instChecker.InstanceIsRunning())
{
instChecker.ActivatePrevInstance();
return FALSE;
}
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControls()。否则,将无法创建窗口。
InitCommonControls();
CWinApp::InitInstance();
// 初始化 OLE 库
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// 标准初始化
//InitMouseManager();
// restore settings from registry
BOOL bExisted = m_Registry.Open( "Software\\Scaton Software\\PortMon\\Settings" );
if( bExisted )
{
m_Registry.Read( "ShowNetProc", m_bShowNetProc );
m_Registry.Read( "Intervals", m_nIntervals );
m_Registry.Read( "Animation", m_bAnimation );
m_Registry.Read( "TrayMode", m_bTrayMode );
}
else
{
if( !m_Registry.CreateKey( "Software\\Scaton Software\\PortMon\\Settings" ) )
{
return FALSE;
}
}
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
SetRegistryKey(_T("Scaton Software"));
SetRegistryBase( _T("Settings") );
LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU)
// 加载本地化资源库
m_hResInst = LoadLibrary("BCGCBProCHS.dll");
BCGCBProSetResourceHandle(m_hResInst);
// 注册应用程序的文档模板。文档模板
// 将用作文档、框架窗口和视图之间的连接
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CPortMonDoc),
RUNTIME_CLASS(CMainFrame), // 主 SDI 框架窗口
RUNTIME_CLASS(CPortMonView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
// 分析标准外壳命令、DDE、打开文件操作的命令行
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// 调度在命令行中指定的命令。如果
// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// save handle of this instance main window
instChecker.SaveHwnd(m_pMainWnd->GetSafeHwnd());
// 唯一的一个窗口已初始化,因此显示它并对其进行更新
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
// 仅当存在后缀时才调用 DragAcceptFiles,
// 在 SDI 应用程序中,这应在 ProcessShellCommand 之后发生
return TRUE;
}
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
public:
CBCGPURLLinkButton m_btLink;
virtual BOOL OnInitDialog();
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BTNLINK, m_btLink);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// 用于运行对话框的应用程序命令
void CPortMonApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
// CPortMonApp 消息处理程序
int CPortMonApp::ExitInstance()
{
// TODO: 在此添加专用代码和/或调用基类
m_Registry.Write( "ShowNetProc", m_bShowNetProc );
m_Registry.Write( "Intervals", m_nIntervals );
m_Registry.Write( "Animation", m_bAnimation );
m_Registry.Write( "TrayMode", m_bTrayMode );
BCGCBProCleanUp();
if( m_hResInst )
{
FreeLibrary(m_hResInst);
}
return __super::ExitInstance();
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
m_btLink.SetURL( _T("http://www.6663.net") );
m_btLink.SetTooltip (_T("软件更新"));
m_btLink.SizeToContent ();
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -