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

📄 masked_edit2.shtml.htm

📁 一套比较全的编辑框控制教程。。。附源代码。
💻 HTM
字号:
<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="zafir anjum">
<title>edit controls - table of contents</title>
<meta name="description" content="source code for various windows controls">
<meta name="keywords" content="mfc source code edit controls">
</head>

<body background="../di2001.jpg"
tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#ffffff">

<h3 align="center"><font color="#aoao99">a masked edit control with time, date, telephone
number, ip address and post code examples</font></h3>

<hr align="center">
<!-- author and contact details -->

<p>this article was contributed by <a href="mailto:jmd@jvf.co.uk">jeremy davis</a>. </p>

<p><img src="masked_edit2.gif" tppabs="http://www.codeguru.com/editctrl/masked_edit2.gif"
width="311" height="300">&nbsp;<a href="masked_edit2_demo.zip"
tppabs="http://www.codeguru.com/editctrl/masked_edit2_demo.zip">download demo project and
source</a> (37k) or <a href="masked_edit2_source.zip"
tppabs="http://www.codeguru.com/editctrl/masked_edit2_source.zip">download source only</a>
(4k)</p>

<p><strong>updated : </strong><a href="#updates">12th august 1998</a><!-- the article... --></p>

<p>the original source for this code came from <a href="mailto::sam.claret@dial.pipex.com">sam
claret's</a> article <a href="masked_edit.shtml.htm"
tppabs="http://www.codeguru.com/editctrl/masked_edit.shtml">a masked edit control</a>.</p>

<p><strong>ctimeedit</strong><br>
the class that i was originally interested in was his ctimeedit that allowed the editing
of hours and minutes in an edit control. his original code only allowed a maximum 23<sup>rd</sup>
hour, and 59<sup>th</sup> minute, i.e. the standard 24 hour clock. there was no way of
specifying a 12 hour clock or even a 48 hour clock.. for this reason i have added <tt><font
color="#990000">sethours(int hrs)</font></tt>, <tt><font color="#990000">setmins(int mins)</font></tt>to
ctimeedit to allow this, and <tt><font color="#990000">settime(cstring date)</font></tt>,
and <tt><font color="#990000">cstring gettimestr()</font></tt> to extend the use with
other time functions..</p>

<p>as with sam's code... </p>

<pre><font color="#990000"><tt>	#include &lt;afxdao.h&gt;
</pre>
</tt></font>

<p>in a header file such as stdafx.h. then create a cedit box in the dialog editor, and
using classwizard declare a cedit control variable for it such as m_editctrl.next edit the
relevant header file to change the control variable from cedit to ctimeedit. </p>

<p>in a fuction such as oninitdialog either write... </p>

<pre><font color="#990000"><tt>	m_editctrl.settime(coledatetime::getcurrenttime());
</pre>
</tt></font>

<p>or </p>

<pre><font color="#990000"><tt>	m_editctrl.settime(&quot;11:03&quot;);
</pre>
</tt></font>

<p>to set the time and then to set the maximum hours and minutes write... </p>

<pre><font color="#990000"><tt>	m_editctrl.sethours(12);
	m_editctrl.setmins(59);
</pre>
</tt></font>

<p>to return the time in a string rather than a coledatetime object write... </p>

<pre><font color="#990000"><tt>	cstring string = m_editctrl.gettimestr();</tt></font></pre>

<p>the default maximum hours are 24, and the default maximum minutes are 59. </p>

<p>&nbsp;</p>

<p><strong>cmaskedit<br>
</strong>joe ismert asked me how he could use this masked edit class to allow entry of,
for example a telephone number. well cdateedit and ctimeedit are both sub-classes of
cmaskedit. to create your own customised masked edit control you can either create your
own sub-class of cmaskedit for your own unique mask, or use cmaskedit directly. the
following telephone number, ip address, and post code examples all use cmaskdirectly,
however can be placed a their own unique sub-class for which either cdateedit and
ctimeedit can be used as examples.</p>

<blockquote>
  <p><strong>telephone number<br>
  </strong>create a cmaskedit control called for example m_editphonectrl. then in
  oninitdialog write...<br>
  </p>
  <pre><font color="#990000"><tt>
  //cmaskedit - telephone initialisation
  m_editphonectrl.m_bistime    = false;

  //for use with ctimeedit
  m_editphonectrl.m_isdate     = false;

  //for use with cdateedit
  m_editphonectrl.m_busemask   = true;

  //set to use cmaskedit
  m_editphonectrl.m_strmask    = &quot;0000 0000000&quot;;            //the mask string
  m_editphonectrl.m_strliteral = &quot;____ _______&quot;;            //&quot;_&quot; char = character entry
                                                            //&quot; &quot; char = no character entry
  m_editphonectrl.m_str = 0116 2111111&quot;;                    //initial value
  m_editphonectrl.m_strmaskliteral = m_editphonectrl.m_str; //backspace replace string
  m_editphonectrl.setwindowtext(m_editphonectrl.m_str);
