연습
Windows API 프로그래밍 -13. 다각형 출력. -
JunkMam
2016. 6. 30. 00:00
다각형은 Polygon이라고 한다.
여기서, 다각형을 표현하기 위해서는 다음과 같은 함수를 사용한다.
Polygon(
HDC hdc, // DC의 핸들.
CONST POINT *lpPoints, // 그릴 좌표.
int nCount); // 좌표의 수.
Polyline(
HDC hdc, // DC의 핸들.
CONST POINT *lppt, //그릴 좌표.
int cPoints); // 좌표의 수.
두개의 함수의 공통점은 다각형을 표현하는 것이지만, Polygon()은 다각형을 표현하는 것이고, Polyline()은 다각선을 표현하는 것이다.
Polygon()은 첫 점과 끝 점이 합쳐지지만, Polyline()은 끝이 끊어져있다.
POINT들은 포인트 배열을들 모아서 사용되는 것으로, x, y라는 것이 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include <stdlib.h> #include <tchar.h> #include <windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); HINSTANCE g_hInst; WNDCLASS WndClass; int numbers = 0; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { HWND hWnd; MSG Message; 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)WndProc; WndClass.lpszClassName="ApiBase"; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW|CS_VREDRAW; //윈도우 클래스 생성. RegisterClass(&WndClass); //윈도우 객체 생성. hWnd = CreateWindow("ApiBase", "Test", WS_OVERLAPPEDWINDOW, 10,// X 100,// Y 400,// Width 400,// Height 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; long dwStyle; POINT polyline[5] = {60,50,40,30,20}; POINT polygon[5] = {10,20,30,40,50}; switch(iMessage) { case WM_DESTROY: PostQuitMessage(0); break; case WM_LBUTTONDOWN: hdc = GetDC(hWnd); Polyline(hdc, polyline, 5); Polyline(hdc, polygon, 5); ReleaseDC(hWnd, hdc); break; case WM_PAINT: hdc = GetDC(hWnd); TextOut(hdc, 100, 50, "Hello World",11); ReleaseDC(hWnd, hdc); break; } return DefWindowProc(hWnd,iMessage,wParam, lParam); } | cs |