Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • T TrafficMonitor
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 813
    • Issues 813
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 3
    • Merge requests 3
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • zhongyang219
  • TrafficMonitor
  • Wiki
  • 插件开发指南

插件开发指南 · Changes

Page history
插件开发指南更新 authored Nov 21, 2021 by zhongyang219's avatar zhongyang219
Hide whitespace changes
Inline Side-by-side
插件开发指南.md
View page @ 145e2227
......@@ -6,15 +6,11 @@
# 准备工作
要为TrafficMonitor开发插件,首先你必须要懂得如果编写C++程序,因为TrafficMonitor是用C++语言开发的,插件也必须使用C++语言编写。
同时你还必须具备一种Windows平台下支持C++的GUI技术,例如MFC、Qt等。
要为TrafficMonitor开发插件,首先你必须要懂得如果编写C++程序,因为TrafficMonitor的插件提供的是C++的指接口。
# 开发步骤
* 一切准备就绪后,你需要通过你的IDE创建一个**动态库**项目。
* 然后将[`PluginInterface.h`](https://github.com/zhongyang219/TrafficMonitor/blob/master/include/PluginInterface.h)这个C++头文件添加到你的项目中。这个文件非常重要,里面包含插件系统所有接口类的定义。
* 一切准备就绪后,你首先需要创建一个**动态库**项目。然后将[`PluginInterface.h`](https://github.com/zhongyang219/TrafficMonitor/blob/master/include/PluginInterface.h)这个C++头文件添加到你的项目中。这个文件非常重要,里面包含插件系统所有接口类的定义。
* 在你的项目中导出一个名为`TMPluginGetInstance`的函数,函数签名如下:
......@@ -36,11 +32,17 @@
#ifdef __cplusplus
}
#endif
/////////////////////////////////////////////////////////////
ITMPlugin* TMPluginGetInstance()
{
return &CPluginDemo::Instance();
}
```
* 编写一个类,实现`ITMPlugin`接口。此类的对象在内存中仅存在一个,由TMPluginGetInstance函数返回。
* 编写一个类,继承自`ITMPlugin`接口,并实现接口的纯虚函数。此类的对象在内存中仅存在一个,由TMPluginGetInstance函数返回。
* 根据你的插件提供的显示项目,编写对应的类,并实现`IPluginItem`接口。类的对象一般可作为`ITMPlugin`派生类的成员变量。例如,你的插件将提供时间和日期两个显示项目,则你需要编写两个类,它们都派生自`IPluginItem`接口,并将这两个类的对象作为`ITMPlugin`派生类的成员。
* 根据你的插件提供的显示项目,编写对应的类,继承自`IPluginItem`接口,并实现接口的纯虚函数。类的对象一般可作为`ITMPlugin`派生类的成员变量。例如,你的插件将提供时间和日期两个显示项目,则你需要编写两个类,它们都派生自`IPluginItem`接口,并将这两个类的对象作为`ITMPlugin`派生类的成员。
* 编译你的项目,将生成的dll文件复制到TrafficMonitor主程序所在目录下的`plugins`目录下,启动TrafficMonitor,插件将自动被加载。
......@@ -283,3 +285,21 @@ virtual void DrawItem(void* hDC, int x, int y, int w, int h, bool dark_mode)
是否为深色模式。
## 示例代码
### CPluginDemo类(继承自ITMPlugin接口)
[PluginDemo.h](https://github.com/zhongyang219/TrafficMonitor/blob/master/PluginDemo/PluginDemo.h)
[PluginDemo.cpp](https://github.com/zhongyang219/TrafficMonitor/blob/master/PluginDemo/PluginDemo.cpp)
### CPluginSystemTime类、CPluginSystemTime类(继承自IPluginItem接口)
[PluginSystemTime.h](https://github.com/zhongyang219/TrafficMonitor/blob/master/PluginDemo/PluginSystemTime.h)
[PluginSystemTime.cpp](https://github.com/zhongyang219/TrafficMonitor/blob/master/PluginDemo/PluginSystemTime.cpp)
[PluginSystemDate.h](https://github.com/zhongyang219/TrafficMonitor/blob/master/PluginDemo/PluginSystemDate.h)
[PluginSystemDate.cpp ](https://github.com/zhongyang219/TrafficMonitor/blob/master/PluginDemo/PluginSystemDate.cpp)
Clone repository

TrafficMonitor Wiki 导航

首页

  • 主窗口
  • 任务栏窗口
  • 右键菜单
  • 选项设置
    • 主窗口设置
    • 任务栏窗口设置
    • 常规设置
  • 硬件监控功能
  • 选择监控的网络连接
  • 更换皮肤功能
  • 通知区图标
  • 历史流量统计
  • 配置和数据文件
  • 插件开发指南

更新日志 - Update Log

常见问题 - Frequently Asked Questions

已知问题