프로그래밍/WIN32 API

Text Out

redjam0123 2017. 4. 6. 00:59

2015.03.21. 01:09

*TextOut 패러미터가 (dc핸들,x좌표,y좌표, 문자열, 문자열 크기)

#include <windows.h>
#include <tchar.h>


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR strCmdLine, int nShowCmd)
{
 WNDCLASSEX wcex;
 memset(&wcex, 0, sizeof(wcex));

 wcex.cbSize             = sizeof(wcex);
 wcex.style             = (CS_HREDRAW | CS_VREDRAW);
 wcex.hbrBackground       = (HBRUSH)GetStockObject(WHITE_BRUSH);
 wcex.hCursor          = LoadCursor(NULL, IDC_ARROW);
 wcex.hIcon             = LoadIcon(NULL, IDI_APPLICATION);
 wcex.hInstance          = hInstance;
 wcex.cbClsExtra          = 0;
 wcex.cbWndExtra          = 0;
 wcex.hIconSm          = NULL;
 wcex.lpszMenuName       = NULL;
 wcex.lpfnWndProc       = WndProc;
 wcex.lpszClassName       = L"MyWindow";
 RegisterClassEx(&wcex);

 HWND hWnd = CreateWindow(
  L"MyWindow", L"MyWindow",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT, CW_USEDEFAULT,
  CW_USEDEFAULT, CW_USEDEFAULT,
  NULL,
  NULL,
  hInstance,
  NULL
  );

 if(hWnd == NULL)
 {
  MessageBox(NULL, L"윈도우 생성 실패", L"에러", MB_ICONERROR | MB_OK);
  return -1;
 }

 ShowWindow(hWnd, SW_SHOW);

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

 return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
 switch (uMsg)
 {
 case WM_PAINT:
  {
   HDC hDC; //DC핸들로 화면에 뿌려주는 역할
   PAINTSTRUCT ps;
   TCHAR szText[] = L"동해물과백두산이마르고닳도록하느님이보우하사우리나라만세무궁화삼천리화려강산~";

   hDC = BeginPaint( hWnd, &ps);

   RECT rc = { 10, 10, 300, 100 };

   DrawText( hDC, szText, lstrlen(szText), &rc, DT_CENTER | DT_WORDBREAK);

   EndPaint(hWnd, &ps);
   break;
  }

 //case WM_PAINT:
 // //TextOut
 // {
 //  HDC hDC;
 //  PAINTSTRUCT ps;
 //  TCHAR szText[] = L"HAHAHAHAHA ;ㅅ;";

 //  hDC = BeginPaint(hWnd, &ps);

 //  TextOut(hDC, 10, 10, szText, lstrlen(szText));

 //  EndPaint(hWnd, &ps);
 //  break;
 // }

 case WM_DESTROY :
  {
   PostQuitMessage(0);
   break;
  }
 }

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

 

 

'프로그래밍 > WIN32 API' 카테고리의 다른 글

1,2일차 기본  (0) 2017.04.06
마우스좌표 나타내기  (0) 2017.04.06
Basic  (0) 2017.04.06
Pen, Brush  (0) 2017.04.06