#include <windows.h>

 

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);

 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpszCmdLine, int nCmdShow)

{
 HWND hwnd;
 MSG msg;
 WNDCLASS W;
 W.style = CS_HREDRAW | CS_VREDRAW;
 W.lpfnWndProc = WndProc;
 W.cbClsExtra = 0;
 W.cbWndExtra = 0;
 W.hInstance = hInstance;
 W.hIcon = LoadIcon(NULL, IDI_APPLICATION);
 W.hCursor = LoadCursor(NULL, IDC_ARROW);
 W.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
 W.lpszMenuName = "TANK BOY";
 W.lpszClassName = "TANK BOY";
 RegisterClass(&W);

 

 hwnd = CreateWindow
  (
  "TANK BOY",
  "TANK BOY",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  NULL,
  NULL,
  hInstance,
  NULL
  );

 

 ShowWindow(hwnd, nCmdShow);
 UpdateWindow(hwnd);

 

 while (GetMessage(&msg, NULL, 0, 0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }

 

 return msg.wParam;
}

 

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
 switch (iMsg)
 {
  HDC hdc;
  PAINTSTRUCT ps;
  static char tank[10][100];
  static int i, count, y;

 

 case WM_CREATE:
  i = 0, count = 0, y = 0;
  break;

 

 case WM_PAINT:
  hdc = BeginPaint(hwnd, &ps);

 

  for (int x = 0; x <= y / 20; x++)
  {
   TextOut(hdc, 0, x * 20, tank[x], strlen(tank[x]));
  }

 

  EndPaint(hwnd, &ps);
  break;

 

 case WM_CHAR:
  if (wParam == VK_BACK)
  {
   if (count == 0)
   {
    if (i == 0)
    {
     hdc = GetDC(hwnd);
     TextOut(hdc, 0, 0, "백스패이스 안됨", 15);
     ReleaseDC(hwnd, hdc);
     break;
    }

    i--;
    count = strlen(tank[i]);
    y -= 20;
   }

 

   else
    count--;
  }

 

  else if (count == 99)
  {
   if (i == 9)
    break;

   i++;
   y += 20;
   count = 0;
  }

 

  else if (wParam == VK_RETURN)
  {
   if (i == 9)
   {
    hdc = GetDC(hwnd);
    TextOut(hdc, 0, 200, "엔터 안됨", 11);
    ReleaseDC(hwnd, hdc);
    break;
   }

   count = 0;
   i++;
   y += 20;
  }

 

  else
   tank[i][count++] = wParam;

 

  tank[i][count] = '\0';
  InvalidateRgn(hwnd, NULL, TRUE);
  break;

 

 case WM_DESTROY:
  PostQuitMessage(0);
  break;
 }

 

 return(DefWindowProc(hwnd, iMsg, wParam, lParam));
}