반응형

이전 예제와 거의 비슷하지만 구현 방식에 약간 차이가 있습니다.

비교하면서 차이점을 확인해 보세요.


//

// Visual Studio 2015, Hello world! API 예제 (2)

//


LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPreInstance,  LPSTR lpszCmdLine, int nCmdShow)
{
  WNDCLASS wc;

  wc.style   = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  wc.lpfnWndProc  = (WNDPROC) WndProc;
  wc.cbClsExtra  = 0;
  wc.cbWndExtra  = 0;
  wc.hInstance  = hInstance;
  wc.hIcon   = LoadIcon (NULL, IDI_APPLICATION);
  wc.hCursor   = LoadCursor (NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  wc.lpszMenuName  = NULL;
  wc.lpszClassName = TEXT("HelloGUI");
  RegisterClass (&wc);

  HWND hWnd = CreateWindow (TEXT("HelloGUI"), TEXT("HelloGUI Application"), WS_OVERLAPPEDWINDOW,
                                             CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

  ShowWindow (hWnd, nCmdShow);

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

  return 0;
}


LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  HDC hdc;
  PAINTSTRUCT ps;
  RECT rc;
  switch (message)
  {
    case WM_PAINT:
      hdc = BeginPaint (hWnd, &ps);
      GetClientRect (hWnd, &rc);
      DrawText (hdc, TEXT("Hello, World! 안녕하세요."), -1,&rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
      EndPaint (hWnd, &ps);
      return 0;
    case WM_DESTROY:
     PostQuitMessage(0);
     return 0;
  }

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

반응형

+ Recent posts