ip_addr_masked_edit.shtml

来自「mfc资源大全包含MFC编程各个方面的源码」· SHTML 代码 · 共 153 行

SHTML
153
字号
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Scott Miller">
   <!- Last Updated: 05/02/1998->
   <TITLE>Miscellaneous - IP Address Masked Edit</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><A HREF="http://www.codeguru.com/cgi/ads.cgi?advert=myad2"><IMG SRC="http://209.66.99.126/advertise2.gif" ALT="" BORDER=2></A><td>
</tr>
</table>


<CENTER>
<H3>
<FONT COLOR="#AOAO99">IP Address Masked Edit</FONT></H3></CENTER>

<CENTER>
<H3>

<HR></H3></CENTER>

<p>This article was contributed by <A HREF="mailto:dziedzic@ma.ultranet.com">Joseph A. Dziedzic</A>. 
This code actually creates a custom control, instead of using an edit control. 
<a href="ip_addr_masked_edit.zip">Download sample</a>.

<p><img src="ip_addr_masked_edit.gif" width="284"
height="175"></p>


<p>
<p>IPTest.exe demonstrates an MFC-based custom control which is very
similar to the one used in the Windows NT 4.0 "Network" applet in
Control Panel.  The custom control can be used in a dialog or a
property page; I haven't tried it in a form.

<p>The control is provided free of charge with the caveat that no
warranty is expressed or implied.  Feel free to email me if you
discover any nasty bugs.

<br>Joseph A. Dziedzic
<br>dziedzic@ma.ultranet.com

<h3>Changes from the original (September 1997) version</h3>

<ol>
<li>The control now validates fields as data is entered for values
greater than 255.  If you want to defer validation until
DDX time (the old mode of operation), specify the style bit
IPAS_NOVALIDATE (defined in IPAddr.h) when creating the control.

<li>The DDX_IPAddr routine has been moved into IPAddr.cpp.  You can
use this default implementation, or write your own.  There is a
version that works with an array of bytes as well as a string of
"."-separated fields.

<li>A few tweaks were made so the control matches the one used in
Windows 95/NT's Network Control Panel applet.  Specifically,
space is now accepted as an indication to move to the next
address field and focus is advanced to the next address field as
soon as three numeric characters have been entered in a field.

<li>The control now has a Create method to allow dynamic creation.

<li>A number of bugs were fixed including: handling of the Delete key
and use of the control on a property page.

<li>The structure named IPADDR (used to pass IP addresses in Windows
messages) was renamed to avoid a conflict with a typedef in the
include file ras.h; the structure is now called IPA_ADDR.  (Most
users of the control won't notice this change.)

<li>The messages to and from the control were renamed from IPMxxx
to IPAMxxx to avoid conflicts with the IE 4 common controls DLL.
</ol>


<h3>How to Use the IP Address Custom Control</h3>

(See IPTestDlg.h and IPTestDlg.cpp for the code outlined below)

<h4>Add the files IPAddr.cpp and IPAddr.h to your project </h4>
These files are the only ones in IPTest.zip that you'll need.

<h4>Add a custom control to a dialog resource </h4>
Size the control to
90 x 13 Dialog Units.  Set the Class to "IPAddr" and the style
to 0x50810000 (WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP).

<h4>Edit the dialog class definition (.h) file as follows:</h4>

  Add a member variable after the closing }}AFX_DATA line:

<PRE><TT><FONT COLOR="#990000">
	unsigned char m_nAddr[4];
</FONT></TT></PRE>

  Add the following lines after the DECLARE_MESSAGE_MAP macro:

<PRE><TT><FONT COLOR="#990000">
	private:
		CIPAddrCtl* m_pIPAddrCtl;
</FONT></TT></PRE>

<h4>Edit the dialog class implementation (.cpp) file as follows:</h4>

  Add the following lines after the closing }}AFX_DATA_INIT line:
<PRE><TT><FONT COLOR="#990000">
	m_pIPAddrCtl = NULL;
	memset(m_nAddr, 0, 4);
</FONT></TT></PRE>

  Add the following lines after the call to CDialog::DoDataExchange in the
  dialog class implementation of ::DoDataExchange:

<PRE><TT><FONT COLOR="#990000">
	// Can't hack DDX_Control'ing the IP Address control since the control code subclasses the control behind our back
	// Fortunately, that means we can do *one* GetDlgItem call and salt away the returned CWnd-derived
	// object pointer for use during the entire dialog
	if (NULL == m_pIPAddrCtl)
		m_pIPAddrCtl = (CIPAddrCtl*) GetDlgItem(IDC_IPADDR);
	ASSERT(NULL != m_pIPAddrCtl);
</FONT></TT></PRE>

  Add the following line after the closing }}AFX_DATA_MAP line:

<PRE><TT><FONT COLOR="#990000">
	DDX_IPAddr(pDX, IDC_IPADDR, m_nAddr);
</FONT></TT></PRE>



<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="http://www.codeguru.com">Goto HomePage</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; 1998 Zafir Anjum</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?