鍥炲? 10妤
程序代码:
Declare integer GradientFillRect IN msimg32 long, string @, long, string @, long, long
Declare integer GradientFillTriangle in "msimg32" Long, string @, Long, string @, Long, Long
DECLARE integer GradientFill IN msimg32 long, string @, long, string @, long, long
DECLARE integer GetWindowDC IN WIN32API integer
DECLARE integer GetLastError IN WIN32API
DECLARE integer ReleaseDC IN WIN32API integer,integer
DECLARE INTEGER GetDesktopWindow IN win32api
DECLARE INTEGER GetDC IN win32api INTEGER hwnd
clea
hdc=getdc(_screen.hwnd)
overtex=NEWOBJECT("trivertex")
overtex.n=3
overtex.set(1,100,100)
overtex.set(2,500,500)
overtex.set(3,50,400)
cvertex=overtex.getstruct()
og_r=NEWOBJECT("gradient_rect")
og_r.n=3
og_r.set(1,0,1,2)
cg_r=og_r.getstruct()
GradientFilltriangle(hdc,@cvertex,3,@cg_r,1,2)
RELEASE memo like o*
RELEASE memo like c*
releasedc(_screen.hwnd,hdc)
**************************************************
*-- 类: trivertex (d:\documents\visual foxpro 项目\myclass.vcx)
*-- 父类: struct (d:\documents\visual foxpro 项目\myclass.vcx)
*-- 基类: custom
*-- 时间戳: 08/22/24 05:03:08 PM
*
DEFINE CLASS trivertex AS custom
Height = 22
Width = 58
*-- 顶点数,决定所有数组大小,2为矩形,3为三角形,大于3则可以任意组合。
n = .F.
*-- 顶点x轴坐标数组
DIMENSION x[2]
*-- 顶点y轴坐标数组
DIMENSION y[2]
*-- 红色分量数组
DIMENSION r[2]
*-- 绿色分量数组
DIMENSION g[2]
*-- 蓝色分量数组
DIMENSION b[2]
*-- alpha透明度分量数组
DIMENSION a[2]
PROCEDURE n_assign
LPARAMETERS vNewVal
*To do: 为 Assign 方法程序修改此例程
IF m.vnewval<>this.n
DIMENSION this.x[m.vnewval]
DIMENSION this.y[m.vnewval]
DIMENSION this.r[m.vnewval]
DIMENSION this.g[m.vnewval]
DIMENSION this.b[m.vnewval]
DIMENSION this.a[m.vnewval]
ENDIF
THIS.n = m.vNewVal
ENDPROC
PROCEDURE getstruct
this.struct=''
FOR i=1 TO this.n
this.struct=this.struct+;
BINTOC(this.x[i],[4rs])+;
BINTOC(this.y[i],[4rs])+;
BINTOC(this.r[i],[2s])+;
BINTOC(this.g[i],[2s])+;
BINTOC(this.b[i],[2s])+;
BINTOC(this.a[i],[2s])
ENDFOR
RETURN this.struct
ENDPROC
PROCEDURE set
*!********* 在设置顶点结构前,需要确定有几个顶点,this.n=? **********!*
PARAMETERS nindex, x,y,nred,ngreen,nblue,nalpha
DO CASE
CASE PARAMETERS()=3
ocolor=NEWOBJECT([color],[myclass])
ncolor=GETCOLOR()
IF ncolor<0
RELEASE ocolor,ncolor
RETURN .f.
ELSE
ocolor.set(ncolor)
this.x[nindex]=x
this.y[nindex]=y
this.r[nindex]=ocolor.r
this.g[nindex]=ocolor.g
this.b[nindex]=ocolor.b
this.a[nindex]=ocolor.a
ENDIF
CASE PARAMETERS()=7
this.x[nindex]=x
this.y[nindex]=y
this.r[nindex]=nred
this.g[nindex]=ngreen
this.b[nindex]=nblue
this.a[nindex]=nalpha
OTHERWISE
RETURN .f.
ENDCASE
ENDPROC
ENDDEFINE
*
*-- EndDefine: trivertex
**************************************************
[此贴子已经被作者于2024-8-22 20:15编辑过]

程序代码:
* 正确声明GradientFill
DECLARE INTEGER GradientFill IN msimg32 ;
INTEGER hdc, ;
STRING @pVertex, ;
LONG dwNumVertex, ;
STRING @pMesh, ;
LONG dwNumMesh, ;
LONG dwMode
* 其他声明保持不变
DECLARE INTEGER GetDC IN user32 INTEGER hwnd
DECLARE INTEGER ReleaseDC IN user32 INTEGER hwnd, INTEGER hdc
DECLARE INTEGER GetLastError IN kernel32
* 获取设备上下文
hdc = GetDC(_SCREEN.HWND)
IF hdc = 0
? "错误:无法获取设备上下文"
RETURN
ENDIF
* 创建顶点和三角形结构(假设类已正确实现)
LOCAL overtex AS OBJECT
overtex = NEWOBJECT("TriVertex", "myclass")
overtex.n = 3
overtex.set(1, 500, 100, 255,0, 0,255) && 红色顶点
overtex.set(2, 250, 600, 0, 255,0,255) && 绿色顶点
overtex.set(3, 750, 600, 0, 0, 255,255) && 蓝色顶点
cvertex = overtex.getstruct()
LOCAL og_triangle AS OBJECT
og_triangle = NEWOBJECT("Gradient_Triangle", "myclass")
og_triangle.set(1, 0, 1, 2) && 使用前三个顶点构成三角形
cg_triangle = og_triangle.getstruct()
* 调用GradientFill绘制三角形
lnResult = GradientFill(hdc, @cvertex, 3, @cg_triangle, 1, 2)
IF lnResult = 0
? "错误:GradientFill 失败,错误代码:", GetLastError()
ENDIF
* 清理资源
RELEASE overtex, og_triangle
ReleaseDC(_SCREEN.HWND, hdc)