Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <windows.h>
  2. #include <TCHAR.H>
  3. LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
  4.     WPARAM wParam, LPARAM lParam);
  5. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  6.     LPSTR lpszCmdLine, int nCmdShow)
  7. {
  8.     HWND     hwnd;
  9.     MSG      msg;
  10.     WNDCLASS WndClass;
  11.     WndClass.style = CS_HREDRAW | CS_VREDRAW;
  12.     WndClass.lpfnWndProc = WndProc;
  13.     WndClass.cbClsExtra = 0;
  14.     WndClass.cbWndExtra = 0;
  15.     WndClass.hInstance = hInstance;
  16.     WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  17.     WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  18.     WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  19.     WndClass.lpszMenuName = NULL;
  20.     WndClass.lpszClassName = _T("Window Class Name");
  21.     RegisterClass(&WndClass);
  22.     hwnd = CreateWindow(_T("Window Class Name"),
  23.         _T("윈도우프로그래밍_과제_20141825_한창기-2"),
  24.         WS_OVERLAPPEDWINDOW,
  25.         0,
  26.         0,
  27.         1000,
  28.         800,
  29.         NULL,
  30.         NULL,
  31.         hInstance,
  32.         NULL
  33.     );
  34.     ShowWindow(hwnd, nCmdShow);
  35.     UpdateWindow(hwnd);
  36.     while (GetMessage(&msg, NULL, 0, 0))
  37.     {
  38.         TranslateMessage(&msg);
  39.         DispatchMessage(&msg);
  40.     }
  41.     return (int)msg.wParam;
  42. }
  43. RECT rect = { 30,30,500,500 };
  44.  
  45. LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
  46.     WPARAM wParam, LPARAM lParam)
  47. {
  48.     HDC hdc;
  49.     PAINTSTRUCT ps;
  50.     LPCWSTR str2 = TEXT("DrawText() 함수를 테스트합니다.\n")
  51.  
  52.         TEXT("이 글을 작성한 날짜는 2012년 8월 17일 새벽 1시입니다.\n")
  53.  
  54.         TEXT("\n")
  55.  
  56.         TEXT("오늘 낮에는 어제보다 더웠습니다.\n")
  57.  
  58.         TEXT("하지만 며칠 전의 찜통더위에 비할바는 아닙니다.\n")
  59.  
  60.         TEXT("그때는 에어컨을 안틀고는 못버틸 날씨였습니다.\n")
  61.  
  62.         TEXT("게다가 전력 비상경보인 주의단계가 발령이 되기까지 했습니다.");
  63.     static TCHAR str[100];
  64.     static int count;
  65.     switch (iMsg)
  66.     {
  67.     case WM_PAINT:
  68.         hdc = BeginPaint(hwnd, &ps);
  69.         DrawText(hdc, str, _tcslen(str), &rect, DT_LEFT|DT_BOTTOM|DT_WORDBREAK);
  70.         EndPaint(hwnd, &ps);
  71.         break;
  72.     case WM_CHAR:
  73.         hdc = GetDC(hwnd);
  74.         if (wParam == VK_BACK)
  75.         {
  76.             if (count <= 0);
  77.             else if (str[--count] == VK_RETURN) str[count--] = NULL; // 개행문자이면 한번 더 삭제
  78.         }
  79.         else if (count >= 99); // 넘어가는거 방지
  80.         else
  81.         {
  82.             if (_tcslen(str) <= 0) str[count++] = wParam;
  83.             else
  84.             {
  85.                 for (int i = _tcslen(str); 0 <= i; i--) // 끝에서 한글자씩 땡겨서 맨 마지막 str[0]에 새로운 문자를 집어넣음
  86.                 {
  87.                     str[i + 1] = str[i];
  88.                 }
  89.                 str[0] = wParam;
  90.                 count++;
  91.             }
  92.         }
  93.         str[count] = NULL;
  94.         InvalidateRgn(hwnd, NULL, TRUE);
  95.         ReleaseDC(hwnd, hdc);
  96.         break;
  97.     case WM_CREATE:
  98.         count = 0;
  99.         break;
  100.     case WM_DESTROY:
  101.         PostQuitMessage(0);
  102.         break;
  103.     }
  104.     return DefWindowProc(hwnd, iMsg, wParam, lParam);
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement