Gradient Fill Triangle Problems

F

Florian Zierer

Hi all,

I have problems using GRADIENT_FILL_TRIANGLE with PInvoke on Windows
Mobile 6.0

GRADIENT_FILL_RECT_H (or _V) works as expected but with triangles I just
get an "Invalid Parameter" error (code 87) from GetLastWin32Error() but
I don't understand where the problem is.

drawRectangle(IntPtr hdc) works but drawTriangle(IntPtr hdc) fails with
error 87.

Can anyone help?

Thanks
Flo

my class looks like this:



class Graphic
{

public struct TRIVERTEX
{
public int x;
public int y;
public ushort Red;
public ushort Green;
public ushort Blue;
public ushort Alpha;
public TRIVERTEX(int x, int y, Color color)
: this(x, y, color.R, color.G, color.B, color.A)
{
}
public TRIVERTEX(
int x, int y,
ushort red, ushort green, ushort blue,
ushort alpha)
{
this.x = x;
this.y = y;
this.Red = (ushort)(red << 8);
this.Green = (ushort)(green << 8);
this.Blue = (ushort)(blue << 8);
this.Alpha = (ushort)(alpha << 8);
}
}
public struct GRADIENT_RECT
{
public uint UpperLeft;
public uint LowerRight;
public GRADIENT_RECT(uint ul, uint lr)
{
this.UpperLeft = ul;
this.LowerRight = lr;
}
}

public struct GRADIENT_TRIANGLE
{
public uint Vertex1;
public uint Vertex2;
public uint Vertex3;
public GRADIENT_TRIANGLE(uint v1, uint v2, uint v3)
{
this.Vertex1 = v1;
this.Vertex2 = v2;
this.Vertex3 = v3;
}
}


public static bool drawTriangle(IntPtr hdc)
{

TRIVERTEX[] vert = new TRIVERTEX[4];
vert[0] = new TRIVERTEX(0, 0, Color.Green);
vert[1] = new TRIVERTEX(0, 100, Color.Green);
vert[2] = new TRIVERTEX(100, 100, Color.Red);
vert[3] = new TRIVERTEX(100, 0, Color.Green);

GRADIENT_TRIANGLE[] gTri = new GRADIENT_TRIANGLE[] { new
GRADIENT_TRIANGLE(0,1,2),new GRADIENT_TRIANGLE(0,2,3)};

return GradientFill(hdc, vert, (uint)vert.Length, gTri,
(uint)gTri.Length, GRADIENT_FILL_TRIANGLE);
}

public static bool drawRectangle(IntPtr hdc)
{
TRIVERTEX[] tva = new TRIVERTEX[2];
tva[0] = new TRIVERTEX(0, 0, Color.Black);
tva[1] = new TRIVERTEX(100, 100, Color.White);
GRADIENT_RECT[] gra = new GRADIENT_RECT[] { new
GRADIENT_RECT(0, 1) };

return GradientFill(hdc, tva, (uint)tva.Length, gra,
(uint)gra.Length, GRADIENT_FILL_RECT_H);
}



[DllImport("coredll.dll", SetLastError = true, EntryPoint =
"GradientFill")]
public extern static bool GradientFill(
IntPtr hdc,
TRIVERTEX[] pVertex,
uint dwNumVertex,
GRADIENT_RECT[] pMesh,
uint dwNumMesh,
uint dwMode);

[DllImport("coredll.dll", SetLastError = true, EntryPoint =
"GradientFill")]
public extern static bool GradientFill(
IntPtr hdc,
TRIVERTEX[] pVertex,
uint dwNumVertex,
GRADIENT_TRIANGLE[] pMesh,
uint dwNumMesh,
uint dwMode);

public const int GRADIENT_FILL_RECT_H = 0x00000000;
public const int GRADIENT_FILL_RECT_V = 0x00000001;
public const int GRADIENT_FILL_TRIANGLE = 0x00000002;


}
}
 
G

Guest

Take a look at the docs:

