본문 바로가기

3-1/윈도우즈프로그래밍

2장 연습문제 1번


(100, 100) 좌표에 'I love you'를 출력하는 프로그램 작성. Textout()함수와 DrawText()함수 이용


Textout()함수

#include<windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="First";

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,IDI_APPLICATION);
 WndClass.hIcon=LoadIcon(NULL, IDI_APPLICATION);
 WndClass.hInstance=hInstance;
 WndClass.lpfnWndProc=(WNDPROC)WndProc;
 WndClass.lpszClassName=lpszClass;
 WndClass.lpszMenuName=NULL;
 WndClass.style=CS_HREDRAW | CS_VREDRAW;
 RegisterClass(&WndClass);

 hWnd=CreateWindow(lpszClass, lpszClass, WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  NULL, (HMENU)NULL, hInstance, NULL);
 ShowWindow(hWnd, nCmdShow);

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

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;

 switch(iMessage)
 {
 case WM_CREATE:
  break;
 case WM_PAINT:
  hdc =  BeginPaint(hwnd, &ps);
  TextOut(hdc, 100, 100, "I Love You", 10);
  EndPaint(hwnd, &ps);
  break;
 case WM_DESTROY:
  PostQuitMessage(0);
  break;
 }
 return(DefWindowProc(hwnd, iMessage, wParam, lParam));
}





출력결과 요로케~

'3-1 > 윈도우즈프로그래밍' 카테고리의 다른 글

간단한 메모장 만들기  (0) 2011.04.09