Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 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.  
  44. LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
  45.     WPARAM wParam, LPARAM lParam)
  46. {
  47.     HDC hdc;
  48.     PAINTSTRUCT ps;
  49.     RECT rect = { 30,30,500,500 };
  50.     static TCHAR str[100];
  51.     static int count;
  52.     switch (iMsg)
  53.     {
  54.     case WM_PAINT:
  55.         hdc = BeginPaint(hwnd, &ps);
  56.         DrawText(hdc, str, _tcslen(str), &rect, DT_LEFT | DT_BOTTOM|DT_WORDBREAK);
  57.         EndPaint(hwnd, &ps);
  58.         break;
  59.     case WM_CHAR:
  60.         hdc = GetDC(hwnd);
  61.         if (wParam == VK_BACK)
  62.         {
  63.             if (count <= 0);
  64.             else if (str[--count] == VK_RETURN) str[count--] = NULL; // 개행문자이면 한번 더 삭제
  65.         }
  66.         else if (count >= 99); // 넘어가는거 방지
  67.         else
  68.         {
  69.             if (_tcslen(str) <= 0) str[count++] = wParam;
  70.             else
  71.             {
  72.                 for (int i = _tcslen(str); 0 <= i; i--) // 끝에서 한글자씩 땡겨서 맨 마지막 str[0]에 새로운 문자를 집어넣음
  73.                 {
  74.                     str[i + 1] = str[i];
  75.                 }
  76.                 str[0] = wParam;
  77.                 count++;
  78.             }
  79.         }
  80.         str[count] = NULL;
  81.         InvalidateRgn(hwnd, NULL, TRUE);
  82.         ReleaseDC(hwnd, hdc);
  83.         break;
  84.     case WM_CREATE:
  85.         count = 0;
  86.         break;
  87.     case WM_DESTROY:
  88.         PostQuitMessage(0);
  89.         break;
  90.     }
  91.     return DefWindowProc(hwnd, iMsg, wParam, lParam);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement