А куда это вставлять?
C | 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
| WNDPROC wpOrigEditProc;
LRESULT APIENTRY EditBoxProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hwndEdit;
switch(uMsg)
{
case WM_INITDIALOG:
{
hwndEdit = GetDlgItem(hwndDlg, ID_EDIT);
wpOrigEditProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) EditSubclassProc);
return TRUE;
}
case WM_DESTROY:
{
SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) wpOrigEditProc);
break;
}
}
return FALSE;
UNREFERENCED_PARAMETER(lParam);
}
LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CHAR:
{
смотрим, какой символ введён ...
...
...
}
case WM_GETDLGCODE: return DLGC_WANTALLKEYS;
}
return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam);
} |
|
Здесь:
C | 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
| #include "stdafx.h"
#include "Bone edit.h"
#include <windowsx.h>
#include <string>
#include <commdlg.h>
#include <commctrl.h>
#define MAX_LOADSTRING 100
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hE;
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
MSG msg;
HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_BONEEDIT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
if(!InitInstance (hInstance, nCmdShow)) return FALSE;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BONEEDIT));
while(GetMessage(&msg, NULL, 0, 0))
{
if(TranslateAccelerator(msg.hwnd, hAccelTable, &msg) != 0) continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BONEEDIT));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_BONEEDIT);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow(szWindowClass, szTitle, WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL, hInstance, NULL);
if(!hWnd) return FALSE;
hE = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, L"", WS_CHILD | WS_VISIBLE | WS_DLGFRAME | ES_NOHIDESEL | ES_MULTILINE, 10, 102, 462, 110, hWnd, (HMENU)4, hInstance, NULL);
Edit_LimitText(hE, 510);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
{
if(LOWORD(wParam) == 1)
{
if(HIWORD(wParam) != EN_CHANGE) break;
wchar_t buf[256]; Edit_GetText(hE, buf, sizeof(buf)); // Текст из окна
wchar_t c[2] = {buf[wcsspn(buf, L"0123456789 ")],'\0'};
if(c[0]) // Если найдёт неверный сивол вернёт его
{
int l = wcscspn(buf, c); // Вернёт номер неверного символа в строке
buf[l] = L'\0'; // удалить из строки всё что после этого символа
Edit_SetText(hE, buf); // Вставить обратно в окно исправленый текст
Edit_SetSel(hE, l, l); // Установить курсор в конец строки
MessageBeep(0xFFFFFFFF); // Воспроизвести сигнал неверного ввода
}
int k = 0, i = -1, len = wcslen(buf);
while(++i < len)
{
if(buf[i] != L' ')
{
if(++k > 2)
{
buf[i] = L' ';
Edit_SetText(hE, buf);
Edit_SetSel(hE, i + 1, i + 1);
MessageBeep(0xFFFFFFFF);
break;
}
}
else k = 0;
}
break;
}
break;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
} |
|
Просто так:
C | 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
| #include "stdafx.h"
#include "Bone edit.h"
#include <windowsx.h>
#include <string>
#include <commdlg.h>
#include <commctrl.h>
#define MAX_LOADSTRING 100
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
WNDPROC wpOrigEditProc;
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT APIENTRY EditBoxProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HWND hE;
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
MSG msg;
HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_BONEEDIT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
if(!InitInstance (hInstance, nCmdShow)) return FALSE;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BONEEDIT));
while(GetMessage(&msg, NULL, 0, 0))
{
if(TranslateAccelerator(msg.hwnd, hAccelTable, &msg) != 0) continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BONEEDIT));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_BONEEDIT);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow(szWindowClass, szTitle, WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL, hInstance, NULL);
if(!hWnd) return FALSE;
hE = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, L"", WS_CHILD | WS_VISIBLE | WS_DLGFRAME | ES_NOHIDESEL | ES_MULTILINE, 10, 102, 462, 110, hWnd, (HMENU)4, hInstance, NULL);
Edit_LimitText(hE, 510);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
{
if(LOWORD(wParam) == 1)
{
if(HIWORD(wParam) != EN_CHANGE) break;
wchar_t buf[256]; Edit_GetText(hE, buf, sizeof(buf)); // Текст из окна
wchar_t c[2] = {buf[wcsspn(buf, L"0123456789 ")],'\0'};
if(c[0]) // Если найдёт неверный сивол вернёт его
{
int l = wcscspn(buf, c); // Вернёт номер неверного символа в строке
buf[l] = L'\0'; // удалить из строки всё что после этого символа
Edit_SetText(hE, buf); // Вставить обратно в окно исправленый текст
Edit_SetSel(hE, l, l); // Установить курсор в конец строки
MessageBeep(0xFFFFFFFF); // Воспроизвести сигнал неверного ввода
}
int k = 0, i = -1, len = wcslen(buf);
while(++i < len)
{
if(buf[i] != L' ')
{
if(++k > 2)
{
buf[i] = L' ';
Edit_SetText(hE, buf);
Edit_SetSel(hE, i + 1, i + 1);
MessageBeep(0xFFFFFFFF);
break;
}
}
else k = 0;
}
break;
}
break;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT APIENTRY EditBoxProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hwndEdit;
switch(uMsg)
{
case WM_INITDIALOG:
{
hwndEdit = GetDlgItem(hwndDlg, ID_EDIT);
wpOrigEditProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) EditSubclassProc);
return TRUE;
}
case WM_DESTROY:
{
SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) wpOrigEditProc);
break;
}
}
return FALSE;
UNREFERENCED_PARAMETER(lParam);
}
LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CHAR:
{
смотрим, какой символ введён ...
...
...
}
case WM_GETDLGCODE: return DLGC_WANTALLKEYS;
}
return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam);
} |
|
?
0
|