예제 #1
0
파일: Form1.cs 프로젝트: CMatri/FadeBar
        public void SelectBitmap(Bitmap bitmap, int opacity)
        {
            // Does this bitmap contain an alpha channel?
            if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new ApplicationException("The bitmap must be 32bpp with alpha-channel.");
            }

            // Get device contexts
            IntPtr screenDc   = GetDC(IntPtr.Zero);
            IntPtr memDc      = CreateCompatibleDC(screenDc);
            IntPtr hBitmap    = IntPtr.Zero;
            IntPtr hOldBitmap = IntPtr.Zero;

            try
            {
                // Get handle to the new bitmap and select it into the current
                // device context.
                hBitmap    = bitmap.GetHbitmap(Color.FromArgb(0));
                hOldBitmap = SelectObject(memDc, hBitmap);

                // Set parameters for layered window update.
                PSize         newSize        = new PSize(bitmap.Width, bitmap.Height);
                PPoint        sourceLocation = new PPoint(0, 0);
                PPoint        newLocation    = new PPoint(this.Left, this.Top);
                BLENDFUNCTION blend          = new BLENDFUNCTION();
                blend.BlendOp             = AC_SRC_OVER;
                blend.BlendFlags          = 0;
                blend.SourceConstantAlpha = (byte)opacity;
                blend.AlphaFormat         = AC_SRC_ALPHA;

                // Update the window.
                UpdateLayeredWindow(
                    this.Handle,        // Handle to the layered window
                    screenDc,           // Handle to the screen DC
                    ref newLocation,    // New screen position of the layered window
                    ref newSize,        // New size of the layered window
                    memDc,              // Handle to the layered window surface DC
                    ref sourceLocation, // Location of the layer in the DC
                    0,                  // Color key of the layered window
                    ref blend,          // Transparency of the layered window
                    ULW_ALPHA           // Use blend as the blend function
                    );
            }
            finally
            {
                // Release device context.
                ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    SelectObject(memDc, hOldBitmap);
                    DeleteObject(hBitmap);
                }
                DeleteDC(memDc);
            }
        }
예제 #2
0
        public override void Load()
        {
            Bind <IKernel>().ToConstant(this.Kernel).InSingletonScope().Named("GlobalKernel");
            Bind <ContextManager>().ToSelf().InSingletonScope();
            Bind <App>().ToSelf().InSingletonScope();

            var sz = new PSize()
            {
                Width = 1080, Height = 1920
            };

            Bind <PSize>().ToConstant(sz).InTransientScope();
        }
예제 #3
0
파일: Form1.cs 프로젝트: CMatri/FadeBar
 static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst,
                                        ref PPoint pptDst, ref PSize psize, IntPtr hdcSrc, ref PPoint pprSrc,
                                        Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
예제 #4
0
 protected void PopulateSize()
 {
     string[] size = { "Large", "Medium", "Small" };
     PSize.DataSource = size;
     PSize.DataBind();
 }