POINT点定义如下
typedef struct tagPOINT
{
LONG x;
LONG y;
} POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;
MoveToEx移动坐标
__gdi_entry WINGDIAPI BOOL WINAPI
MoveToEx( __in HDC hdc, //设备上下文
__in int x, //X坐标
__in int y, //Y坐标
__out_opt LPPOINT lppt //用于保存上一个点坐标
);
BOOL为返回值,返回TRUE代表移动成功,FALSE代表失败
LineTo 从MoveToEx的起始点,到LineTo所指的点画一条直线
__gdi_entry WINGDIAPI BOOL WINAPI
LineTo(
__in HDC hdc,
__in int x,
__in int y
);
BOOL为返回值,返回TRUE代表画线成功,FALSE代表失败
Polyline多线段
__gdi_entry WINGDIAPI BOOL WINAPI
Polyline(
__in HDC hdc,
__in_ecount(cpt) CONST POINT *apt, //POINT的指针
__in int cpt //apt中有多少个元素
);
BOOL为返回值,返回TRUE代表画线成功,FALSE代表失败
Polyline和PolylineTo的区别是PolylineTo把现在的所在的点作为起始点,相当于比Polyline多了一个起始点而已,多画一段线
WINGDIAPI BOOL WINAPI
PolylineTo(
__in HDC hdc,
__in_ecount(cpt) CONST POINT * apt,
__in DWORD cpt
);
Arc画弧线函数
__gdi_entry WINGDIAPI BOOL WINAPI
Arc(
__in HDC hdc,
__in int x1, __in int y1, //左上角
__in int x2, __in int y2, //右下角
__in int x3, __in int y3, //切线1
__in int x4, __in int y4 //切线2
);
SetArcDirection函数用于设置时针旋转方向默认是逆时针方向
WINGDIAPI int WINAPI
SetArcDirection(
__in HDC hdc,
__in int dir //时针旋转方向
// #define AD_COUNTERCLOCKWISE 1 默认参数,逆时针方向旋转
// #define AD_CLOCKWISE 2 顺时针方向旋转
);
返回值为设置成功后时针旋转方向
PolyBezier 贝塞尔曲线
WINGDIAPI BOOL WINAPI
PolyBezier(
__in HDC hdc,
__in_ecount(cpt) CONST POINT * apt, //POINT结构数组的指针,包括了样条端点和控制点的坐标,其顺序是起点的坐标、起点的控制点的坐标、终点的控制点的坐标和终点的坐标。
__in DWORD cpt //POINT数组成员个数
);
例子
#include
#include "resource.h"
INT_PTR CALLBACK DlgMainProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
BOOL bRet = true;
HDC hdc;
PAINTSTRUCT ps;
POINT p1;
POINT pArrayp2[5] = {{100,100},{400,100},{400,200},{100,200},{100,100}};
POINT pArrayp3[5] = {{100,100},{400,200},{200,400},{500,400},{400,500}};
switch(uMsg)
{
case WM_PAINT:
hdc = BeginPaint(hWnd,&ps);
MoveToEx(hdc,100,100,&p1);
LineTo(hdc,200,200);
PolylineTo(hdc,pArrayp2,5);
SetArcDirection(hdc,AD_COUNTERCLOCKWISE);
SetArcDirection(hdc,AD_CLOCKWISE);
Arc(hdc,100,100,400,300,400,600,100,200);
PolyBezier(hdc,pArrayp3,4);
EndPaint(hWnd,&ps);
break;
case WM_CLOSE:
EndDialog(hWnd,0);
break;
default:
bRet = false;
}
return bRet;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DlgMainProc);
return 0;
}