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;
- }
- RECT rect = { 30,30,500,500 };
- LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
- WPARAM wParam, LPARAM lParam)
- {
- HDC hdc;
- PAINTSTRUCT ps;
- LPCWSTR str2 = TEXT("DrawText() 함수를 테스트합니다.\n")
- TEXT("이 글을 작성한 날짜는 2012년 8월 17일 새벽 1시입니다.\n")
- TEXT("\n")
- TEXT("오늘 낮에는 어제보다 더웠습니다.\n")
- TEXT("하지만 며칠 전의 찜통더위에 비할바는 아닙니다.\n")
- TEXT("그때는 에어컨을 안틀고는 못버틸 날씨였습니다.\n")
- TEXT("게다가 전력 비상경보인 주의단계가 발령이 되기까지 했습니다.");
- 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