[Mono-dev] [PATCH] Implement Graphics.ReleaseHdc()

Sebastien Pouliot sebastien.pouliot at gmail.com
Fri Jul 14 22:50:52 EDT 2006


Hello Jonathan,

Please add a space before the starting parenthesis (see Mono source code
guidelines in the wiki) and, more importantly, provide some unit test
cases for ReleaseHdc (e.g. what happens on a second call to
ReleaseHdc ?). 

I'll commit everything asap (or, at worse, when I get back from
vacations).

Thanks!

On Fri, 2006-07-14 at 18:04 -0500, Jonathan Pobst wrote:
> Patch to implement 2.0 parameterless Graphics.ReleaseHdc()
> 
> - Creates a private variable to hold the IntPtr that GetHdc() returns.
> - Stores IntPtr to private variable in GetHdc().
> - In ReleaseHdc(), call ReleaseHdc(IntPtr) passing stored IntPtr.
> - Set private variable back to IntPtr.Zero.

> Please review and commit.
> 
> Thanks,
> Jonathan
> plain text document attachment (graphicsreleasehdc.patch)
> Index: Graphics.cs
> ===================================================================
> --- Graphics.cs	(revision 62615)
> +++ Graphics.cs	(working copy)
> @@ -52,6 +52,9 @@
>  		private bool disposed = false;
>  		private static float defDpiX = 0;
>  		private static float defDpiY = 0;
> +#if NET_2_0
> +		internal IntPtr deviceContextHdc = IntPtr.Zero;
> +#endif
>  
>  #if !NET_2_0
>  		[ComVisible(false)]
> @@ -1771,6 +1774,9 @@
>  		{
>  			IntPtr hdc;
>  			GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out hdc));
> +#if NET_2_0
> +			deviceContextHdc = hdc;
> +#endif
>  			return hdc;
>  		}
>  
> @@ -2034,11 +2040,18 @@
>  		{
>  			Status status = GDIPlus.GdipReleaseDC (nativeObject, hdc);
>  			GDIPlus.CheckStatus (status);
> +
> +#if NET_2_0
> +			if(hdc == deviceContextHdc)
> +				deviceContextHdc = IntPtr.Zero;
> +#endif
> +
>  		}
>  #if NET_2_0
>  		public void ReleaseHdc()
>  		{
> -		      
> +			if(deviceContextHdc != IntPtr.Zero)
> +				ReleaseHdc(deviceContextHdc);
>  		}
>  #endif
>  		[MonoTODO]
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
-- 
Sebastien Pouliot  <sebastien at ximian.com>
Blog: http://pages.infinit.net/ctech/




More information about the Mono-devel-list mailing list