Skip to content

Commit 73c9902

Browse files
committed
插件接口更新,增加ITMPlugin::OnInitialize函数,新增ITrafficMonitor接口
1 parent 26b76dd commit 73c9902

File tree

8 files changed

+162
-4
lines changed

8 files changed

+162
-4
lines changed

TrafficMonitor/TrafficMonitor.cpp

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ bool CTrafficMonitorApp::DPIFromRect(const RECT& rect, UINT* out_dpi_x, UINT* ou
13161316
return hr == S_OK;
13171317
}
13181318

1319-
COLORREF CTrafficMonitorApp::GetThemeColor() const
1319+
unsigned int CTrafficMonitorApp::GetThemeColor() const
13201320
{
13211321
return m_theme_color;
13221322
}
@@ -1386,3 +1386,64 @@ int CTrafficMonitorApp::ExitInstance()
13861386

13871387
return CWinApp::ExitInstance();
13881388
}
1389+
1390+
double CTrafficMonitorApp::GetMonitorData(MonitorItem item)
1391+
{
1392+
switch (item)
1393+
{
1394+
case MI_UP: return m_out_speed;
1395+
case MI_DOWN: return m_in_speed;
1396+
case MI_CPU: return m_cpu_usage;
1397+
case MI_MEMORY: return m_memory_usage;
1398+
case MI_GPU_USAGE: return m_gpu_usage;
1399+
case MI_CPU_TEMP: return m_cpu_temperature;
1400+
case MI_GPU_TEMP: return m_gpu_temperature;
1401+
case MI_HDD_TEMP: return m_hdd_temperature;
1402+
case MI_MAIN_BOARD_TEMP: return m_main_board_temperature;
1403+
case MI_HDD_USAGE: return m_hdd_usage;
1404+
case MI_CPU_FREQ: return m_cpu_freq;
1405+
case MI_TODAY_UP_TRAFFIC: return m_today_up_traffic;
1406+
case MI_TODAY_DOWN_TRAFFIC: return m_today_down_traffic;
1407+
}
1408+
return 0.0;
1409+
}
1410+
1411+
void CTrafficMonitorApp::ShowNotifyMessage(const wchar_t* strMsg)
1412+
{
1413+
CTrafficMonitorDlg* pMainWnd = dynamic_cast<CTrafficMonitorDlg*>(m_pMainWnd);
1414+
if (pMainWnd != nullptr)
1415+
{
1416+
pMainWnd->ShowNotifyTip(CCommon::LoadText(IDS_TRAFFICMONITOR_PLUGIN_NITIFICATION), strMsg);
1417+
}
1418+
}
1419+
1420+
unsigned short CTrafficMonitorApp::GetLanguageId() const
1421+
{
1422+
return m_general_data.language;
1423+
}
1424+
1425+
const wchar_t* CTrafficMonitorApp::GetConfigDir() const
1426+
{
1427+
static std::wstring config_dir;
1428+
config_dir = m_config_dir;
1429+
config_dir += L"plugins\\";
1430+
return config_dir.c_str();
1431+
}
1432+
1433+
int CTrafficMonitorApp::GetDPI(DPIType type) const
1434+
{
1435+
CTrafficMonitorDlg* pMainWnd = dynamic_cast<CTrafficMonitorDlg*>(m_pMainWnd);
1436+
switch (type)
1437+
{
1438+
case DPI_MAIN_WND:
1439+
return m_dpi;
1440+
case DPI_TASKBAR:
1441+
if (pMainWnd != nullptr)
1442+
{
1443+
if (pMainWnd->IsTaskbarWndValid())
1444+
return pMainWnd->GetTaskbarWindow()->GetDPI();
1445+
}
1446+
return m_dpi;
1447+
}
1448+
return 0;
1449+
}

TrafficMonitor/TrafficMonitor.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
#include "DllFunctions.h"
2222
#include "StrTable.h"
2323
#include "PluginUpdateHelper.h"
24+
#include "PluginInterface.h"
2425

2526
// CTrafficMonitorApp:
2627
// 有关此类的实现,请参阅 TrafficMonitor.cpp
2728
//
2829

2930

