获取网速的接口改为GetIfTable2,支持超过4GB以上的网速显示

This commit is contained in:
Zhong Yang
2021-04-10 23:18:08 +08:00
parent c47c82735c
commit e93f84fcd7
13 changed files with 238 additions and 238 deletions
+36 -36
View File
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "AdapterCommon.h"
@@ -14,27 +14,27 @@ CAdapterCommon::~CAdapterCommon()
void CAdapterCommon::GetAdapterInfo(vector<NetWorkConection>& adapters)
{
adapters.clear();
PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO(); //PIP_ADAPTER_INFO结构体指针存储本机网卡信息
unsigned long stSize = sizeof(IP_ADAPTER_INFO); //得到结构体大小,用于GetAdaptersInfo参数
int nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize); //调用GetAdaptersInfo函数,填充pIpAdapterInfo指针变量;其中stSize参数既是一个输入量也是一个输出量
PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO(); //PIP_ADAPTER_INFO结构体指针存储本机网卡信息
unsigned long stSize = sizeof(IP_ADAPTER_INFO); //得到结构体大小,用于GetAdaptersInfo参数
int nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize); //调用GetAdaptersInfo函数,填充pIpAdapterInfo指针变量;其中stSize参数既是一个输入量也是一个输出量
if (ERROR_BUFFER_OVERFLOW == nRel)
{
//如果函数返回的是ERROR_BUFFER_OVERFLOW
//则说明GetAdaptersInfo参数传递的内存空间不够,同时其传出stSize,表示需要的空间大小
//这也是说明为什么stSize既是一个输入量也是一个输出量
delete pIpAdapterInfo; //释放原来的内存空间
pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[stSize]; //重新申请内存空间用来存储所有网卡信息
nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize); //再次调用GetAdaptersInfo函数,填充pIpAdapterInfo指针变量
//如果函数返回的是ERROR_BUFFER_OVERFLOW
//则说明GetAdaptersInfo参数传递的内存空间不够,同时其传出stSize,表示需要的空间大小
//这也是说明为什么stSize既是一个输入量也是一个输出量
delete pIpAdapterInfo; //释放原来的内存空间
pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[stSize]; //重新申请内存空间用来存储所有网卡信息
nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize); //再次调用GetAdaptersInfo函数,填充pIpAdapterInfo指针变量
}
PIP_ADAPTER_INFO pIpAdapterInfoHead = pIpAdapterInfo; //保存pIpAdapterInfo链表中第一个元素的地址
PIP_ADAPTER_INFO pIpAdapterInfoHead = pIpAdapterInfo; //保存pIpAdapterInfo链表中第一个元素的地址
if (ERROR_SUCCESS == nRel)
{
while (pIpAdapterInfo)
{
NetWorkConection connection;
connection.description = pIpAdapterInfo->Description;
connection.description = CCommon::StrToUnicode(pIpAdapterInfo->Description);
connection.ip_address = CCommon::StrToUnicode(pIpAdapterInfo->IpAddressList.IpAddress.String);
connection.subnet_mask = CCommon::StrToUnicode(pIpAdapterInfo->IpAddressList.IpMask.String);
connection.default_gateway = CCommon::StrToUnicode(pIpAdapterInfo->GatewayList.IpAddress.String);
@@ -43,7 +43,7 @@ void CAdapterCommon::GetAdapterInfo(vector<NetWorkConection>& adapters)
pIpAdapterInfo = pIpAdapterInfo->Next;
}
}
//释放内存空间
//释放内存空间
if (pIpAdapterInfoHead)
{
delete pIpAdapterInfoHead;
@@ -51,7 +51,7 @@ void CAdapterCommon::GetAdapterInfo(vector<NetWorkConection>& adapters)
if (adapters.empty())
{
NetWorkConection connection{};
connection.description = CCommon::UnicodeToStr(CCommon::LoadText(L"<", IDS_NO_CONNECTION, L">"));
connection.description = CCommon::LoadText(L"<", IDS_NO_CONNECTION, L">");
adapters.push_back(connection);
}
}
@@ -74,39 +74,39 @@ void CAdapterCommon::RefreshIpAddress(vector<NetWorkConection>& adapters)
}
}
void CAdapterCommon::GetIfTableInfo(vector<NetWorkConection>& adapters, MIB_IFTABLE* pIfTable)
void CAdapterCommon::GetIfTableInfo(vector<NetWorkConection>& adapters, MIB_IF_TABLE2* pIfTable)
{
//依次在IfTable里查找每个连接
//依次在IfTable里查找每个连接
for (size_t i{}; i < adapters.size(); i++)
{
if (adapters[i].description.empty())
continue;
int index;
index = FindConnectionInIfTable(adapters[i].description, pIfTable);
if (index == -1) //如果使用精确匹配的方式没有找到,则采用模糊匹配的方式再查找一次
if (index == -1) //如果使用精确匹配的方式没有找到,则采用模糊匹配的方式再查找一次
index = FindConnectionInIfTableFuzzy(adapters[i].description, pIfTable);
//if (index != -1)
//{
adapters[i].index = index;
adapters[i].in_bytes = pIfTable->table[index].dwInOctets;
adapters[i].out_bytes = pIfTable->table[index].dwOutOctets;
adapters[i].description_2 = (const char*)pIfTable->table[index].bDescr;
adapters[i].in_bytes = pIfTable->Table[index].InOctets;
adapters[i].out_bytes = pIfTable->Table[index].OutOctets;
adapters[i].description_2 = pIfTable->Table[index].Description;
//}
}
}
void CAdapterCommon::GetAllIfTableInfo(vector<NetWorkConection>& adapters, MIB_IFTABLE * pIfTable)
void CAdapterCommon::GetAllIfTableInfo(vector<NetWorkConection>& adapters, MIB_IF_TABLE2 * pIfTable)
{
vector<NetWorkConection> adapters_tmp;
GetAdapterInfo(adapters_tmp); //获取IP地址
GetAdapterInfo(adapters_tmp); //获取IP地址
adapters.clear();
for (size_t i{}; i < pIfTable->dwNumEntries; i++)
for (size_t i{}; i < pIfTable->NumEntries; i++)
{
NetWorkConection connection;
connection.description = connection.description_2 = (const char*)pIfTable->table[i].bDescr;
connection.description = connection.description_2 = pIfTable->Table[i].Description;
connection.index = i;
connection.in_bytes = pIfTable->table[i].dwInOctets;
connection.out_bytes = pIfTable->table[i].dwOutOctets;
connection.in_bytes = pIfTable->Table[i].InOctets;
connection.out_bytes = pIfTable->Table[i].OutOctets;
for (size_t j{}; j < adapters_tmp.size(); j++)
{
if (connection.description.find(adapters_tmp[j].description) != string::npos)
@@ -121,24 +121,24 @@ void CAdapterCommon::GetAllIfTableInfo(vector<NetWorkConection>& adapters, MIB_I
}
}
int CAdapterCommon::FindConnectionInIfTable(string connection, MIB_IFTABLE* pIfTable)
int CAdapterCommon::FindConnectionInIfTable(wstring connection, MIB_IF_TABLE2* pIfTable)
{
for (size_t i{}; i < pIfTable->dwNumEntries; i++)
for (size_t i{}; i < pIfTable->NumEntries; i++)
{
string descr = (const char*)pIfTable->table[i].bDescr;
wstring descr = pIfTable->Table[i].Description;
if (descr == connection)
return i;
}
return -1;
}
int CAdapterCommon::FindConnectionInIfTableFuzzy(string connection, MIB_IFTABLE* pIfTable)
int CAdapterCommon::FindConnectionInIfTableFuzzy(wstring connection, MIB_IF_TABLE2* pIfTable)
{
for (size_t i{}; i < pIfTable->dwNumEntries; i++)
for (size_t i{}; i < pIfTable->NumEntries; i++)
{
string descr = (const char*)pIfTable->table[i].bDescr;
wstring descr = pIfTable->Table[i].Description;
size_t index;
//在较长的字符串里查找较短的字符串
//在较长的字符串里查找较短的字符串
if (descr.size() >= connection.size())
index = descr.find(connection);
else
@@ -146,12 +146,12 @@ int CAdapterCommon::FindConnectionInIfTableFuzzy(string connection, MIB_IFTABLE*
if (index != wstring::npos)
return i;
}
//如果还是没有找到,则使用字符串匹配算法查找
//如果还是没有找到,则使用字符串匹配算法查找
double max_degree{};
int best_index{};
for (size_t i{}; i < pIfTable->dwNumEntries; i++)
for (size_t i{}; i < pIfTable->NumEntries; i++)
{
string descr = (const char*)pIfTable->table[i].bDescr;
wstring descr = pIfTable->Table[i].Description;
double degree = CCommon::StringSimilarDegree_LD(descr, connection);
if (degree > max_degree)
{
+20 -20
View File
@@ -1,17 +1,17 @@
#pragma once
#pragma once
#include "Common.h"
//保存一个网络连接信息
//保存一个网络连接信息
struct NetWorkConection
{
int index{}; //该连接在MIB_IFTABLE中的索引
string description; //网络描述(获取自GetAdapterInfo)
string description_2; //网络描述(获取自GetIfTable)
unsigned int in_bytes; //初始时已接收字节数
unsigned int out_bytes; //初始时已发送字节数
wstring ip_address{ L"-.-.-.-" }; //IP地址
wstring subnet_mask{ L"-.-.-.-" }; //子网掩码
wstring default_gateway{ L"-.-.-.-" }; //默认网关
int index{}; //该连接在MIB_IF_TABLE2中的索引
wstring description; //网络描述(获取自GetAdapterInfo)
wstring description_2; //网络描述(获取自GetIfTable)
unsigned __int64 in_bytes; //初始时已接收字节数
unsigned __int64 out_bytes; //初始时已发送字节数
wstring ip_address{ L"-.-.-.-" }; //IP地址
wstring subnet_mask{ L"-.-.-.-" }; //子网掩码
wstring default_gateway{ L"-.-.-.-" }; //默认网关
};
class CAdapterCommon
@@ -20,22 +20,22 @@ public:
CAdapterCommon();
~CAdapterCommon();
//获取网络连接列表,填充网络描述、IP地址、子网掩码、默认网关信息
//获取网络连接列表,填充网络描述、IP地址、子网掩码、默认网关信息
static void GetAdapterInfo(vector<NetWorkConection>& adapters);
//刷新网络连接列表中的IP地址、子网掩码、默认网关信息
//刷新网络连接列表中的IP地址、子网掩码、默认网关信息
static void RefreshIpAddress(vector<NetWorkConection>& adapters);
//获取网络列表中每个网络连接的MIB_IFTABLE中的索引、初始时已接收/发送字节数的信息
static void GetIfTableInfo(vector<NetWorkConection>& adapters, MIB_IFTABLE* pIfTable);
//获取网络列表中每个网络连接的MIB_IF_TABLE2中的索引、初始时已接收/发送字节数的信息
static void GetIfTableInfo(vector<NetWorkConection>& adapters, MIB_IF_TABLE2* pIfTable);
//直接将MIB_IFTABLE中的所有连接添加到adapters容器中
static void GetAllIfTableInfo(vector<NetWorkConection>& adapters, MIB_IFTABLE* pIfTable);
//直接将MIB_IF_TABLE2中的所有连接添加到adapters容器中
static void GetAllIfTableInfo(vector<NetWorkConection>& adapters, MIB_IF_TABLE2* pIfTable);
private:
//根据一个网络连接描述判断是否在IfTable列表里,返回索引,找不到则返回-1
static int FindConnectionInIfTable(string connection, MIB_IFTABLE* pIfTable);
//根据一个网络连接描述判断是否在IfTable列表里,返回索引,找不到则返回-1
static int FindConnectionInIfTable(wstring connection, MIB_IF_TABLE2* pIfTable);
//根据一个网络连接描述判断是否在IfTable接列表里,返回索引,找不到则返回-1。只需要部分匹配
static int FindConnectionInIfTableFuzzy(string connection, MIB_IFTABLE* pIfTable);
//根据一个网络连接描述判断是否在IfTable接列表里,返回索引,找不到则返回-1。只需要部分匹配
static int FindConnectionInIfTableFuzzy(wstring connection, MIB_IF_TABLE2* pIfTable);
};
+6 -43
View File
@@ -76,7 +76,7 @@ const char* CCommon::GetFileContent(const wchar_t* file_path, size_t& length, bo
return buff;
}
CString CCommon::DataSizeToString(unsigned int size, const PublicSettingData& cfg)
CString CCommon::DataSizeToString(unsigned long long size, const PublicSettingData& cfg)
{
//CString str;
CString value_str, unit_str;
@@ -751,25 +751,21 @@ CString CCommon::LoadTextFormat(UINT id, const std::initializer_list<CVariant>&
return StringFormat(str.GetString(), paras);
}
CString CCommon::IntToString(int n, bool thousand_separation, bool is_unsigned)
CString CCommon::IntToString(__int64 n, bool thousand_separation, bool is_unsigned)
{
CString str;
if(is_unsigned)
str.Format(_T("%u"), static_cast<unsigned int>(n));
else
str.Format(_T("%d"), n);
int length{ str.GetLength() };
wstring str = std::to_wstring(is_unsigned ? static_cast<unsigned __int64>(n) : n);
int count{};
if (thousand_separation)
{
int length{ static_cast<int>(str.size()) };
for (int i{ length - 1 }; i > 0; i--)
{
count++;
if (count % 3 == 0)
str.Insert(i, _T(","));
str.insert(i, L",");
}
}
return str;
return str.c_str();
}
void CCommon::NormalizeFont(LOGFONT & font)
@@ -840,39 +836,6 @@ void CCommon::WStringCopy(wchar_t * str_dest, int dest_size, const wchar_t * str
str_dest[dest_size - 1] = L'\0';
}
double CCommon::StringSimilarDegree_LD(const string & srcString, const string & matchString)
{
int n = srcString.size();
int m = matchString.size();
//int[, ] d = new int[n + 1, m + 1]; // matrix
vector<vector<int>> d(n + 1, vector<int>(m + 1));
int cost; // cost
// Step 1(如果其中一个字符串长度为0,则相似度为1)?
//if (n == 0) return (double)m / max(srcString.size(), matchString.size());
//if (m == 0) return (double)n / max(srcString.size(), matchString.size());
if (n == 0 || m == 0) return 0.0; //如果其中一个字符串长度为0,则相似度为0
// Step 2
for (int i = 0; i <= n; d[i][0] = i++);
for (int j = 0; j <= m; d[0][j] = j++);
// Step 3
for (int i = 1; i <= n; i++)
{
//Step 4
for (int j = 1; j <= m; j++)
{
// Step 5
cost = (matchString.substr(j - 1, 1) == srcString.substr(i - 1, 1) ? 0 : 1);
// Step 6
d[i][j] = min(min(d[i - 1][j] + 1, d[i][j - 1] + 1), d[i - 1][j - 1] + cost);
}
}
// Step 7
double ds = 1 - (double)d[n][m] / max(srcString.size(), matchString.size());
return ds;
}
void CCommon::SetThreadLanguage(Language language)
{
switch (language)
+35 -3
View File
@@ -117,7 +117,7 @@ public:
size:数据的字节数
返回值:转换后的字符串
*/
static CString DataSizeToString(unsigned int size, const PublicSettingData& cfg);
static CString DataSizeToString(unsigned long long size, const PublicSettingData& cfg);
static CString DataSizeToString(unsigned long long size);
//将温度信息转换成字符串
@@ -220,7 +220,7 @@ public:
//n:要转换的数值
//thousand_separation:是否要每隔3位数使用逗号分隔
//is_unsigned:数值是否是无符号的
static CString IntToString(int n, bool thousand_separation = false, bool is_unsigned = false);
static CString IntToString(__int64 n, bool thousand_separation = false, bool is_unsigned = false);
//删除字体名称后面的Bold、Light等字符串,并根据这些字符串设置字体粗细
static void NormalizeFont(LOGFONT& font);
@@ -232,7 +232,39 @@ public:
/// 字符串相似度算法-编辑距离法
/// </summary>
/// <returns>返回的值为0~1,越大相似度越高</returns>
static double StringSimilarDegree_LD(const string& srcString, const string& matchString);
template<class T>
static double StringSimilarDegree_LD(const T& srcString, const T& matchString)
{
int n = srcString.size();
int m = matchString.size();
//int[, ] d = new int[n + 1, m + 1]; // matrix
vector<vector<int>> d(n + 1, vector<int>(m + 1));
int cost; // cost
// Step 1(如果其中一个字符串长度为0,则相似度为1)?
//if (n == 0) return (double)m / max(srcString.size(), matchString.size());
//if (m == 0) return (double)n / max(srcString.size(), matchString.size());
if (n == 0 || m == 0) return 0.0; //如果其中一个字符串长度为0,则相似度为0
// Step 2
for (int i = 0; i <= n; d[i][0] = i++);
for (int j = 0; j <= m; d[0][j] = j++);
// Step 3
for (int i = 1; i <= n; i++)
{
//Step 4
for (int j = 1; j <= m; j++)
{
// Step 5
cost = (matchString.substr(j - 1, 1) == srcString.substr(i - 1, 1) ? 0 : 1);
// Step 6
d[i][j] = min(min(d[i - 1][j] + 1, d[i][j - 1] + 1), d[i - 1][j - 1] + cost);
}
}
// Step 7
double ds = 1 - (double)d[n][m] / max(srcString.size(), matchString.size());
return ds;
}
//设置线程语言
static void SetThreadLanguage(Language language);
+1 -1
View File
@@ -214,7 +214,7 @@ struct MainConfigData
bool m_auto_select{ false }; //自动选择连接
bool m_select_all{ false }; //统计所有连接的网速
string m_connection_name; //当前选择网络的名称
wstring m_connection_name; //当前选择网络的名称
wstring m_skin_name; //选择的皮肤的名称
int m_dft_notify_icon = 0; //默认的通知图标(用于区分win10的深色和浅色模式)
+92 -77
View File
@@ -1,4 +1,4 @@
// CNetworkInfoDlg.cpp : 实现文件
// CNetworkInfoDlg.cpp : 实现文件
//
#include "stdafx.h"
@@ -7,12 +7,12 @@
#include "afxdialogex.h"
// CNetworkInfoDlg 对话框
// CNetworkInfoDlg 对话框
IMPLEMENT_DYNAMIC(CNetworkInfoDlg, CBaseDialog)
CNetworkInfoDlg::CNetworkInfoDlg(vector<NetWorkConection>& adapters, MIB_IFROW* pIfRow, int connection_selected, CWnd* pParent /*=NULL*/)
: CBaseDialog(IDD_NETWORK_INFO_DIALOG, pParent), m_connections(adapters), m_pIfRow(pIfRow), m_connection_selected(connection_selected)
CNetworkInfoDlg::CNetworkInfoDlg(vector<NetWorkConection>& adapters, MIB_IF_TABLE2*& pIfTable, int connection_selected, CWnd* pParent /*=NULL*/)
: CBaseDialog(IDD_NETWORK_INFO_DIALOG, pParent), m_connections(adapters), m_pIfTable(pIfTable), m_connection_selected(connection_selected)
{
m_current_connection = connection_selected;
}
@@ -25,13 +25,13 @@ CNetworkInfoDlg::~CNetworkInfoDlg()
void CNetworkInfoDlg::ShowInfo()
{
CString temp;
MIB_IFROW& network_info = m_pIfRow[m_connections[m_connection_selected].index];
//接口名
m_info_list.SetItemText(0, 1, network_info.wszName);
//接口描述
m_info_list.SetItemText(1, 1, CCommon::StrToUnicode((const char*)network_info.bDescr).c_str());
//连接类型
switch (network_info.dwType)
MIB_IF_ROW2 network_info = m_pIfTable->Table[m_connections[m_connection_selected].index];
//接口名
m_info_list.SetItemText(0, 1, network_info.Alias);
//接口描述
m_info_list.SetItemText(1, 1, network_info.Description);
//连接类型
switch (network_info.Type)
{
case IF_TYPE_OTHER: temp = CCommon::LoadText(IDS_IF_TYPE_OTHER); break;
case IF_TYPE_ETHERNET_CSMACD: temp = CCommon::LoadText(IDS_IF_TYPE_ETHERNET_CSMACD); break;
@@ -49,56 +49,71 @@ void CNetworkInfoDlg::ShowInfo()
default: temp = CCommon::LoadText(IDS_UNKNOW_CONNECTION); break;
}
m_info_list.SetItemText(2, 1, temp);
//速度
temp.Format(_T("%dMbps"), network_info.dwSpeed / 1000000);
//速度
temp.Format(_T("%dMbps"), network_info.TransmitLinkSpeed / 1000000);
m_info_list.SetItemText(3, 1, temp);
//适配器物理地址
//适配器物理地址
temp = _T("");
char buff[3];
for (size_t i{}; i < network_info.dwPhysAddrLen; i++)
for (size_t i{}; i < network_info.PhysicalAddressLength; i++)
{
sprintf_s(buff, "%.2x", network_info.bPhysAddr[i]);
sprintf_s(buff, "%.2x", network_info.PhysicalAddress[i]);
temp += buff;
if (i != network_info.dwPhysAddrLen - 1)
if (i != network_info.PhysicalAddressLength - 1)
temp += _T('-');
}
m_info_list.SetItemText(4, 1, temp);
//IP地址
//IP地址
m_info_list.SetItemText(5, 1, m_connections[m_connection_selected].ip_address.c_str());
//子网掩码
//子网掩码
m_info_list.SetItemText(6, 1, m_connections[m_connection_selected].subnet_mask.c_str());
//默认网关
//默认网关
m_info_list.SetItemText(7, 1, m_connections[m_connection_selected].default_gateway.c_str());
//连接状态
switch (network_info.dwOperStatus)
//连接状态
switch (network_info.OperStatus)
{
case IF_OPER_STATUS_NON_OPERATIONAL: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_NON_OPERATIONAL); break;
case IF_OPER_STATUS_UNREACHABLE: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_UNREACHABLE); break;
case IF_OPER_STATUS_DISCONNECTED: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_DISCONNECTED); break;
case IF_OPER_STATUS_CONNECTING: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_CONNECTING); break;
case IF_OPER_STATUS_CONNECTED: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_CONNECTED); break;
case IF_OPER_STATUS_OPERATIONAL: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_OPERATIONAL); break;
default: temp = CCommon::LoadText(IDS_UNKNOW_STATUS); break;
//case IF_OPER_STATUS_NON_OPERATIONAL: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_NON_OPERATIONAL); break;
//case IF_OPER_STATUS_UNREACHABLE: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_UNREACHABLE); break;
//case IF_OPER_STATUS_DISCONNECTED: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_DISCONNECTED); break;
//case IF_OPER_STATUS_CONNECTING: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_CONNECTING); break;
//case IF_OPER_STATUS_CONNECTED: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_CONNECTED); break;
//case IF_OPER_STATUS_OPERATIONAL: temp = CCommon::LoadText(IDS_IF_OPER_STATUS_OPERATIONAL); break;
case IfOperStatusUp:
temp = CCommon::LoadText(IDS_IF_OPER_STATUS_UP);
break;
case IfOperStatusDown:
case IfOperStatusNotPresent:
case IfOperStatusLowerLayerDown:
temp = CCommon::LoadText(IDS_IF_OPER_STATUS_DOWN);
break;
case IfOperStatusTesting:
case IfOperStatusUnknown:
temp = CCommon::LoadText(IDS_UNKNOW_STATUS);
break;
case IfOperStatusDormant:
temp = CCommon::LoadText(IDS_IF_OPER_STATUS_DORMANT);
break;
default: temp = CCommon::LoadText(IDS_UNKNOW_STATUS); break;
}
m_info_list.SetItemText(8, 1, temp);
//已接收字节数
temp.Format(_T("%s (%s)"), CCommon::IntToString(network_info.dwInOctets, true, true), CCommon::DataSizeToString(network_info.dwInOctets));
//已接收字节数
temp.Format(_T("%s (%s)"), CCommon::IntToString(network_info.InOctets, true, true), CCommon::DataSizeToString(network_info.InOctets));
m_info_list.SetItemText(9, 1, temp);
//已发送字节数
temp.Format(_T("%s (%s)"), CCommon::IntToString(network_info.dwOutOctets, true, true), CCommon::DataSizeToString(network_info.dwOutOctets));
//已发送字节数
temp.Format(_T("%s (%s)"), CCommon::IntToString(network_info.OutOctets, true, true), CCommon::DataSizeToString(network_info.OutOctets));
m_info_list.SetItemText(10, 1, temp);
//自程序启动以来已接收字节数
unsigned int in_bytes_since_start;
in_bytes_since_start = network_info.dwInOctets - m_connections[m_connection_selected].in_bytes;
//自程序启动以来已接收字节数
unsigned __int64 in_bytes_since_start;
in_bytes_since_start = network_info.InOctets - m_connections[m_connection_selected].in_bytes;
temp.Format(_T("%s (%s)"), CCommon::IntToString(in_bytes_since_start, true, true), CCommon::DataSizeToString(in_bytes_since_start));
m_info_list.SetItemText(11, 1, temp);
//自程序启动以来已发送字节数
unsigned int out_bytes_since_start;
out_bytes_since_start = network_info.dwOutOctets - m_connections[m_connection_selected].out_bytes;
//自程序启动以来已发送字节数
unsigned __int64 out_bytes_since_start;
out_bytes_since_start = network_info.OutOctets - m_connections[m_connection_selected].out_bytes;
temp.Format(_T("%s (%s)"), CCommon::IntToString(out_bytes_since_start, true, true), CCommon::DataSizeToString(out_bytes_since_start));
m_info_list.SetItemText(12, 1, temp);
//显示当前选择指示
//显示当前选择指示
CString str;
str.Format(_T("%d/%d"), m_connection_selected + 1, m_connections.size());
SetDlgItemText(IDC_INDEX_STATIC, str);
@@ -112,7 +127,7 @@ void CNetworkInfoDlg::ShowInfo()
void CNetworkInfoDlg::GetProgramElapsedTime()
{
//程序已运行时间
//程序已运行时间
SYSTEMTIME current_time, time;
GetLocalTime(&current_time);
time = CCommon::CompareSystemTime(current_time, m_start_time);
@@ -123,13 +138,13 @@ void CNetworkInfoDlg::GetProgramElapsedTime()
UINT CNetworkInfoDlg::GetInternetIPThreadFunc(LPVOID lpParam)
{
CCommon::SetThreadLanguage(theApp.m_general_data.language); //设置线程语言
CCommon::SetThreadLanguage(theApp.m_general_data.language); //设置线程语言
CNetworkInfoDlg* p_instance = (CNetworkInfoDlg*)lpParam;
wstring ip_address, ip_location;
//IPV4
CCommon::GetInternetIp2(ip_address, ip_location, false); //获取外网IP地址,
if (!IsWindow(p_instance->GetSafeHwnd())) //如果当前对话框已经销毁,则退出线程
CCommon::GetInternetIp2(ip_address, ip_location, false); //获取外网IP地址,
if (!IsWindow(p_instance->GetSafeHwnd())) //如果当前对话框已经销毁,则退出线程
return 0;
if (!ip_address.empty())
{
@@ -147,8 +162,8 @@ UINT CNetworkInfoDlg::GetInternetIPThreadFunc(LPVOID lpParam)
//IPV6
wstring ipv6_address, ipv6_location;
CCommon::GetInternetIp2(ip_address, ip_location, true); //获取外网IP地址,
if (!IsWindow(p_instance->GetSafeHwnd())) //如果当前对话框已经销毁,则退出线程
CCommon::GetInternetIp2(ip_address, ip_location, true); //获取外网IP地址,
if (!IsWindow(p_instance->GetSafeHwnd())) //如果当前对话框已经销毁,则退出线程
return 0;
if (!ip_address.empty())
{
@@ -192,31 +207,31 @@ BEGIN_MESSAGE_MAP(CNetworkInfoDlg, CBaseDialog)
END_MESSAGE_MAP()
// CNetworkInfoDlg 消息处理程序
// CNetworkInfoDlg 消息处理程序
BOOL CNetworkInfoDlg::OnInitDialog()
{
CBaseDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
// TODO: 在此添加额外的初始化
SetWindowText(CCommon::LoadText(IDS_TITLE_CONNECTION_DETIAL));
SetIcon(theApp.GetMenuIcon(IDI_INFO), FALSE); // 设置小图标
SetIcon(theApp.GetMenuIcon(IDI_INFO), FALSE); // 设置小图标
//重新获取IP地址
//重新获取IP地址
CAdapterCommon::RefreshIpAddress(m_connections);
//初始化列表控件
//初始化列表控件
CRect rect;
m_info_list.GetClientRect(rect);
m_info_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
int width0, width1;
width0 = rect.Width() / 4;
width1 = rect.Width() - width0 - theApp.DPI(20) - 1;
m_info_list.InsertColumn(0, CCommon::LoadText(IDS_ITEM), LVCFMT_LEFT, width0); //插入第0列
m_info_list.InsertColumn(1, CCommon::LoadText(IDS_VALUE), LVCFMT_LEFT, width1); //插入第1列
m_info_list.InsertColumn(0, CCommon::LoadText(IDS_ITEM), LVCFMT_LEFT, width0); //插入第0列
m_info_list.InsertColumn(1, CCommon::LoadText(IDS_VALUE), LVCFMT_LEFT, width1); //插入第1列
//向列表中插入行
//向列表中插入行
m_info_list.InsertItem(0, CCommon::LoadText(IDS_INTERFACE_NAME));
m_info_list.InsertItem(1, CCommon::LoadText(IDS_INTERFACE_DESCRIPTION));
m_info_list.InsertItem(2, CCommon::LoadText(IDS_CONNECTION_TYPE));
@@ -244,7 +259,7 @@ BOOL CNetworkInfoDlg::OnInitDialog()
m_info_list.SetItemText(15, 1, CCommon::LoadText(IDS_DOUBLE_CLICK_TO_ACQUIRE));
//}
//显示列表中的信息
//显示列表中的信息
LOGFONT lf{};
GetFont()->GetLogFont(&lf);
lf.lfWeight = FW_BOLD;
@@ -254,23 +269,23 @@ BOOL CNetworkInfoDlg::OnInitDialog()
//CCommon::GetInternetIp();
//if (theApp.m_cfg_data.m_show_internet_ip)
// m_pGetIPThread = AfxBeginThread(GetInternetIPThreadFunc, this); //启动获取外网IP的线程
// m_pGetIPThread = AfxBeginThread(GetInternetIPThreadFunc, this); //启动获取外网IP的线程
//SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); //取消置顶
//SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); //取消置顶
m_info_list.GetToolTips()->SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
m_menu.LoadMenu(IDR_INFO_MENU); //装载右键菜单
m_menu.LoadMenu(IDR_INFO_MENU); //装载右键菜单
SetTimer(CONNECTION_DETAIL_TIMER, 1000, NULL);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
// 异常: OCX 属性页应返回 FALSE
}
void CNetworkInfoDlg::OnCopyText()
{
// TODO: 在此添加命令处理程序代码
// TODO: 在此添加命令处理程序代码
if (!CCommon::CopyStringToClipboard(wstring(m_selected_string)))
MessageBox(CCommon::LoadText(IDS_COPY_TO_CLIPBOARD_FAILED), NULL, MB_ICONWARNING);
}
@@ -279,19 +294,19 @@ void CNetworkInfoDlg::OnCopyText()
void CNetworkInfoDlg::OnNMRClickInfoList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
// TODO: 在此添加控件通知处理程序代码
//获取鼠标点击处的文本
//获取鼠标点击处的文本
int item, sub_item;
item = pNMItemActivate->iItem;
sub_item = pNMItemActivate->iSubItem;
m_selected_string = m_info_list.GetItemText(item, sub_item);
//弹出右键菜单
CMenu* pContextMenu = m_menu.GetSubMenu(0); //获取第一个弹出菜单
CPoint point1; //定义一个用于确定光标位置的位置
GetCursorPos(&point1); //获取当前光标的位置,以便使得菜单可以跟随光标
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point1.x, point1.y, this); //在指定位置显示弹出菜单
//弹出右键菜单
CMenu* pContextMenu = m_menu.GetSubMenu(0); //获取第一个弹出菜单
CPoint point1; //定义一个用于确定光标位置的位置
GetCursorPos(&point1); //获取当前光标的位置,以便使得菜单可以跟随光标
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point1.x, point1.y, this); //在指定位置显示弹出菜单
*pResult = 0;
}
@@ -299,8 +314,8 @@ void CNetworkInfoDlg::OnNMRClickInfoList1(NMHDR *pNMHDR, LRESULT *pResult)
void CNetworkInfoDlg::OnClose()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//对话框关闭时强制结束获取IP地址的线程
// TODO: 在此添加消息处理程序代码和/或调用默认值
//对话框关闭时强制结束获取IP地址的线程
//if(theApp.m_cfg_data.m_show_internet_ip)
// TerminateThread(m_pGetIPThread->m_hThread, 0);
CBaseDialog::OnClose();
@@ -309,7 +324,7 @@ void CNetworkInfoDlg::OnClose()
void CNetworkInfoDlg::OnBnClickedPreviousButton()
{
// TODO: 在此添加控件通知处理程序代码
// TODO: 在此添加控件通知处理程序代码
if (m_connection_selected > 0)
{
m_connection_selected--;
@@ -320,7 +335,7 @@ void CNetworkInfoDlg::OnBnClickedPreviousButton()
void CNetworkInfoDlg::OnBnClickedNextButton()
{
// TODO: 在此添加控件通知处理程序代码
// TODO: 在此添加控件通知处理程序代码
if (m_connection_selected < m_connections.size() - 1)
{
m_connection_selected++;
@@ -331,7 +346,7 @@ void CNetworkInfoDlg::OnBnClickedNextButton()
BOOL CNetworkInfoDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
// TODO: 在此添加专用代码和/或调用基类
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_LEFT)
@@ -353,7 +368,7 @@ BOOL CNetworkInfoDlg::PreTranslateMessage(MSG* pMsg)
void CNetworkInfoDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (nIDEvent == CONNECTION_DETAIL_TIMER)
{
GetProgramElapsedTime();
@@ -364,8 +379,8 @@ void CNetworkInfoDlg::OnTimer(UINT_PTR nIDEvent)
BOOL CNetworkInfoDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//通过鼠标滚轮翻页
// TODO: 在此添加消息处理程序代码和/或调用默认值
//通过鼠标滚轮翻页
if (zDelta > 0)
{
OnBnClickedPreviousButton();
@@ -382,8 +397,8 @@ BOOL CNetworkInfoDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
void CNetworkInfoDlg::OnNMDblclkInfoList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
if (/*!theApp.m_cfg_data.m_show_internet_ip && */!m_ip_acquired && (pNMItemActivate->iItem == 14 || pNMItemActivate->iItem == 15)) //双击了IP地址一行时
// TODO: 在此添加控件通知处理程序代码
if (/*!theApp.m_cfg_data.m_show_internet_ip && */!m_ip_acquired && (pNMItemActivate->iItem == 14 || pNMItemActivate->iItem == 15)) //双击了IP地址一行时
{
m_info_list.SetItemText(14, 1, CCommon::LoadText(IDS_ACQUIRING, _T("...")));
m_info_list.SetItemText(15, 1, CCommon::LoadText(IDS_ACQUIRING, _T("...")));
+14 -14
View File
@@ -1,51 +1,51 @@
#pragma once
#pragma once
#include"Common.h"
#include "afxcmn.h"
#include "AdapterCommon.h"
#include "BaseDialog.h"
// CNetworkInfoDlg 对话框
// CNetworkInfoDlg 对话框
class CNetworkInfoDlg : public CBaseDialog
{
DECLARE_DYNAMIC(CNetworkInfoDlg)
public:
CNetworkInfoDlg(vector<NetWorkConection>& adapters, MIB_IFROW* pIfRow, int connection_selected, CWnd* pParent = NULL); // 标准构造函数
CNetworkInfoDlg(vector<NetWorkConection>& adapters, MIB_IF_TABLE2*& pIfTable, int connection_selected, CWnd* pParent = NULL); // 标准构造函数
virtual ~CNetworkInfoDlg();
// 对话框数据
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_NETWORK_INFO_DIALOG };
#endif
SYSTEMTIME m_start_time; //程序启动的时间
SYSTEMTIME m_start_time; //程序启动的时间
protected:
vector<NetWorkConection>& m_connections;
MIB_IFROW* m_pIfRow;
int m_connection_selected; //当前对话框显示的连接
int m_current_connection; //初始选择的连接
MIB_IF_TABLE2*& m_pIfTable;
int m_connection_selected; //当前对话框显示的连接
int m_current_connection; //初始选择的连接
CListCtrl m_info_list;
CMenu m_menu;
CString m_selected_string;
CFont m_font_bold; //默认字体的粗体
CFont m_font_bold; //默认字体的粗体
CWinThread* m_pGetIPThread; //获取外网IP的线程
bool m_ip_acquired{ false }; //如果已获取外网ip地址,则为true
CWinThread* m_pGetIPThread; //获取外网IP的线程
bool m_ip_acquired{ false }; //如果已获取外网ip地址,则为true
//void GetIPAddress(); //获取IP地址
//void GetIPAddress(); //获取IP地址
void ShowInfo();
void GetProgramElapsedTime();
//获取外网IP的线程函数
//获取外网IP的线程函数
static UINT GetInternetIPThreadFunc(LPVOID lpParam);
virtual CString GetDialogName() const override;
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
+2 -2
View File
@@ -91,7 +91,7 @@ void CTrafficMonitorApp::LoadConfig()
ini.LoadMainWndColors(_T("config"), _T("text_color"), m_main_wnd_data.text_colors, 16384);
m_main_wnd_data.specify_each_item_color = ini.GetBool(_T("config"), _T("specify_each_item_color"), false);
m_cfg_data.m_hide_main_window = ini.GetBool(_T("config"), _T("hide_main_window"), false);
m_cfg_data.m_connection_name = CCommon::UnicodeToStr(ini.GetString(L"connection", L"connection_name", L"").c_str());
m_cfg_data.m_connection_name = ini.GetString(L"connection", L"connection_name", L"");
m_cfg_data.m_skin_name = ini.GetString(_T("config"), _T("skin_selected"), _T(""));
if (m_cfg_data.m_skin_name.substr(0, 8) == L".\\skins\\") //如果读取到的皮肤名称前面有".\\skins\\",则把它删除。(用于和前一个版本保持兼容性)
m_cfg_data.m_skin_name = m_cfg_data.m_skin_name.substr(7);
@@ -266,7 +266,7 @@ void CTrafficMonitorApp::SaveConfig()
ini.SaveMainWndColors(L"config", L"text_color", m_main_wnd_data.text_colors);
ini.WriteBool(_T("config"), _T("specify_each_item_color"), m_main_wnd_data.specify_each_item_color);
ini.WriteInt(L"config", L"hide_main_window", m_cfg_data.m_hide_main_window);
ini.WriteString(L"connection", L"connection_name", CCommon::StrToUnicode(m_cfg_data.m_connection_name.c_str()).c_str());
ini.WriteString(L"connection", L"connection_name", m_cfg_data.m_connection_name.c_str());
ini.WriteString(_T("config"), _T("skin_selected"), m_cfg_data.m_skin_name.c_str());
ini.WriteInt(L"config", L"notify_icon_selected", m_cfg_data.m_notify_icon_selected);
ini.WriteBool(L"config", L"notify_icon_auto_adapt", m_cfg_data.m_notify_icon_auto_adapt);
+2 -2
View File
@@ -39,8 +39,8 @@ public:
wstring m_config_dir;
//以下数据定义为App类中的公共成员,以便于在主对话框和任务栏窗口中都能访问
unsigned int m_in_speed{}; //下载速度
unsigned int m_out_speed{}; //上传速度
unsigned __int64 m_in_speed{}; //下载速度
unsigned __int64 m_out_speed{}; //上传速度
int m_cpu_usage{ -1 }; //CPU利用率
int m_memory_usage{ -1 }; //内存利用率
int m_used_memory{}; //可用物理内存(单位为KB)
Binary file not shown.
+29 -38
View File
@@ -27,7 +27,7 @@ CTrafficMonitorDlg::CTrafficMonitorDlg(CWnd* pParent /*=NULL*/)
CTrafficMonitorDlg::~CTrafficMonitorDlg()
{
free(m_pIfTable);
FreeMibTable(m_pIfTable);
if (m_tBarDlg != nullptr)
{
@@ -282,16 +282,16 @@ void CTrafficMonitorDlg::GetScreenSize()
void CTrafficMonitorDlg::AutoSelect()
{
unsigned int max_in_out_bytes{};
unsigned int in_out_bytes;
unsigned __int64 max_in_out_bytes{};
unsigned __int64 in_out_bytes;
//m_connection_selected = m_connections[0].index;
m_connection_selected = 0;
//自动选择连接时,查找已发送和已接收字节数之和最多的那个连接,并将其设置为当前查看的连接
for (size_t i{}; i<m_connections.size(); i++)
{
if (m_pIfTable->table[m_connections[i].index].dwOperStatus == IF_OPER_STATUS_OPERATIONAL) //只选择网络状态为正常的连接
if (m_pIfTable->Table[m_connections[i].index].OperStatus == IfOperStatusUp) //只选择网络状态为正常的连接
{
in_out_bytes = m_pIfTable->table[m_connections[i].index].dwInOctets + m_pIfTable->table[m_connections[i].index].dwOutOctets;
in_out_bytes = m_pIfTable->Table[m_connections[i].index].InOctets + m_pIfTable->Table[m_connections[i].index].OutOctets;
if (in_out_bytes > max_in_out_bytes)
{
max_in_out_bytes = in_out_bytes;
@@ -305,19 +305,9 @@ void CTrafficMonitorDlg::AutoSelect()
void CTrafficMonitorDlg::IniConnection()
{
//为m_pIfTable开辟所需大小的内存
free(m_pIfTable);
m_dwSize = sizeof(MIB_IFTABLE);
m_pIfTable = (MIB_IFTABLE *)malloc(m_dwSize);
int rtn;
rtn = GetIfTable(m_pIfTable, &m_dwSize, FALSE);
if (rtn == ERROR_INSUFFICIENT_BUFFER) //如果函数返回值为ERROR_INSUFFICIENT_BUFFER,说明m_pIfTable的大小不够
{
free(m_pIfTable);
m_pIfTable = (MIB_IFTABLE *)malloc(m_dwSize); //用新的大小重新开辟一块内存
}
FreeMibTable(m_pIfTable);
GetIfTable2(&m_pIfTable);
//获取当前所有的连接,并保存到m_connections容器中
GetIfTable(m_pIfTable, &m_dwSize, FALSE);
if (!theApp.m_general_data.show_all_interface)
{
CAdapterCommon::GetAdapterInfo(m_connections);
@@ -349,11 +339,11 @@ void CTrafficMonitorDlg::IniConnection()
log_str += _T("\n");
}
log_str += _T("IfTable:\n");
for (size_t i{}; i < m_pIfTable->dwNumEntries; i++)
for (size_t i{}; i < m_pIfTable->NumEntries; i++)
{
log_str += CCommon::IntToString(i);
log_str += _T(" ");
log_str += (const char*)m_pIfTable->table[i].bDescr;
log_str += m_pIfTable->Table[i].Description;
log_str += _T("\n");
}
CCommon::WriteLog(log_str, (theApp.m_config_dir + L".\\connections.log").c_str());
@@ -412,7 +402,7 @@ void CTrafficMonitorDlg::IniConnectionMenu(CMenu * pMenu)
CString connection_descr;
for (size_t i{}; i < m_connections.size(); i++)
{
connection_descr = CCommon::StrToUnicode(m_connections[i].description.c_str()).c_str();
connection_descr = m_connections[i].description.c_str();
pMenu->AppendMenu(MF_STRING | MF_ENABLED, ID_SELECT_ALL_CONNECTION + i + 1, connection_descr);
}
}
@@ -838,11 +828,12 @@ void CTrafficMonitorDlg::OnTimer(UINT_PTR nIDEvent)
if (nIDEvent == MONITOR_TIMER)
{
//获取网络连接速度
int rtn = GetIfTable(m_pIfTable, &m_dwSize, FALSE);
FreeMibTable(m_pIfTable);
int rtn = GetIfTable2(&m_pIfTable);
if (!theApp.m_cfg_data.m_select_all) //获取当前选中连接的网速
{
m_in_bytes = m_pIfTable->table[m_connections[m_connection_selected].index].dwInOctets;
m_out_bytes = m_pIfTable->table[m_connections[m_connection_selected].index].dwOutOctets;
m_in_bytes = m_pIfTable->Table[m_connections[m_connection_selected].index].InOctets;
m_out_bytes = m_pIfTable->Table[m_connections[m_connection_selected].index].OutOctets;
}
else //获取全部连接的网速
{
@@ -853,8 +844,8 @@ void CTrafficMonitorDlg::OnTimer(UINT_PTR nIDEvent)
//if (i > 0 && m_pIfTable->table[m_connections[i].index].dwInOctets == m_pIfTable->table[m_connections[i - 1].index].dwInOctets
// && m_pIfTable->table[m_connections[i].index].dwOutOctets == m_pIfTable->table[m_connections[i - 1].index].dwOutOctets)
// continue; //连接列表中可能会有相同的连接,统计所有连接的网速时,忽略掉已发送和已接收字节数完全相同的连接
m_in_bytes += m_pIfTable->table[m_connections[i].index].dwInOctets;
m_out_bytes += m_pIfTable->table[m_connections[i].index].dwOutOctets;
m_in_bytes += m_pIfTable->Table[m_connections[i].index].InOctets;
m_out_bytes += m_pIfTable->Table[m_connections[i].index].OutOctets;
}
}
@@ -879,8 +870,8 @@ void CTrafficMonitorDlg::OnTimer(UINT_PTR nIDEvent)
// cur_out_speed = 0;
//将当前监控时间间隔的流量转换成每秒时间间隔内的流量
theApp.m_in_speed = static_cast<unsigned int>(cur_in_speed * 1000 / theApp.m_general_data.monitor_time_span);
theApp.m_out_speed = static_cast<unsigned int>(cur_out_speed * 1000 / theApp.m_general_data.monitor_time_span);
theApp.m_in_speed = static_cast<unsigned __int64>(cur_in_speed * 1000 / theApp.m_general_data.monitor_time_span);
theApp.m_out_speed = static_cast<unsigned __int64>(cur_out_speed * 1000 / theApp.m_general_data.monitor_time_span);
m_connection_change_flag = false; //清除连接发生变化的标志
@@ -932,14 +923,14 @@ void CTrafficMonitorDlg::OnTimer(UINT_PTR nIDEvent)
}
}
if (rtn == ERROR_INSUFFICIENT_BUFFER)
{
IniConnection();
CString info;
info.LoadString(IDS_INSUFFICIENT_BUFFER);
info.Replace(_T("<%cnt%>"), CCommon::IntToString(m_restart_cnt));
CCommon::WriteLog(info, theApp.m_log_path.c_str());
}
//if (rtn == ERROR_NOT_ENOUGH_MEMORY)
//{
// IniConnection();
// CString info;
// info.LoadString(IDS_INSUFFICIENT_BUFFER);
// info.Replace(_T("<%cnt%>"), CCommon::IntToString(m_restart_cnt));
// CCommon::WriteLog(info, theApp.m_log_path.c_str());
//}
if (m_monitor_time_cnt % GetMonitorTimerCount(3) == GetMonitorTimerCount(3) - 1)
@@ -963,8 +954,8 @@ void CTrafficMonitorDlg::OnTimer(UINT_PTR nIDEvent)
}
last_interface_num = interface_num;
string descr;
descr = (const char*)m_pIfTable->table[m_connections[m_connection_selected].index].bDescr;
wstring descr;
descr = m_pIfTable->Table[m_connections[m_connection_selected].index].Description;
if (descr != theApp.m_cfg_data.m_connection_name)
{
//写入额外的调试信息
@@ -1416,7 +1407,7 @@ void CTrafficMonitorDlg::OnNetworkInfo()
{
// TODO: 在此添加命令处理程序代码
//弹出“连接详情”对话框
CNetworkInfoDlg aDlg(m_connections, m_pIfTable->table, m_connection_selected);
CNetworkInfoDlg aDlg(m_connections, m_pIfTable, m_connection_selected);
////向CNetworkInfoDlg类传递自启动以来已发送和接收的字节数
//aDlg.m_in_bytes = m_pIfTable->table[m_connections[m_connection_selected].index].dwInOctets - m_connections[m_connection_selected].in_bytes;
//aDlg.m_out_bytes = m_pIfTable->table[m_connections[m_connection_selected].index].dwOutOctets - m_connections[m_connection_selected].out_bytes;
+1 -2
View File
@@ -47,8 +47,7 @@ protected:
CTaskBarDlg* m_tBarDlg; //任务栏窗口的指针
vector<NetWorkConection> m_connections; //保存获取到的要显示到“选择网卡”菜单项中的所有网络连接
MIB_IFTABLE* m_pIfTable;
DWORD m_dwSize{}; //m_pIfTable的大小
MIB_IF_TABLE2* m_pIfTable;
int m_connection_selected{ 0 }; //要显示流量的连接的序号
unsigned __int64 m_in_bytes; //当前已接收的字节数
unsigned __int64 m_out_bytes; //当前已发送的字节数
Binary file not shown.