夜晚真是做事的好时候,上次搞了半天获取IP地址,没成功,这次整理了一下思路,仔细看了下wxWidgets的文档(英文废物继续啃E文资料中....)一次性成功,今天用的获取本机IP方法的前提是需要得到本地计算机名.
 
直接贴主要的代码片段就是了,做备忘
InBlock.gifvoid ttFrame::showtxt(wxMouseEvent &event
InBlock.gif
InBlock.gif 
InBlock.gif        //创建wxIPV4address对象 
InBlock.gif        wxIPV4address addr; 
InBlock.gif        //获得本地计算机名 
InBlock.gif        wxString computerName=::wxGetFullHostName(); 
InBlock.gif        //获得当前用户名 
InBlock.gif        wxString username=::wxGetUserId(); 
InBlock.gif        //wxIPV4address的hostname属性赋值("计算机名") 
InBlock.gif        addr.Hostname(computerName); 
InBlock.gif        //获得IP地址 
InBlock.gif        wxString ipaddr = addr.IPAddress(); 
InBlock.gif 
InBlock.gif        //输出数据到文本框 
InBlock.gif        txt_ip->AppendText(ipaddr); 
InBlock.gif 
InBlock.gif        txt_cmpname->AppendText(computerName); 
InBlock.gif 
InBlock.gif        txt_username->AppendText(username); 
InBlock.gif 
InBlock.gif}