资源简介
MFC实时网络连接装状况监测代码,点击按钮查看网络状况,网络若连接则实时监测到,并关闭窗口。

代码片段和文件信息
#include
#include
#include
#include
#include “CheckInternetState.h“
#pragma comment(lib“Wininet.lib“)
#pragma comment(lib“Sensapi.lib“)
#pragma comment(lib“iphlpapi“)
BOOL CheckInternetMethord1()
{
//#define INTERNET_CONNECTION_MODEM 1
//#define INTERNET_CONNECTION_LAN 2
//#define INTERNET_CONNECTION_PROXY 4
//#define INTERNET_CONNECTION_MODEM_BUSY 8
DWORD flags;//上网方式
BOOL bOnline=TRUE;//是否在线
bOnline=InternetGetConnectedState(&flags0);
// if(bOnline)//在线
// {
// if ((flags & INTERNET_CONNECTION_MODEM) ==INTERNET_CONNECTION_MODEM)
// {
// cout<<“在线:拨号上网“ << endl;
// }
// if ((flags & INTERNET_CONNECTION_LAN) ==INTERNET_CONNECTION_LAN)
// {
// cout<<“在线:通过局域网“ << endl;
// }
// if ((flags & INTERNET_CONNECTION_PROXY) ==INTERNET_CONNECTION_PROXY)
// {
// cout<<“在线:代理“ << endl;
// }
// if ((flags & INTERNET_CONNECTION_MODEM_BUSY) ==INTERNET_CONNECTION_MODEM_BUSY)
// {
// cout<<“MODEM被其他非INTERNET连接占用“ << endl;
// }
// }
// else
// {
// cout<<“不在线/n“;
// }
return bOnline;
}
BOOL CheckInternetMethord2()
{
DWORD flags;//上网方式
BOOL bOnline = TRUE;//是否在线
bOnline=IsNetworkAlive(&flags);
// if(bOnline && GetLastError() == 0)//在线,调用后要用GetLastError确定是否调用成功
// {
// if ((flags & NETWORK_ALIVE_LAN) ==NETWORK_ALIVE_LAN)
// {
// cout<<“在线:NETWORK_ALIVE_LAN“ << endl;
// }
// if ((flags & NETWORK_ALIVE_WAN) ==NETWORK_ALIVE_WAN)
// {
// cout<<“在线:NETWORK_ALIVE_WAN“ << endl;
// }
// if ((flags & NETWORK_ALIVE_AOL) ==NETWORK_ALIVE_AOL)
// {
// cout<<“在线:NETWORK_ALIVE_AOL“ << endl;
// }
// }
// else
// {
// cout<<“不在线“ << endl;
// }
return bOnline;
}
//说明:
//InternetGetConnectedState():对网络状况不能及时反应
//IsNetworkAlive():可以及时反应网络连通情况,但是需要服务System Event Notification支持(系统默认自动启动该服务)。调用后要用GetLastError确定是否调用成功
bool CheckInternetMethord3()
{
bool bIsInternetAvailable = false;
// Get the required buffer size
DWORD dwBufferSize = 0;
if (ERROR_INSUFFICIENT_BUFFER == GetIpForwardTable(NULL &dwBufferSize false))
{
BYTE *pByte = new BYTE[dwBufferSize];
if (pByte)
{
PMIB_IPFORWARDTABLE pRoutingTable = reinterpret_cast(pByte);
// Attempt to fill buffer with routing table information
if (NO_ERROR == GetIpForwardTable(pRoutingTable &dwBufferSize false))
{
DWORD dwRowCount = pRoutingTable->dwNumEntries; // Get row count
// Look for default route to gateway
for (DWORD dwIndex = 0; dwIndex < dwRowCount; ++dwIndex)
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4543 2014-11-07 13:17 20141106_checkInternetState\TestInternetState\TestCheckInternetState\CheckInternetState.cpp
文件 351 2014-11-07 10:59 20141106_checkInternetState\TestInternetState\TestCheckInternetState\CheckInternetState.h
文件 5694 2014-11-07 13:30 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\BuildLog.htm
文件 28573 2014-11-07 13:18 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\CheckInternetState.obj
文件 4177 2014-11-07 13:18 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\stdafx.obj
文件 2048 2014-11-07 13:18 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\TestCheckInternetState.exe.em
文件 2112 2014-11-07 13:18 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\TestCheckInternetState.exe.em
文件 621 2014-11-07 13:30 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\TestCheckInternetState.exe.intermediate.manifest
文件 56614 2014-11-07 13:18 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\TestCheckInternetState.obj
文件 633856 2014-11-07 13:18 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\vc90.idb
文件 282624 2014-11-07 13:18 20141106_checkInternetState\TestInternetState\TestCheckInternetState\Debug\vc90.pdb
文件 1273 2014-11-06 17:56 20141106_checkInternetState\TestInternetState\TestCheckInternetState\ReadMe.txt
文件 227 2014-11-06 17:56 20141106_checkInternetState\TestInternetState\TestCheckInternetState\stdafx.cpp
文件 229 2014-11-07 10:09 20141106_checkInternetState\TestInternetState\TestCheckInternetState\stdafx.h
文件 498 2014-11-06 17:56 20141106_checkInternetState\TestInternetState\TestCheckInternetState\targetver.h
文件 1150 2014-11-07 11:02 20141106_checkInternetState\TestInternetState\TestCheckInternetState\TestCheckInternetState.cpp
文件 4444 2014-11-07 11:04 20141106_checkInternetState\TestInternetState\TestCheckInternetState\TestCheckInternetState.vcproj
文件 1421 2014-11-07 11:07 20141106_checkInternetState\TestInternetState\TestCheckInternetState\TestCheckInternetState.vcproj.zhangfeng-PC.zhangfeng.user
文件 4321 2014-11-12 18:37 20141106_checkInternetState\TestInternetState\TestInternetState\CheckInternetState.cpp
文件 374 2014-11-12 18:09 20141106_checkInternetState\TestInternetState\TestInternetState\CheckInternetState.h
文件 1819 2014-11-07 13:30 20141106_checkInternetState\TestInternetState\TestInternetState\InternetStatus.cpp
文件 511 2014-11-07 13:16 20141106_checkInternetState\TestInternetState\TestInternetState\InternetStatus.h
文件 2943 2014-11-06 11:11 20141106_checkInternetState\TestInternetState\TestInternetState\ReadMe.txt
文件 21630 2003-07-24 09:52 20141106_checkInternetState\TestInternetState\TestInternetState\res\TestInternetState.ico
文件 373 2014-11-06 11:11 20141106_checkInternetState\TestInternetState\TestInternetState\res\TestInternetState.rc2
文件 540 2014-11-06 11:11 20141106_checkInternetState\TestInternetState\TestInternetState\Resource.h
文件 148 2014-11-06 11:11 20141106_checkInternetState\TestInternetState\TestInternetState\stdafx.cpp
文件 1796 2014-11-06 11:11 20141106_checkInternetState\TestInternetState\TestInternetState\stdafx.h
文件 1030 2014-11-06 11:11 20141106_checkInternetState\TestInternetState\TestInternetState\targetver.h
文件 58952 2014-11-06 11:12 20141106_checkInternetState\TestInternetState\TestInternetState\TestInternetState.aps
............此处省略18个文件信息
相关资源
- 基于MFC的TCP调试助手源码95706
- 基于mfc的多线程文件传输
- MFC数字钟(基于VC6.0)
- VC++MFC小游戏实例教程(实例)+MFC类库
- ChartCtrl控件库(可在VS2019中使用)
- 商品库存管理系统 C++ MFC
- mfc 调用redis
- MFC视频播放器源码(支持avi/wma/mp3等格
- mfc绘图大全(画直线、矩形、椭圆)
- MFC控件重绘
- hook,捕获所有案件,查找所有窗口,
- (学习)VS2010之MFC入门到精通教程
- MFC文档_视图_框架_模板结构体系深入
- 简单员工管理系统(适合初学MFC)
- MFC五子棋游戏
- MFC UDP编程
- MFC的异步网络通讯应用程序
- C++MFC模块讲解,黑发程序员课程整理
- 一个简单而强大的基于MFC的web server源
- 基于MFC的VC++仿QQ浏览器源码(雏形)
- MFCaccess.rar
- VC++MFC课程设计的学生成绩管理系统
- MFC 日历控件 万年历 Calendar自绘
- CrystalDiskInfo-HDD/SSD硬盘信息,SMART信息
- MFC自定义界面HUI,高效简单,含详细
- 仿射密码-Affine cipher
- c++MFC车牌自动识别定位,只能定位和
- mfc+sql 酒店客房管理系统
- 基于图割的图像分割OpenCV+MFC实现
- MFC绘制Bezier曲线B样条曲线曲线拟合
评论
共有 条评论