30-
class CTrafficMonitorApp : public CWinApp
31+
class CTrafficMonitorApp : public CWinApp, public ITrafficMonitor
3132
{
3233
public:
3334
//各种路径
@@ -168,7 +169,7 @@ class CTrafficMonitorApp : public CWinApp
168169

169170
bool DPIFromRect(const RECT& rect, UINT* out_dpi_x, UINT* out_dpi_y);
170171

171-
COLORREF GetThemeColor() const;
172+
virtual unsigned int GetThemeColor() const override;
172173
void SetThemeColor(COLORREF color);
173174

174175
private:
@@ -197,6 +198,13 @@ class CTrafficMonitorApp : public CWinApp
197198
afx_msg void OnFrequentyAskedQuestions();
198199
afx_msg void OnUpdateLog();
199200
virtual int ExitInstance();
201+
202+
// 通过 ITrafficMonitor 继承
203+
double GetMonitorData(MonitorItem item) override;
204+
void ShowNotifyMessage(const wchar_t* strMsg) override;
205+
unsigned short GetLanguageId() const override;
206+
const wchar_t* GetConfigDir() const override;
207+
int GetDPI(DPIType type) const override;
200208
};
201209

202210
extern CTrafficMonitorApp theApp;

TrafficMonitor/TrafficMonitorDlg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ class CTrafficMonitorDlg : public CDialog
156156

157157
void AddNotifyIcon(); //添加通知区图标
158158
void DeleteNotifyIcon();
159+
public:
159160
void ShowNotifyTip(const wchar_t* title, const wchar_t* message); //显示通知区提示
161+
protected:
160162
void UpdateNotifyIconTip(); //更新通知区图标的鼠标提示
161163

162164
void SaveHistoryTraffic();
@@ -173,7 +175,9 @@ class CTrafficMonitorDlg : public CDialog
173175
void LoadBackGroundImage();
174176
void SetTextFont();
175177

178+
public:
176179
bool IsTaskbarWndValid() const;
180+
protected:
177181

178182
void TaskbarShowHideItem(DisplayItem type);
179183

TrafficMonitor/language.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
#define IDS_SECONDARY_DISPLAY L"IDS_SECONDARY_DISPLAY"
217217
#define IDS_RESTORE_FROM_SLEEP_LOG L"IDS_RESTORE_FROM_SLEEP_LOG"
218218
#define IDS_PLUGIN_NEW_VERSION_INFO L"IDS_PLUGIN_NEW_VERSION_INFO"
219+
#define IDS_TRAFFICMONITOR_PLUGIN_NITIFICATION L"IDS_TRAFFICMONITOR_PLUGIN_NITIFICATION"
219220

220221
#define TXT_OK L"TXT_OK"
221222
#define TXT_CANCEL L"TXT_CANCEL"

TrafficMonitor/language/English.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ IDS_PRIMARY_DISPLAY = "Primary display"
220220
IDS_SECONDARY_DISPLAY = "Secondary display <%1%>"
221221
IDS_RESTORE_FROM_SLEEP_LOG = "The system has been restored from hibernation, the connection has been reinitialized. (<%1%> times has been reinitialized.)"
222222
IDS_PLUGIN_NEW_VERSION_INFO = "Update available, latest version: <%1%>"
223+
IDS_TRAFFICMONITOR_PLUGIN_NITIFICATION = "TrafficMonitor Plugin Notification"
223224

224225
TXT_OK = "OK"
225226
TXT_CANCEL = "Cancel"

TrafficMonitor/language/Simplified_Chinese.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ IDS_PRIMARY_DISPLAY = "主显示器"
220220
IDS_SECONDARY_DISPLAY = "副显示器 <%1%>"
221221
IDS_RESTORE_FROM_SLEEP_LOG = "系统已从休眠状态恢复,已重新初始化连接。(已重新初始化<%1%>次)"
222222
IDS_PLUGIN_NEW_VERSION_INFO = "有更新,最新版本:<%1%>"
223+
IDS_TRAFFICMONITOR_PLUGIN_NITIFICATION = "TrafficMonitor 插件通知"
223224

224225
TXT_OK = "确定"
225226
TXT_CANCEL = "取消"

TrafficMonitor/language/Traditional_Chinese.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ IDS_PRIMARY_DISPLAY = "主顯示器"
220220
IDS_SECONDARY_DISPLAY = "副顯示器 <%1%>"
221221
IDS_RESTORE_FROM_SLEEP_LOG = "系統已從休眠狀態恢復,已重新初始化連線。(已重新初始化<%1%>次)"
222222
IDS_PLUGIN_NEW_VERSION_INFO = "有更新,最新版本:<%1%>"
223+
IDS_TRAFFICMONITOR_PLUGIN_NITIFICATION = "TrafficMonitor 外掛通知"
223224

224225
TXT_OK = "確定"
225226
TXT_CANCEL = "取消"

