📄 ddx_phone.shtml.htm
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Chris Maunder">
<TITLE>Dialog - Parse phone fields</TITLE>
</HEAD>
<BODY>
<CENTER>
<H3>
<FONT COLOR="#000099">Parse phone fields</FONT></H3></CENTER>
<CENTER>
<H3>
<HR></H3></CENTER>
This article was contributed by <A HREF="mailto:jlundgre@igate.sprint.com">Jeff Lundgren</A>.
<P>Here is a function I use to parse phone fields. I've tested this on
Windows 95/NT with Visual C++ 5.0 SP1/2.
<P>This works by changing the value to a formatted phone number.
<P>I'm sure there could be some code improvements here, and would
appreciate any suggestions anyone might have.
<PRE><TT><FONT COLOR="#990000">
//Definition
void AFXAPI DDX_Phone(CDataExchange* pDX, int nIDC, CString& value);
//Implementation
void AFXAPI DDX_Phone(CDataExchange* pDX, int nIDC, CString& value)
{
HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
if (pDX->m_bSaveAndValidate)
{
int nLen = ::GetWindowTextLength(hWndCtrl);
::GetWindowText(hWndCtrl, value.GetBufferSetLength(nLen),nLen+1);
value.ReleaseBuffer();
}
else
{
CString newValue;
for(int x=0; x < value.GetLength();x++)
{
if(value[x] != '(' &&
value[x] != ')' &&
value[x] != '-' &&
value[x] != ' ' &&
value[x] != '.')
newValue += value[x];
}
if(newValue.GetLength()==7)
newValue.Format("%s-%s",newValue.Left(3),newValue.Right(4));
else if(newValue.GetLength()==10)
newValue.Format("(%s)%s-%s",newValue.Left(3),newValue.Mid(3,3),newValue.Right(4));
else if(newValue.GetLength()>10)
newValue.Format("(%s) %s-%s%s",newValue.Left(3),newValue.Mid(3,3),newValue.Mid(6,4),newValue.Right(newValue.GetLength()-10));
else
newValue = value;
AfxSetWindowText(hWndCtrl, newValue);
}
}
</FONT></TT></PRE>
<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="../index.htm" tppabs="http://www.codeguru.com/">Goto HomePage</A></FONT></TD>
<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>© 1997 Zafir Anjum</FONT> </CENTER>
</TD>
<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A> </FONT></DIV>
</TD>
</TR>
</TABLE>
<CENTER><FONT SIZE=-2></FONT></CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -