工作问题积累(三)程序中判断本地网络是否中断 C++

来源:互联网 发布:风云2坐骑进阶数据 编辑:程序博客网 时间:2024/06/06 01:09

以下是步骤:

1.构造判断网络是否断开的函数

void CQueenMainDlg::Fun_InternetGetConnectedState(){ DWORD nFlags;//上网方式 BOOL m_online = TRUE; m_online = InternetGetConnectedState(&nFlags,0); if (m_online){ //本地联网 }else{ //网络已经断开 }}


 

2.设置一个定时器,定时检查

#define TIMER_NETWORK 0x3322


 

3.在OnInitDialog()函数中启动定时器

Settimer(TIMER_NETWORK,1000,NULL);//此处1000表示1000毫秒,单位是ms


 

4.在onTimer()函数中调用 Fun_InternetGetConnectedState()

  

if(nIDEvent == TIMER_NETWORK) { Fun_InternetGetConnectedState(); }



 

0 0
原创粉丝点击