各种多边形绘制函数

来源:互联网 发布:张佳玮写字的地方 知乎 编辑:程序博客网 时间:2024/04/29 11:38

Rectangle

The Rectangle function draws a rectangle. The rectangle is outlinedby using the current pen and filled by using the current brush.

BOOL Rectangle(

  HDC hdc,        // handle to DC

  int nLeftRect,  // x-coord of upper-left corner of rectangle

  int nTopRect,   // y-coord of upper-left corner of rectangle

  int nRightRect// x-coord of lower-right corner of rectangle

  int nBottomRect  // y-coord oflower-right corner of rectangle

);

Ellipse

The Ellipse function draws an ellipse. The center of the ellipse isthe center of the specified bounding rectangle. The ellipse is outlined byusing the current pen and is filled by using the current brush.

BOOL Ellipse(

  HDC hdc,       // handle to DC

  int nLeftRect// x-coord of upper-left corner of rectangle

  int nTopRect,  // y-coord of upper-left corner of rectangle

  int nRightRect,// x-coord oflower-right corner of rectangle

  int nBottomRect // y-coord of lower-right corner of rectangle

);

Parameters

hdc

[in] Handle to thedevice context.

nLeftRect

[in] Specifies thex-coordinate, in logical coordinates, of the upper-left corner of the boundingrectangle.

nTopRect

[in] Specifies they-coordinate, in logical coordinates, of the upper-left corner of the boundingrectangle.

nRightRect

[in] Specifies thex-coordinate, in logical coordinates, of the lower-right corner of the boundingrectangle.

nBottomRect

[in] Specifies they-coordinate, in logical coordinates, of the lower-right corner of the boundingrectangle.

Windows画椭圆是需要设置一个 矩形的左上角坐标和右下角坐标,他会在这个矩形内设置内接椭圆(内接圆)。

RoundRect

The RoundRect function draws a rectangle withrounded corners. The rectangle is outlined by using the current pen and filledby using the current brush.

BOOL RoundRect(
  HDC hdc,         // handle to DC
  int nLeftRect,   // x-coord of upper-left corner of rectangle
  int nTopRect,    // y-coord of upper-left corner of rectangle
  int nRightRect// x-coord of lower-right corner of rectangle
  int nBottomRect, // y-coord of lower-right corner of rectangle
  int nWidth,      // width of ellipse
  int nHeight      // height of ellipse
);

圆角矩形,(其实四个角都是椭圆构成),所以最后两个参数是设置椭圆的宽度和高度。

Arc

The Arc function draws an elliptical arc.

BOOL Arc(
  HDC hdc,         // handle to device context
  int nLeftRect,   // x-coord of rectangle's upper-left corner
  int nTopRect,    // y-coord of rectangle's upper-left corner
  int nRightRect// x-coord of rectangle's lower-right corner
  int nBottomRect, // y-coord of rectangle's lower-right corner
  int nXStartArc// x-coord of first radial ending point
  int nYStartArc// y-coord of first radial ending point
  int nXEndArc,    // x-coord of second radial ending point
  int nYEndArc     // y-coord of second radial ending point
);

Parameters

hdc

[in] Handle tothe device context where drawing takes place.

nLeftRect

[in] Specifiesthe x-coordinate, in logical units, of the upper-left corner of the boundingrectangle.

Windows 95/98/Me: The sum of nLeftRectplus nRightRectmustbe less than 32768.

nTopRect

[in] Specifiesthe y-coordinate, in logical units, of the upper-left corner of the boundingrectangle.

Windows 95/98/Me: The sum of nTopRectplus nBottomRectmustbe less than 32768.

nRightRect

[in] Specifiesthe x-coordinate, in logical units, of the lower-right corner of the boundingrectangle.

Windows 95/98/Me: The sum of nLeftRectplus nRightRectmustbe less than 32768.

nBottomRect

[in] Specifiesthe y-coordinate, in logical units, of the lower-right corner of the boundingrectangle.

Windows 95/98/Me: The sum of nTopRectplus nBottomRectmustbe less than 32768.

nXStartArc

[in] Specifiesthe x-coordinate, in logical units, of the ending point of the radial linedefining the starting point of the arc.

nYStartArc

[in] Specifiesthe y-coordinate, in logical units, of the ending point of the radial linedefining the starting point of the arc.

nXEndArc

[in] Specifiesthe x-coordinate, in logical units, of the ending point of the radial linedefining the ending point of the arc.

nYEndArc

[in] Specifiesthe y-coordinate, in logical units, of the ending point of the radial linedefining the ending point of the arc.

 

Arc函数 画一个弧,参数说明:

前四个参数也是跟矩形一样,左上角坐标,右下角坐标。 后四个参数指的是 两个切点的坐标。切割这个矩形里面的椭圆。

