コード例 #1
0
ファイル: Uxtheme.cs プロジェクト: zhaoyin/officeOBA
 public static extern int GetThemePartSize(IntPtr hTheme,
                                           IntPtr hDC,
                                           int partId,
                                           int stateId,
                                           IntPtr rect,
                                           Win32.THEMESIZE themeSize,
                                           ref Win32.SIZE size);
コード例 #2
0
        /// <summary>
        /// Sets the given bitmap as window content with transparent parts via the
        /// layered windows API.
        /// </summary>
        /// <param name="bitmap">The bitmap to set.</param>
        /// <param name="opacity">The overall opacity (255 = opaque).</param>
        public static void SetBitmap(Control control, Bitmap bitmap, int opacity)
        {
            if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");
            }

            IntPtr screenDc  = Win32.GetDC(IntPtr.Zero);
            IntPtr memDc     = Win32.CreateCompatibleDC(screenDc);
            IntPtr hBitmap   = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;

            try
            {
                hBitmap   = bitmap.GetHbitmap(Color.FromArgb(0)); // grab a GDI handle from this GDI+ bitmap
                oldBitmap = Win32.SelectObject(memDc, hBitmap);

                Win32.SIZE          size        = new Win32.SIZE(bitmap.Width, bitmap.Height);
                Win32.POINT         pointSource = new Win32.POINT(0, 0);
                Win32.POINT         topPos      = new Win32.POINT(control.Left, control.Top);
                Win32.BLENDFUNCTION blend       = new Win32.BLENDFUNCTION();
                blend.BlendOp             = Win32.AC_SRC_OVER;
                blend.BlendFlags          = 0;
                blend.SourceConstantAlpha = (byte)opacity;
                blend.AlphaFormat         = Win32.AC_SRC_ALPHA;

                if (!control.IsDisposed && !control.Disposing)
                {
                    Win32.UpdateLayeredWindow(control.Handle, screenDc, ref topPos, ref size, memDc,
                                              ref pointSource, 0, ref blend, Win32.ULW_ALPHA);
                }
            }
            finally
            {
                Win32.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    Win32.SelectObject(memDc, oldBitmap);
                    Win32.DeleteObject(hBitmap);
                }
                Win32.DeleteDC(memDc);
            }
        }
コード例 #3
0
        /// <summary>
        /// Get the size of a themed part in a givenstate.
        /// </summary>
        /// <param name="g">Graphics object reference.</param>
        /// <param name="part">Theme part.</param>
        /// <param name="state">Theme state of part.</param>
        /// <param name="themeSize">How to calculate the size.</param>
        /// <returns>new Size if themed; otherwise Size.Empty</returns>
        public Size GetThemePartSize(Graphics g, int part, int state, THEMESIZE themeSize)
        {
            Size retSize = Size.Empty;

            if (IsControlThemed)
            {
                Win32.SIZE size = new Win32.SIZE();

                IntPtr hDC = g.GetHdc();
                Uxtheme.GetThemePartSize(_hTheme, hDC, part, state, IntPtr.Zero, themeSize, ref size);
                g.ReleaseHdc(hDC);

                // Copy back results
                retSize.Width  = size.cx;
                retSize.Height = size.cy;
            }

            return(retSize);
        }
コード例 #4
0
    /// <summary>
    /// Redraws the bitmap overlay.
    /// </summary>
    /// <returns>True if successful, false otherwise.</returns>
    protected bool RefreshBitmap()
    {
        // The bitmap must be 32-bit RGBA
        if (_bitmap == null || _bitmap.PixelFormat != PixelFormat.Format32bppArgb)
        {
            return(false);
        }

        // Create a memory DC that's compatible with the screen
        IntPtr screenDC = Win32.GetDC(IntPtr.Zero);

        if (screenDC == IntPtr.Zero)
        {
            return(false);
        }

        IntPtr memDC = GDI32.CreateCompatibleDC(screenDC);

        if (memDC == IntPtr.Zero)
        {
            Win32.ReleaseDC(IntPtr.Zero, screenDC);
            return(false);
        }

        // Prepare to draw the bitmap
        IntPtr hBitmap   = IntPtr.Zero;
        IntPtr oldBitmap = IntPtr.Zero;

        bool success = false;

        try
        {
            // Select the bitmap into the memory DC
            hBitmap   = _bitmap.GetHbitmap(Color.FromArgb(0));            // grab a GDI handle from this GDI+ bitmap
            oldBitmap = GDI32.SelectObject(memDC, hBitmap);

            // Call UpdateLayeredWindow to effectively blit the contents of the memory DC into the form while performing alpha blending
            Win32.POINT windowTopLeft = new Win32.POINT(Left, Top);

            Win32.SIZE  bitmapSize    = new Win32.SIZE(_bitmap.Width, _bitmap.Height);
            Win32.POINT bitmapTopLeft = new Win32.POINT(0, 0);

            byte blendAlpha = 0;
            if (_bitmapOpacity < 0)
            {
                blendAlpha = 0;
            }
            else if (_bitmapOpacity > 1)
            {
                blendAlpha = 255;
            }
            else
            {
                blendAlpha = (byte)(_bitmapOpacity * 255);
            }

            GDI32.BLENDFUNCTION blendFunc = new GDI32.BLENDFUNCTION();
            blendFunc.BlendOp             = GDI32.AC_SRC_OVER;
            blendFunc.BlendFlags          = 0;
            blendFunc.SourceConstantAlpha = blendAlpha;
            blendFunc.AlphaFormat         = GDI32.AC_SRC_ALPHA;

            Win32.UpdateLayeredWindow(Handle, screenDC, ref windowTopLeft, ref bitmapSize, memDC, ref bitmapTopLeft, 0, ref blendFunc, Win32.ULW_ALPHA);

            success = true;
        }
        finally
        {
            // Clean up the resources
            if (hBitmap != IntPtr.Zero)
            {
                GDI32.SelectObject(memDC, oldBitmap);
                GDI32.DeleteObject(hBitmap);
            }

            GDI32.DeleteDC(memDC);
            Win32.ReleaseDC(IntPtr.Zero, screenDC);
        }

        return(success);
    }
