vs2005中提供有IP Address控件,可以方便的输入IPv4地址,wxWidgets没有提供类似插件,不过可以利用PlatformSDK自己定义一个
1,声明一个基于wxControl的类,类名为wxIpAddr,实现如下:
wxIpCtrl.h
#ifndef _WXIPCTRL_H_
#define
_WXIPCTRL_H_
#if
defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma
interface "wxIpCtrl.h"
#endif
#include
"
CommCtrl.h
" // SDK必须用到的头文件
#include
"
wx/msw/private.h
"
class
WXDLLEXPORT wxIpAddr:
public
wxControl

...
{
public:
wxIpAddr(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxT("SysIPAddress32"))

...{
Create(parent, id, value, pos, size, style, validator, name);
}
bool Create(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxT("SysIPAddress32"));
~wxIpAddr();
virtual wxSize DoGetBestSize() const;// 为IP address控件定义一个合适的大小
wxUint32 GetIpAddr32();// 得到一个32位IP地址(大字节序)
wxString GetIPAddStr();// 得到一个xxx.xxx.xxx.xxx格式的字符串
private:

}
;
#endif
2,方法实现:
wxIpCtrl.cpp
#if
defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma
implementation "wxIpCtrl.h"
#endif

//
For compilers that support precompilation, includes "wx/wx.h".
#include
"
wx/wxprec.h
"

#ifdef __BORLANDC__
#pragma
hdrstop
#endif

#ifndef WX_PRECOMP
#include
"
wx/wx.h
"
#endif
#include
"
wxIpCtrl.h
"
wxIpAddr::
~
wxIpAddr()

...
{

}
bool
wxIpAddr::Create(wxWindow
*
parent, wxWindowID id,
const
wxString
&
value,
const
wxPoint
&
pos,
const
wxSize
&
size,
long
style,
const
wxValidator
&
validator,
const
wxString
&
name)