Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <TCHAR.H>
- LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
- WPARAM wParam, LPARAM lParam);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpszCmdLine, int nCmdShow)
- {
- HWND hwnd;
- MSG msg;
- WNDCLASS WndClass;
- WndClass.style = CS_HREDRAW | CS_VREDRAW;
- WndClass.lpfnWndProc = WndProc;
- WndClass.cbClsExtra = 0;
- WndClass.cbWndExtra = 0;
- WndClass.hInstance = hInstance;
- WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- WndClass.lpszMenuName = NULL;
- WndClass.lpszClassName = _T("Window Class Name");
- RegisterClass(&WndClass);
- hwnd = CreateWindow(_T("Window Class Name"),
- _T("윈도우프로그래밍_과제_20141825_한창기-2"),
- WS_OVERLAPPEDWINDOW,
- 0,
- 0,
- 1000,
- 800,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int)msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
- WPARAM wParam, LPARAM lParam)
- {
- HDC hdc;
- PAINTSTRUCT ps;
- RECT rect = { 30,30,500,500 };
- static TCHAR str[100];
- static int count;
- switch (iMsg)
- {
- case WM_PAINT:
- hdc = BeginPaint(hwnd, &ps);
- DrawText(hdc, str, _tcslen(str), &rect, DT_LEFT | DT_BOTTOM|DT_WORDBREAK);
- EndPaint(hwnd, &ps);
- break;
- case WM_CHAR:
- hdc = GetDC(hwnd);
- if (wParam == VK_BACK)
- {
- if (count <= 0);
- else if (str[--count] == VK_RETURN) str[count--] = NULL; // 개행문자이면 한번 더 삭제
- }
- else if (count >= 99); // 넘어가는거 방지
- else
- {
- if (_tcslen(str) <= 0) str[count++] = wParam;
- else
- {
- for (int i = _tcslen(str); 0 <= i; i--) // 끝에서 한글자씩 땡겨서 맨 마지막 str[0]에 새로운 문자를 집어넣음
- {
- str[i + 1] = str[i];
- }
- str[0] = wParam;
- count++;
- }
- }
- str[count] = NULL;
- InvalidateRgn(hwnd, NULL, TRUE);
- ReleaseDC(hwnd, hdc);
- break;
- case WM_CREATE:
- count = 0;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- }
- return DefWindowProc(hwnd, iMsg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement