⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip_addr_masked_edit.shtml.htm

📁 mfc资料集合5
💻 HTM
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Zafir Anjum">
   <TITLE>Miscellaneous - IP Address Masked Edit</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><A HREF="http://209.66.99.126/cgi/ads.cgi?advert=catalyst"><IMG SRC="../banners/catalyst.jpg" tppabs="http://www.codeguru.com/banners/catalyst.jpg" HEIGHT=60 WIDTH=468 ALT="Catalyst Development" BORDER=2></A><BR><SMALL><A HREF="http://209.66.99.126/cgi/ads.cgi?advert=catalyst">Click here for Free ActiveX Control</A></SMALL><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="iptest.zip" tppabs="http://www.codeguru.com/misc/iptest.zip">Download sample</a>.

<p><img src="ip_addr_masked_edit.gif" tppabs="http://www.codeguru.com/misc/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 nor have I tried to
create one dynamically in a dialog.

<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>How to Use the IP Address Custom Control</h3>

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

<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;
		void DDX_IPAddr(CDataExchange* pDX, int nIDC, unsigned char* nAddr);
</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>

  Add the following routine in the dialog class implementation; substitute the
  dialog class name for "YourDialog::"


<PRE><TT><FONT COLOR="#990000">
void YourDialog::DDX_IPAddr(CDataExchange* pDX, int nIDC, unsigned char* nAddr)
{
	IPADDR x;										// Temp for address

	CIPAddrCtl* pIPAddrCtl = (CIPAddrCtl*) GetDlgItem(nIDC);
	if (!pDX->m_bSaveAndValidate)
	{
		// Load IP address control with current data
		x.nAddr1 = nAddr[0];						// Copy address bytes over
		x.nAddr2 = nAddr[1];
		x.nAddr3 = nAddr[2];
		x.nAddr4 = nAddr[3];
		pIPAddrCtl->SetAddress(&x);
	}
	else
	{
		// Save contents of IP address control
		BOOL bStatus = pIPAddrCtl->GetAddress(TRUE, &x);
		if (!bStatus)
		{
			pDX->Fail();
		}
		nAddr[0] = (char) x.nAddr1;
		nAddr[1] = (char) x.nAddr2;
		nAddr[2] = (char) x.nAddr3;
		nAddr[3] = (char) x.nAddr4;
	}

}
</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>&copy; 1997 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>
<CENTER><IMG SRC="../cgi/Count.cgi-ft=2&dd=E-df=misc_ip_addr_mask_edit.cnt" tppabs="http://www.codeguru.com/cgi/Count.cgi?ft=2&dd=E%7cdf=misc_ip_addr_mask_edit.cnt" ALIGN="BOTTOM" BORDER="0"></CENTER>
</BODY>
</HTML>

⌨️ 快捷键说明

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