コード例 #1
0
ファイル: DeviceContext.cs プロジェクト: jaemilton/winforms
        /// <include file='doc\IDeviceContext.uex' path='docs/doc[@for="DeviceContext.GetHdc"]/*' />
        /// <devdoc>
        ///     Explicit interface method implementation to hide them a bit for usability reasons so the object is seen
        ///     as a wrapper around an hdc that is always available, and for performance reasons since it caches the hdc
        ///     if used in this way.
        /// </devdoc>


        IntPtr IDeviceContext.GetHdc()
        {
            if (this.hDC == IntPtr.Zero)
            {
                Debug.Assert(this.dcType == DeviceContextType.Display, "Calling GetDC from a non display/window device.");

                // Note: for common DCs, GetDC assigns default attributes to the DC each time it is retrieved.
                // For example, the default font is System.
                this.hDC = IntUnsafeNativeMethods.GetDC(new HandleRef(this, this.hWnd));
#if TRACK_HDC
                Debug.WriteLine(DbgUtil.StackTraceToStr(String.Format("hdc[0x{0:x8}]=DC.GetHdc(hWnd=0x{1:x8})", unchecked ((int)this.hDC), unchecked ((int)this.hWnd))));
#endif
            }

            return(this.hDC);
        }