</tt></font></pre>
  <p><strong>ip address<br>
  </strong></p>
  <p>create a cmaskedit control called for example m_editipctrl. then in oninitdialog
  write...<br>
  </p>
  <pre><font color="#990000"><tt>
  //cmaskedit - ip address initialisation
  m_editipctrl.m_bistime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = false;
  m_editipctrl.m_isdate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = false;
  m_editipctrl.m_busemask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = true;
  m_editipctrl.m_strmask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;999.999.999.999&quot;;
  m_editipctrl.m_strliteral&nbsp;&nbsp;&nbsp;&nbsp; = &quot;___.___.___.___&quot;;
  m_editipctrl.m_str&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;209.66 .99 .126&quot;;
  m_editipctrl.m_strmaskliteral = m_editipctrl.m_str;
  m_editipctrl.setwindowtext(m_editipctrl.m_str);
</tt></font></pre>
  <p><strong>post code<br>
  </strong></p>
  <p>create a cmaskedit control called for example m_editpcodectrl. then in oninitdialog
  write...<br>
  </p>
  <pre><font color="#990000"><tt>
  //cmaskedit - ipost code initialisation

  m_editpcodectrl.m_bistime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = false;
  m_editpcodectrl.m_isdate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = false;
  m_editpcodectrl.m_busemask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = true;
  m_editpcodectrl.m_strmask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;ll00 0ll&quot;;
  m_editpcodectrl.m_strliteral&nbsp;&nbsp;&nbsp;&nbsp; = &quot;____ ___&quot;;
  m_editpcodectrl.m_str&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;le12 7at&quot;;
  m_editpcodectrl.m_strmaskliteral = m_editpcodectrl.m_str;
  m_editpcodectrl.setwindowtext(m_editpcodectrl.m_str);
</tt></font></pre>
</blockquote>

<blockquote>
  <p align="left"><strong>cmaskedit m_strmask<br>
  </strong>the member variable m_strmask specifies what type of characters can be written
  and where.</p>
  <table border="0" width="31%">
    <tr>
      <td width="20%"><strong>0</strong></td>
      <td width="50%">digit only</td>
    </tr>
    <tr>
      <td width="20%"><strong>9</strong></td>
      <td width="50%">digit or space</td>
    </tr>
    <tr>
      <td width="20%"><strong>#</strong></td>
      <td width="50%">digit or space or + or -</td>
    </tr>
    <tr>
      <td width="20%"><strong>l</strong></td>
      <td width="50%">alpha only</td>
    </tr>
    <tr>
      <td width="20%"><strong>?</strong></td>
      <td width="50%">alpha or space</td>
    </tr>
    <tr>
      <td width="20%"><strong>a</strong></td>
      <td width="50%">alphanumeric</td>
    </tr>
    <tr>
      <td width="20%"><strong>a</strong></td>
      <td width="50%">alphanumeric or space</td>
    </tr>
    <tr>
      <td width="20%"><strong>&amp;</strong></td>
      <td width="50%">all printable characters</td>
    </tr>
  </table>
</blockquote>

<p><a name="updates"></a><strong>updates</strong></p>

<p><strong>12th august 1998<br>
</strong>&nbsp;&nbsp; cmaskedit : added the use of backspace to replace what has already
been typed with another string (by <a href="mailto::rfujimoto@oceania.com">rodney fujimoto</a>).
the examples use the original string as a replacement,&nbsp; however by default the
replacement is blank, thus nothing will be replaced by the backspace key.<br>
&nbsp;&nbsp; provided separate .zip file of masked.cpp and masked.h to demo .zip file.<br>
&nbsp;&nbsp; updated demo .exe.</p>

<p><strong>7th august 1998<br>
</strong>&nbsp;&nbsp; ctimeedit : added settime(cstring date), and cstring gettimestr().<br>
&nbsp;&nbsp; cmaskedit : cured bug with &quot;9&quot; masks not allowing spaces.<br>
&nbsp;&nbsp; updated article and demo .exe, added examples.</p>

<p><strong>27th july 1998<br>
&nbsp;&nbsp; </strong>original version</p>

<p>last updated: 12 august 1998 </p>
<!--comments-->
</body>
</html>

⌨️ 快捷键说明

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