MFC:整数编辑框CEdit
来源:互联网 发布:儿童画画软件 编辑:程序博客网 时间:2024/05/17 21:41
头文件(NumEdit.h)代码:
#pragma onceclass CNumEdit : public CEdit{DECLARE_DYNAMIC(CNumEdit)public:CNumEdit();virtual ~CNumEdit();protected:DECLARE_MESSAGE_MAP()public:afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);};
源文件(NumEdit.cpp)代码:#include "stdafx.h"#include "NumEdit.h"IMPLEMENT_DYNAMIC(CNumEdit, CEdit)CNumEdit::CNumEdit(){}CNumEdit::~CNumEdit(){}BEGIN_MESSAGE_MAP(CNumEdit, CEdit)ON_WM_CHAR()ON_WM_CTLCOLOR_REFLECT()END_MESSAGE_MAP()void CNumEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags){TCHAR ch = nChar;CString strText;if (ch == '-'){GetWindowText(strText);int len = strText.GetLength();if (len <= 0){CEdit::OnChar(nChar, nRepCnt, nFlags);}else {if (strText.Find('-') < 0){SetSel(0, 0, FALSE);CEdit::OnChar(nChar, nRepCnt, nFlags);}}}else if (ch >= '0' && ch <= '9'){GetWindowText(strText);if (strText.Find('0') == 0){//this->Clear();this->SetWindowText(_T(""));}if (strText.Find('-') == 0 && 1 == HIWORD(this->GetSel()) && ch == '0')//int nSel = HIWORD(this->GetSel()); 获取光标位置{return;}CEdit::OnChar(nChar, nRepCnt, nFlags);}else if (ch == 0x08 || ch == 0x09){CEdit::OnChar(nChar, nRepCnt, nFlags);}return;}HBRUSH CNumEdit::CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/){CDC* dc = GetDC();CRect rect;GetClientRect(rect);rect.InflateRect(1, 1, 1, 1);CBrush brush(FrameRectColor);dc->FrameRect(rect, &brush);DeleteObject(brush);ReleaseDC(dc);return NULL;}
阅读全文
0 0
- MFC:整数编辑框CEdit
- [MFC]CEdit编辑框类
- MFC CEdit获取编辑框内容
- mfc中使用CEdit为编辑框设置字体
- MFC中将CEdit设置光标当前位置在编辑框最后
- 编辑框CEdit
- 编辑框(CEdit)汇总.
- MFC CEdit编辑框内容不能选中和复制原因和解决
- 自绘编辑框CEdit(继承CEdit方式)
- MFC--CEdit
- CEdit获取编辑框的内容
- VC++ 实现CEdit编辑框输入小数!
- CEdit获取编辑框的内容
- CEdit获取编辑框的内容
- 编辑框CEdit自动换行简单设置
- CEdit编辑框透明的实现
- 如何禁止编辑框输入汉字CEdit
- CEdit获取编辑框的内容
- 网络的那些事之ACL
- 高性能Mysql笔记 (4) --库表结构优化
- 基于canvas的图像有机物检测
- 解决ajax跨域问题的多种方法
- 记录
- MFC:整数编辑框CEdit
- 用代码刷新ODBC连接表
- JavaSE学习--集合02
- 【字符编码】ASCII、Unicode和UTF-8的区别
- powerDesigner生成sql一些常见问题解决
- centOS安装telnet(在线和rpm包安装)
- BZOJ2120 数颜色 分块
- Python中函数传递参数有四种形式
- 倒计时5s