Exemple #1
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case FormStyleAPI.WM_NCPAINT:
                if (m_aeroEnabled)
                {
                    var v = 2;
                    FormStyleAPI.DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                    FormStyleAPI.MARGINS margins = new FormStyleAPI.MARGINS()
                    {
                        bottomHeight = 1,
                        leftWidth    = 0,
                        rightWidth   = 0,
                        topHeight    = 0
                    };
                    FormStyleAPI.DwmExtendFrameIntoClientArea(this.Handle, ref margins);
                }
                break;

            default:
                break;
            }
            base.WndProc(ref m);

            //폼 드레그시 이동 가능하게
            if (m_bDrag)
            {
                if (m.Msg == FormStyleAPI.WM_NCHITTEST && (int)m.Result == FormStyleAPI.HTCLIENT)
                {
                    m.Result = (IntPtr)FormStyleAPI.HTCAPTION;
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// 拖动窗口移动
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void LBHeadTitle_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         FormStyleAPI.ReleaseCapture();
         FormStyleAPI.SendMessage(Handle, FormStyleAPI.WM_NCLBUTTONDOWN, FormStyleAPI.HTCAPTION, 0);
     }
 }
Exemple #3
0
 /// <summary>
 /// 设置无标题窗口可拖动
 /// </summary>
 /// <param name="e"></param>
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (e.Button == MouseButtons.Left)
     {
         FormStyleAPI.ReleaseCapture();
         FormStyleAPI.SendMessage(Handle, FormStyleAPI.WM_NCLBUTTONDOWN, FormStyleAPI.HTCAPTION, 0);
     }
 }
Exemple #4
0
        public void SetImageUpdateLayeredWindow(Bitmap image, int newOpacity = 255)
        {
            if (image == null)
            {
                return;
            }

            if (image.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");
            }

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

            try
            {
                hBitmap = image.GetHbitmap(Color.FromArgb(0));

                oldBitmap = FormStyleAPI.SelectObject(memDc, hBitmap);

                var size = new FormStyleAPI.Size {
                    cx = image.Width, cy = image.Height
                };

                var pointSource = new FormStyleAPI.Point {
                    x = 0, y = 0
                };

                var topPos = new FormStyleAPI.Point {
                    x = Left, y = Top
                };

                var blend = new FormStyleAPI.BLENDFUNCTION
                {
                    BlendOp             = FormStyleAPI.AC_SRC_OVER,
                    BlendFlags          = 0,
                    SourceConstantAlpha = (byte)newOpacity,
                    AlphaFormat         = FormStyleAPI.AC_SRC_ALPHA
                };

                FormStyleAPI.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, FormStyleAPI.ULW_ALPHA);
            }
            finally
            {
                FormStyleAPI.ReleaseDC(IntPtr.Zero, screenDc);

                if (hBitmap != IntPtr.Zero)
                {
                    FormStyleAPI.SelectObject(memDc, oldBitmap);
                    FormStyleAPI.DeleteObject(hBitmap);
                }
                FormStyleAPI.DeleteDC(memDc);
            }
        }
Exemple #5
0
 public void frmMain_MouseMove()
 {
     try
     {
         FormStyleAPI.ReleaseCapture();
         FormStyleAPI.SendMessage(Handle, FormStyleAPI.WM_NCLBUTTONDOWN, FormStyleAPI.HTCAPTION, 0);
     }
     catch {}
 }
Exemple #6
0
        private bool CheckAeroEnabled()
        {
            if (Environment.OSVersion.Version.Major >= 6)
            {
                //Environment.OSVersion.Version.Minor == 0 //Windows Vista
                //Environment.OSVersion.Version.Minor == 1//Windows 7
                //Environment.OSVersion.Version.Minor == 2//Windows 8

                int enabled = 0;
                FormStyleAPI.DwmIsCompositionEnabled(ref enabled);
                return((enabled == 1) ? true : false);
            }
            return(false);
        }
Exemple #7
0
        public void SetBits()
        {
            if (BackgroundImage != null)
            {
                //绘制绘图层背景
                Bitmap bitmap = new Bitmap(BackgroundImage, base.Width, base.Height);
                if (!Image.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Image.IsAlphaPixelFormat(bitmap.PixelFormat))
                {
                    throw new ApplicationException("图片必须是32位带Alhpa通道的图片。");
                }
                IntPtr oldBits  = IntPtr.Zero;
                IntPtr screenDC = FormStyleAPI.GetDC(IntPtr.Zero);
                IntPtr hBitmap  = IntPtr.Zero;
                IntPtr memDc    = FormStyleAPI.CreateCompatibleDC(screenDC);

                try
                {
                    FormStyleAPI.Point         topLoc     = new FormStyleAPI.Point(Left, Top);
                    FormStyleAPI.Size          bitMapSize = new FormStyleAPI.Size(Width, Height);
                    FormStyleAPI.BLENDFUNCTION blendFunc  = new FormStyleAPI.BLENDFUNCTION();
                    FormStyleAPI.Point         srcLoc     = new FormStyleAPI.Point(0, 0);

                    hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
                    oldBits = FormStyleAPI.SelectObject(memDc, hBitmap);

                    blendFunc.BlendOp             = FormStyleAPI.AC_SRC_OVER;
                    blendFunc.SourceConstantAlpha = Byte.Parse(((int)(Main.Opacity * 255)).ToString());
                    blendFunc.AlphaFormat         = FormStyleAPI.AC_SRC_ALPHA;
                    blendFunc.BlendFlags          = 0;

                    FormStyleAPI.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, FormStyleAPI.ULW_ALPHA);
                }
                finally
                {
                    if (hBitmap != IntPtr.Zero)
                    {
                        FormStyleAPI.SelectObject(memDc, oldBits);
                        FormStyleAPI.DeleteObject(hBitmap);
                    }
                    FormStyleAPI.ReleaseDC(IntPtr.Zero, screenDC);
                    FormStyleAPI.DeleteDC(memDc);
                    bitmap.Dispose();
                }
            }
        }