http://msdn2.microsoft.com/en-us/library/aa925212.aspx

Specifically the value table for ulMode


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com


Florian Zierer said:
Hi all,

I have problems using GRADIENT_FILL_TRIANGLE with PInvoke on Windows
Mobile 6.0

GRADIENT_FILL_RECT_H (or _V) works as expected but with triangles I just
get an "Invalid Parameter" error (code 87) from GetLastWin32Error() but I
don't understand where the problem is.

drawRectangle(IntPtr hdc) works but drawTriangle(IntPtr hdc) fails with
error 87.

Can anyone help?

Thanks
Flo

my class looks like this:



class Graphic
{

public struct TRIVERTEX
{
public int x;
public int y;
public ushort Red;
public ushort Green;
public ushort Blue;
public ushort Alpha;
public TRIVERTEX(int x, int y, Color color)
: this(x, y, color.R, color.G, color.B, color.A)
{
}
public TRIVERTEX(
int x, int y,
ushort red, ushort green, ushort blue,
ushort alpha)
{
this.x = x;
this.y = y;
this.Red = (ushort)(red << 8);
this.Green = (ushort)(green << 8);
this.Blue = (ushort)(blue << 8);
this.Alpha = (ushort)(alpha << 8);
}
}
public struct GRADIENT_RECT
{
public uint UpperLeft;
public uint LowerRight;
public GRADIENT_RECT(uint ul, uint lr)
{
this.UpperLeft = ul;
this.LowerRight = lr;
}
}

public struct GRADIENT_TRIANGLE
{
public uint Vertex1;
public uint Vertex2;
public uint Vertex3;
public GRADIENT_TRIANGLE(uint v1, uint v2, uint v3)
{
this.Vertex1 = v1;
this.Vertex2 = v2;
this.Vertex3 = v3;
}
}


public static bool drawTriangle(IntPtr hdc)
{

TRIVERTEX[] vert = new TRIVERTEX[4];
vert[0] = new TRIVERTEX(0, 0, Color.Green);
vert[1] = new TRIVERTEX(0, 100, Color.Green);
vert[2] = new TRIVERTEX(100, 100, Color.Red);
vert[3] = new TRIVERTEX(100, 0, Color.Green);

GRADIENT_TRIANGLE[] gTri = new GRADIENT_TRIANGLE[] { new
GRADIENT_TRIANGLE(0,1,2),new GRADIENT_TRIANGLE(0,2,3)};

return GradientFill(hdc, vert, (uint)vert.Length, gTri,
(uint)gTri.Length, GRADIENT_FILL_TRIANGLE);
}

public static bool drawRectangle(IntPtr hdc)
{
TRIVERTEX[] tva = new TRIVERTEX[2];
tva[0] = new TRIVERTEX(0, 0, Color.Black);
tva[1] = new TRIVERTEX(100, 100, Color.White);
GRADIENT_RECT[] gra = new GRADIENT_RECT[] { new
GRADIENT_RECT(0, 1) };

return GradientFill(hdc, tva, (uint)tva.Length, gra,
(uint)gra.Length, GRADIENT_FILL_RECT_H);
}



[DllImport("coredll.dll", SetLastError = true, EntryPoint =
"GradientFill")]
public extern static bool GradientFill(
IntPtr hdc,
TRIVERTEX[] pVertex,
uint dwNumVertex,
GRADIENT_RECT[] pMesh,
uint dwNumMesh,
uint dwMode);

[DllImport("coredll.dll", SetLastError = true, EntryPoint =
"GradientFill")]
public extern static bool GradientFill(
IntPtr hdc,
TRIVERTEX[] pVertex,
uint dwNumVertex,
GRADIENT_TRIANGLE[] pMesh,
uint dwNumMesh,
uint dwMode);

public const int GRADIENT_FILL_RECT_H = 0x00000000;
public const int GRADIENT_FILL_RECT_V = 0x00000001;
public const int GRADIENT_FILL_TRIANGLE = 0x00000002;


}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top