💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 一、查看一下aardio封装的drawLine()代码,增加了注释 ``` drawLine = function(hdc,x1,y1,x2,y2,...){ ::Gdi32.MoveToEx(hdc,x1,y1,null ); // 先移动到第一点 ::LineTo(hdc,x2,y2); // 从第一个点画向第二个点画一条线 if(...) return lineTo(hdc,...); // ... 是成对的(x,y)值,如有就接着画下去 } ``` * gdi库进行了重新封装 * 用到了MoveToEx和LineTo两个函数。 # 二、查看一下关于GDI line and curves 的说明 * 官网如下: https://docs.microsoft.com/zh-cn/windows/win32/gdi/line-and-curve-functions * 共有15个函数:我们可以打开一个一个查看定义: ![](https://img.kancloud.cn/da/76/da76a2ff245955244f670d9b4f41f1b4_1092x516.png) * 选一个Polyline函数的说明: ![](https://img.kancloud.cn/e9/c2/e9c244cbd1fb43da25b4db7a4bab98f3_709x626.png) * 在aardio库中没有对Polyline、PolylineTo 、PolyPolyline定义和封装 # 三、我们在/*intellisense(::)*/ 和/*end intellisense*/ 之间新增三个常量申明 ``` /*intellisense(::)*/ //BOOL Polyline(HDC hdc,const POINT *apt,int cpt); // api函数,C++格式 ::Polyline = g.api("Polyline","bool(ptr hdc,struct apt,int cpt)"); // 转换成Aardio中可用的 //BOOL PolylineTo(HDC hdc,const POINT *apt,DWORD cpt); ::PolylineTo = g.api("PolylineTo","bool(ptr hdc,struct apt,int cpt)"); //BOOL PolyPolyline(HDC hdc,const POINT *apt,const DWORD *asz,DWORD csz); ::PolyPolyline = g.api("PolyPolyline","bool(ptr hdc,struct apt,int asz, int csz)"); /*end intellisense*/ ``` * 为什么要这样做,看看帮助里的自定义智能提示中的说明: ![](https://img.kancloud.cn/e2/b3/e2b3c271b139d614ca8f0e98ddf7388d_799x148.png) * 要注意c++中的参数,在aardio中定义的参数就不一样了 * | C++中参数 | aardio中参数 | | :---: | :---: | | HDC hdc | ptr hdc | | const POINT *apt | struct apt | | int cpt | int cpt | | DWORD cpt | int cpt | | const DWORD *asz | struct asz | # 四、在程序中如何使用 ``` gdi.paint( hwnd, function( hdc,width, height,rcPaint,fErase,paintStruct ){ // Polyline() 的第二个参数是一个结构体 var points = {int value[10] = {50;50; 100;50; 100;100; 50;100; 50;50;} } ::Polyline(hdc,points,5) ::BitBlt(hdc, 0, 0, width, height, hMemDc, 0, 0, 0xCC0020/*_SRCCOPY*/); } ); ``` * ::Polyline(hdc,points,5) -- 注意前面有“::” * 运行后的效里 ![](https://img.kancloud.cn/0b/dd/0bdd7efcad098fd949a8057b805c3a11_492x345.png)