Hwan'Story › @kim-hwan

API - TimerText2

· (수정 ) · 조회 75

API - TimerText2

소스코드

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hInst;
LPCTSTR lpszClass = TEXT("TimerText2");

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
  HWND hWnd;
  MSG Message;
  WNDCLASS WndClass;
  g_hInst = hInstance;

  WndClass.cbClsExtra = 0;
  WndClass.cbWndExtra = 0;
  WndClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  WndClass.hCursor = LoadCursor(NULL, IDC_CROSS);
  WndClass.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
  WndClass.hInstance = hInstance;
  WndClass.lpfnWndProc = WndProc;
  WndClass.lpszClassName = lpszClass;
  WndClass.lpszMenuName = NULL;
  WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  RegisterClass(&WndClass);

  hWnd = CreateWindow(lpszClass, lpszClass, WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
    CW_USEDEFAULT, CW_USEDEFAULT, 100, 300,
    NULL, (HMENU) NULL, hInstance, NULL);
  ShowWindow(hWnd, nCmdShow);

  while (GetMessage(&Message, NULL, 0, 0))
  {
    TranslateMessage(&Message);
    DispatchMessage(&Message);
  }
  return (int) Message.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
  HDC hdc;
  PAINTSTRUCT ps;
  static LPTSTR sText[5] = { TEXT("TimerText2"),
    TEXT("switch"), TEXT("API"), TEXT("P.113"), TEXT("2009.1.13")
  };

  static int ck = 0;
  static int i = 200;

  switch (iMessage)
  {
    case WM_CREATE:
      SetTimer(hWnd, 1, 50, NULL);
      SendMessage(hWnd, WM_TIMER, 1, 0);
      return 0;
    case WM_TIMER:
      switch (wParam)
      {
        case 1:
          if (i == 10)
          {
            KillTimer(hWnd, 1);
            SetTimer(hWnd, 2, 1000, NULL);
          }
          i -= 10;
          InvalidateRect(hWnd, NULL, TRUE);
          break;
        case 2:
          i = 200;
          SetTimer(hWnd, 1, 50, NULL);
          KillTimer(hWnd, 2);
          ck++;
          if (ck == 5)
            ck = 0;
          break;
      }
      return 0;
    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      TextOut(hdc, 10, i, sText[ck], lstrlen(sText[ck]));
      EndPaint(hWnd, &ps);
      return 0;
    case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
  }

  return (DefWindowProc(hWnd, iMessage, wParam, lParam));
}

실행결과

image.png

관련 게시글