![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
nCnt
=
m_serverlist.GetItemCount();
//
获得当前在线的主机数量
2 nItem = m_serverlist.InsertItem(nCnt,(_bstr_t)ip, 0 ); // nItem=新增加的记录,nItem值由自动排序生成,所以数值不会顺序生成
3
4 if (nCnt > 1 ) // 最后一项要大于1
5 {
6 -- nCnt;
7 int i2 = 1 ;
8 // for(Tmpi=nItem;Tmpi<++nItem;Tmpi++ )
9 // { // nItem值是随机的,主机上线会自动按IP地址对nItem进行排序
10 // 先判断外网IP和主机名称:
11 // Tmpi=nItem+1;
12 for (Tmpi = nItem + 1 ;Tmpi < nItem + 3 ;Tmpi ++ )
13 {
14 if (m_serverlist.GetItemText(nItem, 0 ) == m_serverlist.GetItemText(Tmpi, 0 ) && m_serverlist.GetItemText(nItem, 1 ) == m_serverlist.GetItemText(Tmpi, 1 ))
15 // if(m_serverlist.GetItemText(nItem,0 ) == m_serverlist.GetItemText(Tmpi,0))
16 {
17 // MessageBox("Host online repeat!","WARN");
18 // MessageBox(m_serverlist.GetItemText(Tmpi,0));
19
20 m_serverlist.DeleteItem(Tmpi); // 删除以前的重复IP地址,保留最新的连接
21
22 }
23 // --Online;
24 nCnt = m_serverlist.GetItemCount();
25 temp.Format( " Current Online: %d hosts " ,nCnt);
26 AfxGetMainWnd() -> SetDlgItemText(IDC_STATIC_1, temp);
27 m_serverlist.Update( 0 );
28 }
2 nItem = m_serverlist.InsertItem(nCnt,(_bstr_t)ip, 0 ); // nItem=新增加的记录,nItem值由自动排序生成,所以数值不会顺序生成
3
4 if (nCnt > 1 ) // 最后一项要大于1
5 {
6 -- nCnt;
7 int i2 = 1 ;
8 // for(Tmpi=nItem;Tmpi<++nItem;Tmpi++ )
9 // { // nItem值是随机的,主机上线会自动按IP地址对nItem进行排序
10 // 先判断外网IP和主机名称:
11 // Tmpi=nItem+1;
12 for (Tmpi = nItem + 1 ;Tmpi < nItem + 3 ;Tmpi ++ )
13 {
14 if (m_serverlist.GetItemText(nItem, 0 ) == m_serverlist.GetItemText(Tmpi, 0 ) && m_serverlist.GetItemText(nItem, 1 ) == m_serverlist.GetItemText(Tmpi, 1 ))
15 // if(m_serverlist.GetItemText(nItem,0 ) == m_serverlist.GetItemText(Tmpi,0))
16 {
17 // MessageBox("Host online repeat!","WARN");
18 // MessageBox(m_serverlist.GetItemText(Tmpi,0));
19
20 m_serverlist.DeleteItem(Tmpi); // 删除以前的重复IP地址,保留最新的连接
21
22 }
23 // --Online;
24 nCnt = m_serverlist.GetItemCount();
25 temp.Format( " Current Online: %d hosts " ,nCnt);
26 AfxGetMainWnd() -> SetDlgItemText(IDC_STATIC_1, temp);
27 m_serverlist.Update( 0 );
28 }