-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextbox.c
More file actions
124 lines (107 loc) · 3.53 KB
/
textbox.c
File metadata and controls
124 lines (107 loc) · 3.53 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
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
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void AddControls(HWND hwnd);
HWND hEdit;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
const char CLASS_NAME[] = "MyWindowClass";
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
wc.lpfnWndProc = WindowProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&wc)) {
MessageBox(NULL, "Window registration failed!", "Error", MB_OK | MB_ICONERROR);
return 1;
}
HWND hwnd = CreateWindowEx(
0,
CLASS_NAME,
"My First Textbox",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
800, 600,
NULL,
NULL,
hInstance,
NULL
);
if (!hwnd) {
MessageBox(NULL, "Window creation failed!", "Error", MB_OK | MB_ICONERROR);
return 1;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_CREATE:
AddControls(hwnd);
break;
case WM_SIZE:
if (hEdit) {
int newWidth = LOWORD(lParam);
int newHeight = HIWORD(lParam);
SetWindowPos(hEdit, NULL, 10, 10, newWidth - 20, newHeight - 20, SWP_NOZORDER);
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == 1001) {
if (HIWORD(wParam) == EN_CHANGE) {
char buffer[256];
GetWindowText(hEdit, buffer, sizeof(buffer));
printf("Edit control text: %s\n", buffer);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
void AddControls(HWND hwnd) {
hEdit = CreateWindowEx(
WS_EX_CLIENTEDGE,
"EDIT",
"",
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
10, 10, 780, 580,
hwnd,
(HMENU)1001,
GetModuleHandle(NULL),
NULL
);
if (hEdit == NULL){
MessageBox(hwnd, "Could not create edit control", "Error", MB_OK);
return;
}
HFONT hFont = CreateFont(
16,
0,
0,
0,
FW_NORMAL,
FALSE,
FALSE,
FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS,
"Arial"
);
SendMessage(hEdit, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
}