Chord

The Chord function draws a chord (a region boundedby the intersection of an ellipse and a line segment, called a secant). Thechord is outlined by using the current pen and filled by using the currentbrush.

BOOL Chord(
  HDC hdc,         // handle to DC
  int nLeftRect,   // x-coord of upper-left corner of rectangle
  int nTopRect,    // y-coord of upper-left corner of rectangle
  int nRightRect// x-coord of lower-right corner of rectangle
  int nBottomRect, // y-coord of lower-right corner of rectangle
  int nXRadial1,   // x-coord of first radial's endpoint
  int nYRadial1,   // y-coord of first radial's endpoint
  int nXRadial2,   // x-coord of second radial's endpoint
  int nYRadial2    // y-coord of second radial's endpoint
);

Parameters

hdc

[in] Handle tothe device context in which the chord appears.

nLeftRect

[in] Specifiesthe x-coordinate, in logical coordinates, of the upper-left corner of thebounding rectangle.

nTopRect

[in] Specifiesthe y-coordinate, in logical coordinates, of the upper-left corner of thebounding rectangle.

nRightRect

[in] Specifiesthe x-coordinate, in logical coordinates, of the lower-right corner of thebounding rectangle.

nBottomRect

[in] Specifiesthe y-coordinate, in logical coordinates, of the lower-right corner of thebounding rectangle.

nXRadial1

[in] Specifiesthe x-coordinate, in logical coordinates, of the endpoint of the radialdefining the beginning of the chord.

nYRadial1

[in] Specifiesthe y-coordinate, in logical coordinates, of the endpoint of the radialdefining the beginning of the chord.

nXRadial2

[in] Specifiesthe x-coordinate, in logical coordinates, of the endpoint of the radialdefining the end of the chord.

nYRadial2

[in] Specifiesthe y-coordinate, in logical coordinates, of the endpoint of the radialdefining the end of the chord.

Chord函数和Arc函数类似,但是 它会把两个切点连接起来形成封闭图形。

Pie

The Pie function draws a pie-shaped wedge bounded bythe intersection of an ellipse and two radials. The pie is outlined by usingthe current pen and filled by using the current brush.

BOOL Pie(
  HDC hdc,         // handle to DC
  int nLeftRect,   // x-coord of upper-left corner of rectangle
  int nTopRect,    // y-coord of upper-left corner of rectangle
  int nRightRect// x-coord of lower-right corner of rectangle
  int nBottomRect, // y-coord of lower-right corner of rectangle
  int nXRadial1,   // x-coord of first radial's endpoint
  int nYRadial1,   // y-coord of first radial's endpoint
  int nXRadial2,   // x-coord of second radial's endpoint
  int nYRadial2    // y-coord of second radial's endpoint
);

Parameters

hdc

[in] Handle tothe device context.

nLeftRect

[in] Specifiesthe x-coordinate, in logical coordinates, of the upper-left corner of thebounding rectangle.

nTopRect

[in] Specifiesthe y-coordinate, in logical coordinates, of the upper-left corner of thebounding rectangle.

nRightRect

[in] Specifiesthe x-coordinate, in logical coordinates, of the lower-right corner of thebounding rectangle.

nBottomRect

[in] Specifiesthe y-coordinate, in logical coordinates, of the lower-right corner of thebounding rectangle.

nXRadial1

[in] Specifiesthe x-coordinate, in logical coordinates, of the endpoint of the first radial.

nYRadial1

[in] Specifiesthe y-coordinate, in logical coordinates, of the endpoint of the first radial.

nXRadial2

[in] Specifiesthe x-coordinate, in logical coordinates, of the endpoint of the second radial.

nYRadial2

[in] Specifiesthe y-coordinate, in logical coordinates, of the endpoint of the second radial.

Pie和Chord相似,但是它会连接两个切点和中心点

Rectangle.c

