Why reinvent the wheel? You'd use the CIPAddressCtrl that comes with MFC.
Main Topics
Browse All TopicsHow do I implement an Edit box which will have fixed digits and dots between digits? The kind of control you find in TCP/IP protocol setup.Could I have some example code please.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You can use some kind of mask edit control. Have a look to:
http://www.codeproject.com
Some more examples of validating edit controls at:
http://www.codeproject.com
I have used the maskedit control without problems with eVC++, here is an IP variation of the control from codeproject. I have translated it, hope there are not errors:
ipmaskedit.h
---------------
#include "maskedit.h" /* original maskedit control, also you must add maskedit.cpp to your project */
class CEditIPAddr : public CMaskEdit
{
public:
typedef struct {
unsigned dir1:8;
unsigned dir2:8;
unsigned dir3:8;
unsigned dir4:8;
} TIPAddr;
public:
DWORD m_Address;
CEditIPAddr () : CEditIPAddr () {
m_Address= 0;
}
virtual void PreSubclassWindow() {
Init("[0-2][0-9][0-9].[0-2
CMaskEdit::PreSubclassWind
}
static void AFXAPI DDX_EditIPAddr (CDataExchange* pDX, int nIDC, CEditIPAddr & rControl, DWORD& addr);
static void AFXAPI DDV_EditIPAddr(CDataExchan
};
IPmaskedit.cpp
-----------------
#include "ipmaskedit.h"
void AFXAPI CEditIPAddr::DDX_CEditIPAd
{
DDX_Control(pDX, nIDC, (CWnd&)rControl);
CString data;
TIPAddr IPaddr;
if (!pDX->m_bSaveAndValidate)
memcpy(&IPaddr, &addr, sizeof(IPaddr));
data.Format(TEXT("%03i.%03
rControl.SetData(data);
} else {
data = rControl.GetData();
IPaddr.dir4 = LOBYTE(_ttoi(data.Mid(0,3)
IPaddr.dir3 = LOBYTE(_ttoi(data.Mid(4,3)
IPaddr.dir2 = LOBYTE(_ttoi(data.Mid(8,3)
IPaddr.dir1 = LOBYTE(_ttoi(data.Mid(12,3
memcpy(&addr, &IPaddr, sizeof(addr));
}
}
void AFXAPI CEditIPAddr::DDV_CEditIPAd
{
if (pDX->m_bSaveAndValidate) {
CString data = rControl.GetData();
int dir4 = _ttoi(data.Mid( 0,3));
int dir3 = _ttoi(data.Mid( 4,3));
int dir2 = _ttoi(data.Mid( 8,3));
int dir1 = _ttoi(data.Mid(12,3));
if (dir1*dir2*dir3*dir4==0 || dir1>255 || dir2>255 || dir3>255 || dir4>255) {
::MessageBox(NULL, TEXT("Values must be between 1 and 255."), TEXT("IP Address Error"), MB_OK|MB_ICONEXCLAMATION);
pDX->Fail();
rControl.SetFocus();
}
}
}
Business Accounts
Answer for Membership
by: SteHPosted on 2004-11-25 at 08:15:09ID: 12675566
Have a look at lidating_e dit_contro l.htm
http://www.flounder.com/va
on how to modify an edit control. Instead of changing the background you only change display to show a dot after at most 3 digits.