results than trying to invalidate chunks of the desktop. Top level windows
All new articles provide code in C# and VB.NET.
"Gabriel Lozano-Morán" <glozano@no-spam.org> wrote in message
news:ewCbd$XBGHA.2040@TK2MSFTNGP14.phx.gbl...
> Using a mousehook I am drawing the mouse coordinates on the desktopwindow
> when a user hovers the mouse over a certain control. The problem I am
> having
> know I need to invalidate the region where I am drawing the coordinates,
> thus I need to invalidate a specified region on the desktopwindow. I have
> tried it P/Invoke calls to InvalidateRect and RedrawWindow but I guess I
> am
> stuck on the correct params. Can someone also help me with any lead to how
> to use double buffering when drawing on the desktop window.
>
> Subset of the code:
>
> ============================================================================
> ============
> [SuppressUnmanagedCodeSecurity]
> public class SafeNativeMethods
> {
> [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
> public static extern bool InvalidateRect(HandleRef hWnd, ref RECT rect,
> bool erase);
>
> [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
> public static extern bool RedrawWindow(HandleRef hwnd, ref RECT rect,
> HandleRef hrgnUpdate, int flags);
>
> [StructLayout(LayoutKind.Sequential)]
> public struct RECT
> {
> public int left;
> public int top;
> public int right;
> public int bottom;
>
> public RECT(int left, int top, int right, int bottom)
> {
> this.left = left;
> this.top = top;
> this.right = right;
> this.bottom = bottom;
> }
> }
> }
> ============================================================================
> ============
> [SuppressUnmanagedCodeSecurity]
> public sealed class UnsafeNativeMethods
> {
> [DllImport("user32.dll")]
> public static extern IntPtr GetDesktopWindow();
>
> [DllImport("user32.dll")]
> public static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgn, uint
> flags);
>
> [DllImport("user32.dll", EntryPoint="ReleaseDC", CharSet=CharSet.Auto,
> ExactSpelling=true)]
> public static extern int ReleaseDC(HandleRef hWnd, HandleRef hDC);
> }
> ============================================================================
> ============
> ...
> // I left out the constructors and finalizers
> IntPtr hdc =
> UnsafeNativeMethods.GetDCEx(UnsafeNativeMethods.GetDesktopWindow(),
> IntPtr.Zero, 1027);
> Graphics graphics = Graphics.FromHdc(hdc);
> ...
> // The drawing of the string is called from within a mousemove event
> graphics.DrawString(...);
> ...
> ============================================================================
> ============
>
> I am not very experienced in using GDI, so hopefully someone here can help
> me. Any info, lead is strongly appreciated.
>
> Gabriel Lozano-Morán
> MCSD .NET
> Real Software
>
http://www.realdn.net >
http://www.realsoftware.be >
>