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

Jon Chambers joncham at gmail.com
Fri Jul 14 22:54:38 EDT 2006


Jonathan,
      Not sure, but would the hdc need disposed (in the Dispose method) if
the user never calls ReleaseHdc?

Thanks,
Jonathan

On 7/14/06, Sebastien Pouliot <sebastien.pouliot at gmail.com> wrote:
>
> 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/
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060714/a5c7d198/attachment.html 


More information about the Mono-devel-list mailing list