/* -------------------------------------------------------------------RectangleAuthor:邱于涵Time:2016年11月29日20:35:01--------------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT("MyWindows");HWND hwnd;MSG msg;WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW;wndclass.lpfnWndProc = WndProc;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance;wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName = NULL;wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);return 0;}hwnd = CreateWindow(szAppName,TEXT("涵涵工作室"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd, iCmdShow);UpdateWindow(hwnd);while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){HDC hdc;PAINTSTRUCT ps;RECT rect;static POINT apt[] = { 50, 20, 20, 60, 80, 60, 50, 20, 70, 20, 100, 60, 130, 20, 70, 20, 150, 20, 150, 60, 190, 60, 190, 20, 150, 20 };static int asz[] = { 4, 4, 5 };switch (message){case WM_PAINT:hdc = GetDC(hwnd);Rectangle(hdc, 100, 100, 200, 200);ReleaseDC(hwnd, hdc);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, message, wParam, lParam);}


Ellipse.c

/* -------------------------------------------------------------------Ellipse画椭圆Time:2016年11月29日20:33:38Author:邱于涵--------------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT("MyWindows");HWND hwnd;MSG msg;WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW;wndclass.lpfnWndProc = WndProc;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance;wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName = NULL;wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);return 0;}hwnd = CreateWindow(szAppName,TEXT("涵涵工作室"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd, iCmdShow);UpdateWindow(hwnd);while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){HDC hdc;PAINTSTRUCT ps;RECT rect;static POINT apt[] = { 50, 20, 20, 60, 80, 60, 50, 20, 70, 20, 100, 60, 130, 20, 70, 20, 150, 20, 150, 60, 190, 60, 190, 20, 150, 20 };static int asz[] = { 4, 4, 5 };switch (message){case WM_PAINT:hdc = GetDC(hwnd);Ellipse(hdc, 200, 200, 400, 400);ReleaseDC(hwnd, hdc);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, message, wParam, lParam);}


Arc.c

/* -------------------------------------------------------------------ArcAuthor:邱于涵Time:2016年11月29日20:56:23--------------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT("MyWindows");HWND hwnd;MSG msg;WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW;wndclass.lpfnWndProc = WndProc;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance;wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName = NULL;wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);return 0;}hwnd = CreateWindow(szAppName,TEXT("涵涵工作室"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd, iCmdShow);UpdateWindow(hwnd);while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){HDC hdc;PAINTSTRUCT ps;RECT rect;static POINT point1 = { 100, 100 };static POINT point2 = { 300, 300 };/*****************************前面两个POINT 是 矩形左上角和右下角的点坐标*后面两个POINT 是 两个切点的坐标*切下来的就是 Arc函数画出来的圆弧****************************/static POINT point3 = { 150, 50 };static POINT point4 = {50,150};switch (message){case WM_PAINT:hdc = GetDC(hwnd);Arc(hdc, point1.x, point1.y, point2.x, point2.y, point2.x, point3.y, point4.x, point4.y);ReleaseDC(hwnd, hdc);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, message, wParam, lParam);}


chord.c

/* -------------------------------------------------------------------ChordAuthor:邱于涵Time:2016年11月29日20:56:47--------------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT("MyWindows");HWND hwnd;MSG msg;WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW;wndclass.lpfnWndProc = WndProc;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance;wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName = NULL;wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);return 0;}hwnd = CreateWindow(szAppName,TEXT("涵涵工作室"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd, iCmdShow);UpdateWindow(hwnd);while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){HDC hdc;PAINTSTRUCT ps;RECT rect;static POINT point1 = { 100, 100 };static POINT point2 = { 300, 300 };/*****************************前面两个POINT 是 矩形左上角和右下角的点坐标*后面两个POINT 是 两个切点的坐标*切下来的就是 Arc函数画出来的圆弧*Chord会把两个切点连接起来形成封闭的图形****************************/static POINT point3 = { 150, 50 };static POINT point4 = { 50, 150 };switch (message){case WM_PAINT:hdc = GetDC(hwnd);Chord(hdc, point1.x, point1.y, point2.x, point2.y, point2.x, point3.y, point4.x, point4.y);ReleaseDC(hwnd, hdc);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, message, wParam, lParam);}


pie.c

/* -------------------------------------------------------------------PieAuthor:邱于涵Time:2016年11月29日21:27:15--------------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT("MyWindows");HWND hwnd;MSG msg;WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW;wndclass.lpfnWndProc = WndProc;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance;wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);//设置黑色画刷为背景wndclass.lpszMenuName = NULL;wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);return 0;}hwnd = CreateWindow(szAppName,TEXT("涵涵工作室"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd, iCmdShow);UpdateWindow(hwnd);while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){HDC hdc;PAINTSTRUCT ps;RECT rect;static POINT point1 = { 100, 100 };static POINT point2 = { 300, 300 };/*****************************前面两个POINT 是 矩形左上角和右下角的点坐标*后面两个POINT 是 两个切点的坐标*切下来的就是 Arc函数画出来的圆弧*Pie会连接两个切点加中心点****************************/static POINT point3 = { 150, 50 };static POINT point4 = { 50, 150 };HPEN hCurrentPen;HPEN hPrePen;switch (message){case WM_PAINT:hdc = GetDC(hwnd);hCurrentPen = GetStockObject(WHITE_PEN);hPrePen = SelectObject(hdc, hCurrentPen);//选择后 返回被替代的HPENPie(hdc, point1.x, point1.y, point2.x, point2.y, point2.x, point3.y, point4.x, point4.y);SelectObject(hdc, hPrePen);//还回去ReleaseDC(hwnd, hdc);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, message, wParam, lParam);}


0 0