include/PluginInterface.h

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ class IPluginItem
151151
virtual float GetResourceUsageGraphValue() const { return 0.0; }
152152
};
153153

154+
class ITrafficMonitor;
154155

156+
///////////////////////////////////////////////////////////////////////////////////////////////////////
155157
//插件接口
156158
class ITMPlugin
157159
{
@@ -161,7 +163,7 @@ class ITMPlugin
161163
* @attention 插件开发者不应该修改这里的返回值,也不应该重写此虚函数。
162164
* @return int
163165
*/
164-
virtual int GetAPIVersion() const { return 6; }
166+
virtual int GetAPIVersion() const { return 7; }
165167

166168
/**
167169
* @brief 获取插件显示项目的对象
@@ -313,8 +315,85 @@ class ITMPlugin
313315
*/
314316
virtual int IsCommandChecked(int command_index) { return false; }
315317

318+
/**
319+
* @brief 插件初始化
320+
* @detail 当插件被加载时被调用,传递ITrafficMonitor接口的指针。插件可以保存此指针以调用ITrafficMonitor接口中的函数
321+
* @param pApp
322+
*/
323+
virtual void OnInitialize(ITrafficMonitor* pApp) {}
324+
};
325+
326+
327+
///////////////////////////////////////////////////////////////////////////////////////////////////////
328+
//主程序接口
329+
class ITrafficMonitor
330+
{
331+
public:
332+
/** 主程序的所有监控信息 */
333+
enum MonitorItem
334+
{
335+
MI_UP, /**< 上传速度 */
336+
MI_DOWN, /**< 下载速度 */
337+
MI_CPU, /**< CPU利用率 */
338+
MI_MEMORY, /**< 内存利用率 */
339+
MI_GPU_USAGE, /**< 显卡利用率 */
340+
MI_CPU_TEMP, /**< CPU温度 */
341+
MI_GPU_TEMP, /**< 显卡温度 */
342+
MI_HDD_TEMP, /**< 硬盘温度 */
343+
MI_MAIN_BOARD_TEMP, /**< 主板温度 */
344+
MI_HDD_USAGE, /**< 硬盘利用率 */
345+
MI_CPU_FREQ, /**< CPU频率 */
346+
MI_TODAY_UP_TRAFFIC, /**< 今日上传流量 */
347+
MI_TODAY_DOWN_TRAFFIC /**< 今日下载流量 */
348+
};
349+
350+
/**
351+
* @brief 获取一个主程序的监控信息
352+
* (ITMPlugin::OnMonitorInfo将被弃用)
353+
* @param item 要获取监控信息的项目
354+
* @return 获取到监控信息
355+
*/
356+
virtual double GetMonitorData(MonitorItem item) = 0;
357+
358+
/**
359+
* @brief 显示一个通知消息
360+
* @param strMsg 要显示的通知消息
361+
*/
362+
virtual void ShowNotifyMessage(const wchar_t* strMsg) = 0;
363+
364+
/**
365+
* @brief 获取当前语言id
366+
* @return 当前主程序的语言id
367+
*/
368+
virtual unsigned short GetLanguageId() const = 0;
369+
370+
/**
371+
* @brief 获取配置文件目录
372+
* @return 配置文件目录
373+
*/
374+
virtual const wchar_t* GetConfigDir() const = 0;
375+
376+
/** 主程序DPI类型 */
377+
enum DPIType
378+
{
379+
DPI_MAIN_WND, /**< 主窗口的DPI */
380+
DPI_TASKBAR /**< 任务栏窗口的DPI */
381+
};
382+
383+
/**
384+
* @brief 获取主程序DPI
385+
* @return 主程序DPI
386+
*/
387+
virtual int GetDPI(DPIType type) const = 0;
388+
389+
/**
390+
* @brief 获取当前系统主题颜色
391+
* @return COLORREF格式的颜色值
392+
*/
393+
virtual unsigned int GetThemeColor() const = 0;
316394
};
317395

396+
318397
/*
319398
* 注意:插件dll需导出以下函数
320399
* ITMPlugin* TMPluginGetInstance();
@@ -340,4 +419,6 @@ class ITMPlugin
340419
* -------------------------------------------------------------------------
341420
* 6 | 新增 IPluginItem::GetResourceUsageGraphType IPluginItem::GetResourceUsageGraphValue 函数
342421
* -------------------------------------------------------------------------
422+
* 7 | 新增 ITMPlugin::OnInitialize 函数
423+
* -------------------------------------------------------------------------
343424
*/

0 commit comments

Comments
 (0)