IP Address Control
If you're writing an Internet-aware program, you might have already wondered howyou're going to validate certain kinds of input from your users. One thing you could ask
for is an IP address, like this one:
205.210.40.1
IP addresses always have four parts, separated by dots, and each part is always a number
between 1 and 255. The IP address picker guarantees that the user will give you
information that meets this format.
To try it out, add yet another line to OnCreate(), this time a call to CreateIPAddress().
Add the function to the class. The code is really simple; just add a call to Create():
void CCommonView::CreateIPAddress()
{
m_ipaddress.Create(WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(470,40,650,65), this, IDC_IPADDRESS);
}
Remember to add a resource ID for IDC_IPADDRESS. No special styles are related to this
simple control. There are some useful member functions to get, set, clear, or otherwise
manipulate the address. Check them out in the online documentation.
Build and run Common, and try entering numbers or letters into the parts of the field.
Notice how the control quietly fixes bad values (enter 999 into one part, for example)
and how it moves you along from part to part as you enter the third digit or type a dot.
It's a simple control, but if you need to obtain IP addresses from the user, this is the only
way to fly.
No comments:
Post a Comment