MFC ListCtrl和IP控件的使用杂记

ListCtrl中选中内容的提取

添加一个 list 控件 变量 m_list:

POSITION pos = m_list.GetFirstSelectedItemPosition();

if (pos != NULL)
{
    int nItem = m_list.GetNextSelectedItem(pos);
    CString strText = m_list.GetItemText(nItem,4);
    pos = 0;
}

// 4 为 第几列

 CIPAddressCtrl类的使用(IP地址与CString的互相转化)

//将CString   型IP地址在IPAddressCtrl中显示  
CString   strIP="192.168.0.10";  
DWORD   dwIP;  
dwIP   =   inet_addr(strIP);  
unsigned   char   *pIP   =   (unsigned   char*)&dwIP;  
m_ipAddr.SetAddress(*pIP,   *(pIP+1),   *(pIP+2),   *(pIP+3));  

//将IPAddressCtrl中的IP地址获得并转换成CString型  
unsigned   char   *pIP;  
CString   strIP;  
DWORD   dwIP;  
m_ipAddr.GetAddress(dwIP);  
pIP   =   (unsigned   char*)&dwIP;  
strIP.Format("%u.%u.%u.%u",*(pIP+3),   *(pIP+2),   *(pIP+1),   *pIP); 

//CIPAddressCtrl的用法
CIPAddressCtrl的值转换成CString,CString转换成CIPAddressCtrl
CString strIP="192.168.1.184";
m_IPAddr.SetWindowText(strIP);
CString strIP;
m_IPAddr.GetWindowText(strIP);

CString strIP="192.168.1.184";
DWORD dwAddress= ntohl( inet_addr(strIP));
m_IPAddr.SetAddress(dwAddress);

//为控件设置数据
m_addr.SetAddress(192,168,0,2);
//从控件得到数据
BYTE b1,b2,b3,b4;
m_addr.GetAddress(b1,b2,b3,b4);

 

 

posted @ 2013-01-03 10:55  cococo点点  阅读(544)  评论(0编辑  收藏  举报