Hi Geoff,
Tried both methods (GetDC and GetWindowDC) and get 2 different int values so
there must be a difference.
Anyway I've tried GradientFill and get a 'NotSupportedException' with both.
I think I'm doing something wrong.
Have you ever got GradientFill to work? If so, can you spot what's wrong
with my code (see below).
Thanks...Ron
=========================================================================
public struct TRIVERTEX
{
public long x;
public long y;
public int Red;
public int Green;
public int Blue;
public int Alpha;
}
public struct GRADIENT_RECT
{
public long UpperLeft;
public long LowerRight;
}
[DllImport("Coredll.dll", EntryPoint="GetCapture")]
private static extern long GetCapture();
[DllImport("Coredll.dll", EntryPoint="GetDC")]
private static extern long GetDC(long hWnd);
[DllImport("Coredll.dll", EntryPoint="GradientFill")]
public static extern void GradientFill(long hdc, TRIVERTEX[] pVertex,
long dwNumVertex, GRADIENT_RECT pMesh, long dwNumMesh,
long dwMode);
try
{
this.Capture = true;
long hwnd = GetCapture();
this.Capture = false;
long hdc = GetDC(hwnd);
Rectangle r = this.ClientRectangle;
GRADIENT_RECT gRect = new GRADIENT_RECT();
TRIVERTEX[] vert = new TRIVERTEX[2];
vert[0].x = r.Left;
vert[0].y = r.Top;
vert[0].Red = 0x0000;
vert[0].Green = 0x0000;
vert[0].Blue = 0xff00;
vert[0].Alpha = 0x0000;
vert[1].x = r.Right;
vert[1].y = r.Bottom;
vert[1].Red = 0x0000;
vert[1].Green = 0xff00;
vert[1].Blue = 0x0000;
vert[1].Alpha = 0x0000;
gRect.UpperLeft = 0;
gRect.LowerRight = 1;
GradientFill(hdc, vert, 2, gRect, 1, 0);
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
============================================================================
=====
Geoff Schwab said:
Hi,
I am away from my work PC right now so forgive me if this
is not completely accurate but you can do something like
this - I will verify Monday morning with the full
P/Invoke code if needed:
In the Control on which you want to draw...
this.Catpure = true;
P/Invoke GetCapture(); // returns HWND
this.Capture = false;
P/Invoke GetDC(hwnd); // returns DC from HWND above
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
This posting is provided "AS IS" with no warranties, and
confers no rights.