LuvSea

직선, 원, 사각형 그리기 본문

sTudy

직선, 원, 사각형 그리기

사랑海 2009. 7. 6. 12:18
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include<windows.h>

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

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevlnstance, 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_ARROW);
 WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 WndClass.hInstance=hInstance;
 WndClass.lpfnWndProc=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,NULL,0,0))
 {
  TranslateMessage(&Message);
  DispatchMessage(&Message);
 }
 return (int)Message.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM WParam,LPARAM IParam)
{
 HDC hdc;
 PAINTSTRUCT ps;

 switch(iMessage)
 {
  case WM_DESTROY:
  PostQuitMessage(0);
  return 0;
  case WM_PAINT:
  hdc = BeginPaint(hWnd,&ps);
  SetPixel(hdc,10,10,RGB(255,0,0));
  Rectangle(hdc,50,100,150,200); //사각형 x1 50 x2 150  y1 100  y2 200
  Ellipse(hdc,50,100,150,200);  // 원 x-r y-r x+r  y+r
  MoveToEx(hdc,150,200,NULL);  // 직선 그리기x1 y1
  LineTo(hdc,50,100);   //             x2 y2
  MoveToEx(hdc,150,100,NULL);
  LineTo(hdc,50,200);
  MoveToEx(hdc,50,100,NULL);
  LineTo(hdc,100,50);
  MoveToEx(hdc,100,50,NULL);
  LineTo(hdc,150,100);
  EndPaint(hWnd,&ps);

  return 0;
 }
 return(DefWindowProc(hWnd,iMessage,WParam,IParam));
}

/*반원 그리기
  case WM_PAINT:
  hdc = BeginPaint(hWnd,&ps);
  SetPixel(hdc,10,10,RGB(255,0,0));
  Ellipse(hdc,200,200,300,300);  // 원 x-r y-r x+r  y+r
  MoveToEx(hdc,250,300,NULL);  // 직선 그리기x1 y1
  LineTo(hdc,250,500);   //             x2 y2
  
  MoveToEx(hdc,250,350,NULL);  // 직선 그리기x1 y1
  LineTo(hdc,150,200);   //             x2 y2
  MoveToEx(hdc,250,350,NULL);  // 직선 그리기x1 y1
  LineTo(hdc,350,200);   //             x2 y2
  
  MoveToEx(hdc,250,500,NULL);  // 직선 그리기x1 y1
  LineTo(hdc,150,650);   //             x2 y2
  MoveToEx(hdc,250,500,NULL);  // 직선 그리기x1 y1
  LineTo(hdc,350,650);   //             x2 y2
  
  Arc(hdc,80,80,400,400,400,80,80,80);
  Arc(hdc,80,40,400,360,400,40,80,40);

  EndPaint(hWnd,&ps);

  return 0;
*/

Comments