public void DrawBackground(GraphicsContext dc, int partId, int stateId, Rect drawRect, Rect clipRect)
 {
     AssertPartDefined(partId, stateId);
     using (StructureBuffer <Rect> clipRectPtr = new StructureBuffer <Rect>())
     {
         clipRectPtr.Value = clipRect;
         int hr = NativeMethods.DrawThemeBackground(Handle, dc.Handle, partId, stateId, ref drawRect, clipRectPtr.Handle);
         if (hr != 0)
         {
             Marshal.ThrowExceptionForHR(hr);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Creates a new instance of Font.
        /// </summary>
        /// <param name="ptr">
        /// The native handle to the font data.
        /// </param>
        public Font(IntPtr ptr)
        {
            Handle = ptr;

            using (StructureBuffer <LOGFONT> logFontPtr = new StructureBuffer <LOGFONT>())
            {
                int returnedSize = NativeMethods.GetObject(Handle, logFontPtr.Size, logFontPtr.Handle);
                if (logFontPtr.Size != returnedSize)
                {
                    throw new InvalidOperationException($"GetObject() returned incorrect size (got {returnedSize} bytes, expected {logFontPtr.Size} bytes)");
                }
                mFontDescriptor = logFontPtr.Value;
            }
        }
示例#3
0
        public static Font CreateSystemUIFont()
        {
            using (StructureBuffer <NONCLIENTMETRICSW> metricsPtr = new StructureBuffer <NONCLIENTMETRICSW>())
            {
                const int SPI_GETNONCLIENTMETRICS = 0x29;

                NONCLIENTMETRICSW metrics = new NONCLIENTMETRICSW();
                metrics.cbSize   = Marshal.SizeOf <NONCLIENTMETRICSW>();
                metricsPtr.Value = metrics;

                NativeMethods.SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, metricsPtr.Size, metricsPtr.Handle, 0);
                return(new Font(metricsPtr.Value.lfMessageFont));
            }
        }
示例#4
0
        public void ShowPopupMenu(Point windowRelativePosition, Control owner, PopupMenuFlags flags, Rect excludeRect)
        {
            Point screenPosition = windowRelativePosition;
            bool  success        = NativeMethods.ClientToScreen(owner.Handle, ref screenPosition);

            if (!success)
            {
                throw new System.ComponentModel.Win32Exception();
            }

            TPMPARAMS paramStruct = new TPMPARAMS();

            paramStruct.cbStruct  = Convert.ToUInt32(Marshal.SizeOf <TPMPARAMS>());
            paramStruct.rcExclude = excludeRect;

            using (StructureBuffer <TPMPARAMS> ptr = new StructureBuffer <TPMPARAMS>())
            {
                ptr.Value = paramStruct;
                NativeMethods.TrackPopupMenuEx(Handle, (uint)flags, screenPosition.x, screenPosition.y, owner.Handle, ptr.Handle);
            }
        }