Esempio n. 1
0
        public virtual void UpdateWindow(Nub nub, Bitmap buffer)
        {
            if (buffer == null || buffer.PixelFormat == 0) {
                return;
            }

            IntPtr dcMemory = default(IntPtr);
            dcMemory = CreateCompatibleDC(IntPtr.Zero);

            // calculate the new window position/size based on the bitmap size
            POINTAPI ptWindowScreenPosition = default(POINTAPI);
            ptWindowScreenPosition.x = nub.Left;
            ptWindowScreenPosition.y = nub.Top;

            ST_SIZE szWindow = default(ST_SIZE);
            szWindow.hSize = nub.Height;
            szWindow.vSize = nub.Width;

            // setup the blend function
            BLENDFUNCTION blendPixelFunction = new BLENDFUNCTION() {
                BlendOp = AC_SRC_OVER,
                BlendFlags = 0,
                SourceConstantAlpha = 255,
                AlphaFormat = AC_SRC_ALPHA
            };

            POINTAPI ptSrc = default(POINTAPI);
            // start point of the copy from dcMemory to dcScreen
            ptSrc.x = 0;
            ptSrc.y = 0;

            //This is where anything needs to get drawn to be shown or updated on the window
            using (Graphics g = Graphics.FromImage(buffer)) {
                Draw(nub, g);
            }

            // perform the alpha blend
            IntPtr useBmp = IntPtr.Zero;
            useBmp = buffer.GetHbitmap(Color.FromArgb(0));
            IntPtr bmpOld = IntPtr.Zero;
            bmpOld = SelectObject(dcMemory, useBmp);

            try {
                UpdateLayeredWindow(
                    nub.Handle,
                    IntPtr.Zero,
                    ref ptWindowScreenPosition,
                    ref szWindow,
                    dcMemory,
                    ref ptSrc,
                    0,
                    ref blendPixelFunction,
                    ULW_ALPHA
                );

            }
            catch (System.ObjectDisposedException) { }
            catch (Exception) { }

            SelectObject(dcMemory, bmpOld);
            DeleteObject(useBmp);
            DeleteObject(bmpOld);
            ReleaseDC(IntPtr.Zero, dcMemory);
            DeleteDC(dcMemory);

            dcMemory = IntPtr.Zero;
            bmpOld = IntPtr.Zero;
            useBmp = IntPtr.Zero;
        }
Esempio n. 2
0
        private void window_NeedsSumNubbin(object sender, WindowBoundsEventArgs e)
        {
            Nub nub = null;
            Rectangle windowRect = e.Rect.ToRectangle();

            if (_nubs.ContainsKey(e.Handle)) {

                nub = _nubs[e.Handle];
                nub.Renub(windowRect);

                return;
            }

            nub = new Nub() {
                WindowEdge = e.Edge,
                WindowHandle = e.Handle,
                WindowRect = windowRect,
                LastWindowRect = e.LastRect.ToRectangle()
            };

            _nubs.Add(e.Handle, nub);

            nub.FormClosing += nub_FormClosing;
            nub.Show();
        }
Esempio n. 3
0
 public static void Draw(Nub nub, Graphics g)
 {
     SizeF textSize = g.MeasureString(String.Concat(nub.WindowText, "W"), Theme.Current.Font);
 }