EditEx.cpp
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* CC/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "EditEx.h"
CEditEx::CEditEx()
{
}
CEditEx::~CEditEx()
{
}
void CEditEx::CheckNumber(const string &intput, string &output)
{
if(intput.empty())
return;
unsigned char chCurrent = 0;
unsigned char chNext = 0;
for(unsigned int i = 0; i < intput.length(); i++)
{
chCurrent = intput[i];
chNext = intput[i + 1];
if(chCurrent >= 48 && chCurrent <= 57)// 当前字符是半角数字
{
output += chCurrent;
}
else if(chCurrent < 163)// 当前字符为其他单字节编码字符
{
}
else if(chCurrent == 163 && chNext >= 176 && chNext <= 185)// 当前字符为全角数字
{
unsigned char temp = chNext - 128;
output += temp;
i++;// 跳过双字节编码字符的第二字节
}
else// 中文及其他全角字符
{
i++;// 跳过双字节编码字符的第二字节
}
}
}
LRESULT CEditEx::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_PASTE)
{
if(IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard())
{
HGLOBAL hGlobalClip = GetClipboardData(CF_TEXT);
char *pDataBuf = static_cast<char *>(GlobalLock(hGlobalClip));
string strInput(pDataBuf);
GlobalUnlock(hGlobalClip);
string strOutput;
CheckNumber(strInput, strOutput);
if(EmptyClipboard())
{
hGlobalClip = GlobalAlloc(GHND, strOutput.length() + 1);
pDataBuf = static_cast<char *>(GlobalLock(hGlobalClip));
strcpy(pDataBuf, strOutput.c_str());
GlobalUnlock(hGlobalClip);
SetClipboardData(CF_TEXT, hGlobalClip);
}
CloseClipboard();
}
}
else if(message == WM_CHAR)
{
BYTE ch = LOBYTE(LOWORD(wParam));
if(!isdigit(ch) && ch != 8 && ch != 'c' - 'a' + 1 && ch != 'v' - 'a' + 1 && ch != 'x' - 'a' + 1)
return 0;
}
return CEdit::WindowProc(message, wParam, lParam);
}