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

📄 simplenumericedit.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">simple numeric edit control </font></h3>

<hr>
<!-- author and contact details -->

<p>this article was contributed by <a href="mailto:bob_place@hotmail.com">bob place</a>. <!-- sample image - gif or jpg --> <!-- <p><img src="[image filename here]" tppabs="http://www.codeguru.com/editctrl/%5bimage filename here%5d" > -->
<!-- environment eg nt 4.0 sp3, vc6.0 sp1 --><!-- <p><u>environment:</u> ****** --><!-- text / source code --></p>

<p>in our application we needed several edit controls to accept only numbers. one might
think to use the number option on the resource editor, but unfortunately that did not
allow us to enter the &quot;-&quot; minus sign. so we needed a different solution. </p>

<p>we looked at codeguru to find a simple maskedit control. there were several to choose
from but unfortunately they all did much more that we needed, and the cursor movement,
backspace and delete were not exactly the same as the standard edit control (which was a
requirement). with nothing else to do, we (like so many others other there) simply wrote
our own. </p>

<p>it was unbelievably simple. here are the steps we took: </p>

<p>1: created a new class using class wizard where the base class was cedit. 2: added this
handler for wm_char <!-- start a block of source code --> </p>

<pre><tt><font color="#990000">
void maskedit::onchar(uint nchar, uint nrepcnt, uint nflags)
{
 cstring holder =
  &quot;`~!@#$%^&amp;*()_+|=\\qwertyuiop[]asdfghjkl;'zxcvbnm,./qwertyuiop{}asdfghjkl:/\&quot;
  &quot;zxcvbnm<>/&quot;;

 if(holder.find(nchar)!=-1)
  return;

 cedit::onchar(nchar, nrepcnt, nflags);
}
<!-- end the block of source code -->
</font></tt></pre>

<p>that's it. no it does not check for every possibility in the world, but it does exactly
what we needed. it allows us to have an edit control that works exactly like the default,
but only allows numbers and the &quot;-&quot; sign. there is probably a more elegant way
we could have done this, but this was fast, and it worked. <!-- demo project --> <!-- <p><a href="../../tppmsgs/msgs0.htm#81" tppabs="http://www.codeguru.com/editctrl/%5bdemo project zip file name here%5d">download demo project - [size in kb] kb</a> --> <!-- zipped source --> <!-- <p><a href="../../tppmsgs/msgs0.htm#82" tppabs="http://www.codeguru.com/editctrl/%5bsource code zip file name here%5d">download source - [size in kb] kb</a> --> <!-- posted / update  date month day, year (eg august 11, 1998) - add to the list --> </p>

<p>date posted: december 8, 1998 <!--comments--> </p>
</body>
</html>

⌨️ 快捷键说明

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