Hi there,
I am trying to use GradientFillRec t in a VB.NET application.
Does anyone have any examples of the correct PInvoke signature and
marshaling that I need to perform in order to achieve this?
BTW, I do not want to use .Nets gradient fill capabilities, and so far I
have this.
----------------------------------------------
Private Const GRADIENT_FILL_R ECT_H As Long = &H0
Private Const GRADIENT_FILL_R ECT_V As Long = &H1
<StructLayout(L ayoutKind.Seque ntial)_
Public Structure TRIVERTEX
Public x As Int32
Public y As Int32
Public Red As Int16
Public Green As Int16
Public Blue As Int16
Public Alpha As Int16
End Structure
<StructLayout(L ayoutKind.Seque ntial)_
Public Structure GRADIENT_RECT
Public UpperLeft As Integer
Public LowerRight As Integer
End Structure
<DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
ByVal pVertex As IntPtr, _
ByVal dwNumVertex As Integer, _
ByRef pMesh As GRADIENT_RECT, _
ByVal dwNumMesh As Integer, _
ByVal dwMode As Long) As Integer
End Function
Private Sub doGradientFill( ByVal iGraphics As Graphics, _
ByVal iSize As Size)
'//--------------------------------------------------
With iGraphics
Dim pTVxVert(2) As TRIVERTEX
Dim pGRtRect As GRADIENT_RECT
pTVxVert(0).x = 0
pTVxVert(0).y = 0
pTVxVert(0).Red = (Color.Green.R)
pTVxVert(0).Gre en = (Color.Green.G)
pTVxVert(0).Blu e = (Color.Green.B)
pTVxVert(0).Alp ha = (Color.Green.A)
pTVxVert(1).x = iSize.Width
pTVxVert(1).y = iSize.Height
pTVxVert(1).Red = (Color.Red.R)
pTVxVert(1).Gre en = (Color.Red.G)
pTVxVert(1).Blu e = (Color.Red.B)
pTVxVert(1).Alp ha = (Color.Red.A)
pGRtRect.UpperL eft = 0
pGRtRect.LowerR ight = 1
Dim pIPrVert As IntPtr =
Marshal.AllocHG lobal(Marshal.S izeOf(pTVxVert) )
Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
GRADIENT_FILL_R ECT_H)
'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
GRADIENT_FILL_R ECT_V)
Call iGraphics.Relea seHdc(pIPrHDC)
End With
End Sub
----------------------------------------------
Unfortunately this does not work as pTVxVert is an array and the size
cannot be calculated correctly. Any ideas?
Many thanks in advance.
Nick.
I am trying to use GradientFillRec t in a VB.NET application.
Does anyone have any examples of the correct PInvoke signature and
marshaling that I need to perform in order to achieve this?
BTW, I do not want to use .Nets gradient fill capabilities, and so far I
have this.
----------------------------------------------
Private Const GRADIENT_FILL_R ECT_H As Long = &H0
Private Const GRADIENT_FILL_R ECT_V As Long = &H1
<StructLayout(L ayoutKind.Seque ntial)_
Public Structure TRIVERTEX
Public x As Int32
Public y As Int32
Public Red As Int16
Public Green As Int16
Public Blue As Int16
Public Alpha As Int16
End Structure
<StructLayout(L ayoutKind.Seque ntial)_
Public Structure GRADIENT_RECT
Public UpperLeft As Integer
Public LowerRight As Integer
End Structure
<DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
ByVal pVertex As IntPtr, _
ByVal dwNumVertex As Integer, _
ByRef pMesh As GRADIENT_RECT, _
ByVal dwNumMesh As Integer, _
ByVal dwMode As Long) As Integer
End Function
Private Sub doGradientFill( ByVal iGraphics As Graphics, _
ByVal iSize As Size)
'//--------------------------------------------------
With iGraphics
Dim pTVxVert(2) As TRIVERTEX
Dim pGRtRect As GRADIENT_RECT
pTVxVert(0).x = 0
pTVxVert(0).y = 0
pTVxVert(0).Red = (Color.Green.R)
pTVxVert(0).Gre en = (Color.Green.G)
pTVxVert(0).Blu e = (Color.Green.B)
pTVxVert(0).Alp ha = (Color.Green.A)
pTVxVert(1).x = iSize.Width
pTVxVert(1).y = iSize.Height
pTVxVert(1).Red = (Color.Red.R)
pTVxVert(1).Gre en = (Color.Red.G)
pTVxVert(1).Blu e = (Color.Red.B)
pTVxVert(1).Alp ha = (Color.Red.A)
pGRtRect.UpperL eft = 0
pGRtRect.LowerR ight = 1
Dim pIPrVert As IntPtr =
Marshal.AllocHG lobal(Marshal.S izeOf(pTVxVert) )
Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
GRADIENT_FILL_R ECT_H)
'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
GRADIENT_FILL_R ECT_V)
Call iGraphics.Relea seHdc(pIPrHDC)
End With
End Sub
----------------------------------------------
Unfortunately this does not work as pTVxVert is an array and the size
cannot be calculated correctly. Any ideas?
Many thanks in advance.
Nick.
Comment