谁知道 GradientFill 怎么用,是API

紫焰月读 2002-05-06 02:28:21
以下为本人所做,只是没有任何反应,不知为何, 请兄弟们帮我看看
Private Const GRADIENT_FILL_RECT_H = 0
Private Const GRADIENT_FILL_RECT_V = 1
Private Const GRADIENT_FILL_TRIANGLE = 2

Private Type TRIVERTEX
x As Long
y As Long
Red As Long
Green As Long
Blue As Long
Alpha As Long
End Type

Private Type GRADIENT_RECT
UpperLeft As Long 'upper-left
LowerRight As Long 'lower-right
End Type

Private Declare Function GradientFill Lib "Msimg32.dll" (ByVal hdc As Long, pVertex As TRIVERTEX, dwNumVertex As Long, pMesh As GRADIENT_RECT, dwNumMesh As Long, dwMode As Long) As Long

Private Sub Command3_Click()
Dim vert(0 To 1) As TRIVERTEX
Dim gRect As GRADIENT_RECT

vert(0).x = 0
vert(0).y = 0
vert(0).Red = 0
vert(0).Green = 0
vert(0).Blue = 0
vert(0).Alpha = 0

vert(1).x = 100
vert(1).y = 320
vert(1).Red = 0
vert(1).Green = 0
vert(1).Blue = &HFF00
vert(1).Alpha = 0

gRect.UpperLeft = 0
gRect.LowerRight = 1

GradientFill Me.hdc, vert(0), 2, gRect, 1, GRADIENT_FILL_RECT_H
End Sub
...全文
199 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
紫焰月读 2002-05-07
  • 打赏
  • 举报
回复
非常感谢大家,我找到问题的所在了,是出在声明时漏写的传值的标志,谢谢大家热心帮助,我结贴了。^-^
water_j 2002-05-06
  • 打赏
  • 举报
回复
参考代码:

Private Type TRIVERTEX
x As Long
y As Long
Red As Integer 'Ushort value
Green As Integer 'Ushort value
Blue As Integer 'ushort value
Alpha As Integer 'ushort
End Type
Private Type GRADIENT_RECT
UpperLeft As Long 'In reality this is a UNSIGNED Long
LowerRight As Long 'In reality this is a UNSIGNED Long
End Type

Const GRADIENT_FILL_RECT_H As Long = &H0 'In this mode, two endpoints describe a rectangle. The rectangle is
'defined to have a constant color (specified by the TRIVERTEX structure) for the left and right edges. GDI interpolates
'the color from the top to bottom edge and fills the interior.
Const GRADIENT_FILL_RECT_V As Long = &H1 'In this mode, two endpoints describe a rectangle. The rectangle
' is defined to have a constant color (specified by the TRIVERTEX structure) for the top and bottom edges. GDI interpolates
' the color from the top to bottom edge and fills the interior.
Const GRADIENT_FILL_TRIANGLE As Long = &H2 'In this mode, an array of TRIVERTEX structures is passed to GDI
'along with a list of array indexes that describe separate triangles. GDI performs linear interpolation between triangle vertices
'and fills the interior. Drawing is done directly in 24- and 32-bpp modes. Dithering is performed in 16-, 8.4-, and 1-bpp mode.
Const GRADIENT_FILL_OP_FLAG As Long = &HFF

Private Declare Function GradientFillRect Lib "msimg32" Alias "GradientFill" (ByVal hdc As Long, pVertex As TRIVERTEX, ByVal dwNumVertex As Long, pMesh As GRADIENT_RECT, ByVal dwNumMesh As Long, ByVal dwMode As Long) As Long
Private Function LongToUShort(Unsigned As Long) As Integer
'A small function to convert from long to unsigned short
LongToUShort = CInt(Unsigned - &H10000)
End Function
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'API uses pixels
Me.ScaleMode = vbPixels
End Sub
Private Sub Form_Paint()
Dim vert(1) As TRIVERTEX
Dim gRect As GRADIENT_RECT

'from black
With vert(0)
.x = 0
.y = 0
.Red = 0&
.Green = 0& '&HFF& '0&
.Blue = 0&
.Alpha = 0&
End With

'to blue
With vert(1)
.x = Me.ScaleWidth
.y = Me.ScaleHeight
.Red = 0&
.Green = 0&
.Blue = LongToUShort(&HFF00&)
.Alpha = 0&
End With

gRect.UpperLeft = 0
gRect.LowerRight = 1

GradientFillRect Me.hdc, vert(0), 2, gRect, 1, GRADIENT_FILL_RECT_H
End Sub
water_j 2002-05-06
  • 打赏
  • 举报
回复
是不是To draw a shaded rectangle from [0,0] to [100,32],?
顶点的位置问题?
water_j 2002-05-06
  • 打赏
  • 举报
回复
If the function fails, the return value is FALSE
GradientFill Me.hdc, vert(0), 2, gRect, 1, GRADIENT_FILL_RECT_H
返回FALSE
ferrytang 2002-05-06
  • 打赏
  • 举报
回复
www.myvc.net是一个编程技术论坛,为广大编程爱好者提供一个交流技术的空间!
现在,www.myvc.net将为大家提供一个资源下载的空间!第一批将提供<三层结构源代码>
<开发文档模版>两项。
需要者可去以下网址留下email
http://www.myvc.net/dispbbs.asp?boardID=16&RootID=658&ID=658&page=1
我们也提供资源上传的空间,如果你愿意和大家分享你的资源,你可以和www.myvc.net联系
紫焰月读 2002-05-06
  • 打赏
  • 举报
回复
不行
Chice_wxg 2002-05-06
  • 打赏
  • 举报
回复

GradientFill Me.hdc, vert(0), 2, gRect, 1, GRADIENT_FILL_RECT_H
Me.Refresh
End Sub



再试试

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