Windows API でユーザーからの文字の入力を受け付けるコンポーネントがエディットです。
1行だけ入力できるフィールドも、複数行入力できるテキストエリアも同じエディットコンポーネントを使います。
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int PASCAL WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "REVIEW";
RegisterClass(&wc);
hwnd = CreateWindow("REVIEW",
"Review",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
300, 200,
NULL, NULL, hInstance, NULL);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
RECT rect;
HWND label1, label2, label3;
static HWND edit1 , edit2, edit3;
switch (msg)
{
case WM_CREATE:
GetClientRect(hwnd, &rect);
label1 = CreateWindow("STATIC", "Title",
WS_CHILD | WS_VISIBLE | SS_RIGHT,
5, 5, 50, 20, hwnd, NULL, NULL, NULL);
label2 = CreateWindow("STATIC", "Author",
WS_CHILD | WS_VISIBLE | SS_RIGHT,
5, 35, 50, 20, hwnd, NULL, NULL, NULL);
label3 = CreateWindow("STATIC", "Review",
WS_CHILD | WS_VISIBLE | SS_RIGHT,
5, 65, 50, 20, hwnd, NULL, NULL, NULL);
edit1 = CreateWindow("EDIT", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
60, 5, rect.right - 65, 25,
hwnd, NULL, NULL, NULL);
edit2 = CreateWindow("EDIT", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
60, 35, rect.right - 65, 25,
hwnd, NULL, NULL, NULL);
edit3 = CreateWindow("EDIT", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE,
60, 65, rect.right - 65, rect.bottom - 70,
hwnd, NULL, NULL, NULL);
return 0;
case WM_SIZE:
GetClientRect(hwnd, &rect);
SetWindowPos (edit1, HWND_TOP, 0, 0, rect.right - 65, 25, SWP_NOMOVE);
SetWindowPos (edit2, HWND_TOP, 0, 0, rect.right - 65, 25, SWP_NOMOVE);
SetWindowPos (edit3, HWND_TOP, 0, 0, rect.right - 65, rect.bottom - 70, SWP_NOMOVE);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}