コード例 #5
0
	/// <summary>
	/// Redraws the bitmap overlay.
	/// </summary>
	/// <returns>True if successful, false otherwise.</returns>
	protected bool RefreshBitmap()
	{
		// The bitmap must be 32-bit RGBA
		if (_bitmap == null || _bitmap.PixelFormat != PixelFormat.Format32bppArgb)
			return false;

		// Create a memory DC that's compatible with the screen
		IntPtr screenDC = Win32.GetDC(IntPtr.Zero);
		if (screenDC == IntPtr.Zero)
			return false;

		IntPtr memDC = GDI32.CreateCompatibleDC(screenDC);
		if (memDC == IntPtr.Zero)
		{
			Win32.ReleaseDC(IntPtr.Zero, screenDC);
			return false;
		}

		// Prepare to draw the bitmap
		IntPtr hBitmap = IntPtr.Zero;
		IntPtr oldBitmap = IntPtr.Zero;

		bool success = false;

		try
		{
			// Select the bitmap into the memory DC
			hBitmap = _bitmap.GetHbitmap(Color.FromArgb(0));  // grab a GDI handle from this GDI+ bitmap
			oldBitmap = GDI32.SelectObject(memDC, hBitmap);

			// Call UpdateLayeredWindow to effectively blit the contents of the memory DC into the form while performing alpha blending
			Win32.POINT windowTopLeft = new Win32.POINT(Left, Top);

			Win32.SIZE bitmapSize = new Win32.SIZE(_bitmap.Width, _bitmap.Height);
			Win32.POINT bitmapTopLeft = new Win32.POINT(0, 0);

			byte blendAlpha = 0;
			if (_bitmapOpacity < 0)
				blendAlpha = 0;
			else if (_bitmapOpacity > 1)
				blendAlpha = 255;
			else
				blendAlpha = (byte)(_bitmapOpacity * 255);

			GDI32.BLENDFUNCTION blendFunc = new GDI32.BLENDFUNCTION();
			blendFunc.BlendOp = GDI32.AC_SRC_OVER;
			blendFunc.BlendFlags = 0;
			blendFunc.SourceConstantAlpha = blendAlpha;
			blendFunc.AlphaFormat = GDI32.AC_SRC_ALPHA;

			Win32.UpdateLayeredWindow(Handle, screenDC, ref windowTopLeft, ref bitmapSize, memDC, ref bitmapTopLeft, 0, ref blendFunc, Win32.ULW_ALPHA);

			success = true;
		}
		finally
		{
			// Clean up the resources
			if (hBitmap != IntPtr.Zero)
			{
				GDI32.SelectObject(memDC, oldBitmap);
				GDI32.DeleteObject(hBitmap);
			}

			GDI32.DeleteDC(memDC);
			Win32.ReleaseDC(IntPtr.Zero, screenDC);
		}

		return success;
	}
コード例 #6
0
    public void SetBits(Bitmap bitmap, byte opacity)
    {
        if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat))
            throw new ApplicationException("The bitmap must be 32 bits per pixel with an alpha channel.");

        IntPtr oldBits = IntPtr.Zero;
        IntPtr screenDC = Win32.GetDC(IntPtr.Zero);
        IntPtr hBitmap = IntPtr.Zero;
        IntPtr memDc = Win32.CreateCompatibleDC(screenDC);
        Win32.POINT topLoc = new Win32.POINT(Left, Top);
        Win32.SIZE bitMapSize = new Win32.SIZE(bitmap.Width, bitmap.Height);
        Win32.BLENDFUNCTION blendFunc = new Win32.BLENDFUNCTION();
        Win32.POINT srcLoc = new Win32.POINT(0, 0);
        blendFunc.BlendOp = Win32.AC_SRC_OVER;
        blendFunc.SourceConstantAlpha = opacity;
        blendFunc.AlphaFormat = Win32.AC_SRC_ALPHA;
        blendFunc.BlendFlags = 0;

        try
        {
            hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
            oldBits = Win32.SelectObject(memDc, hBitmap);
            Win32.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, Win32.ULW_ALPHA);
        }
        finally
        {
            if (hBitmap != IntPtr.Zero)
            {
                Win32.SelectObject(memDc, oldBits);
                Win32.DeleteObject(hBitmap);
            }
            Win32.ReleaseDC(IntPtr.Zero, screenDC);
            Win32.DeleteDC(memDc);
        }
    }
コード例 #7
0
 public static extern int DwmQueryThumbnailSourceSize(
     IntPtr hThumbnailId,
     ref Win32.SIZE size);
コード例 #8
0
 public static extern int DwmRegisterThumbnail(
     IntPtr hwndDestination,
     IntPtr hwndSource,
     ref Win32.SIZE minimizedSize,
     ref IntPtr hThumbnailId);