コード例 #1
0
ファイル: NativeMethods.cs プロジェクト: yzwbrian/winform-ui
 [DllImport("user32.dll")]//在桌面找寻子窗体
 public static extern IntPtr ChildWindowFromPointEx(IntPtr pHwnd, NativeMethods.Point pt, uint uFlgs);
コード例 #2
0
ファイル: SkinForm.cs プロジェクト: panshuiqing/winform-ui
        public void SetBits()
        {
            if (BackgroundImage != null)
            {
                //绘制绘图层背景
                Bitmap bitmap = new Bitmap(BackgroundImage, base.Width, base.Height);
                if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat))
                    throw new ApplicationException("图片必须是32位带Alhpa通道的图片。");
                IntPtr oldBits = IntPtr.Zero;
                IntPtr screenDC = NativeMethods.GetDC(IntPtr.Zero);
                IntPtr hBitmap = IntPtr.Zero;
                IntPtr memDc = NativeMethods.CreateCompatibleDC(screenDC);

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

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

                    blendFunc.BlendOp = AC.AC_SRC_OVER;
                    blendFunc.SourceConstantAlpha = Byte.Parse("255");
                    blendFunc.AlphaFormat = AC.AC_SRC_ALPHA;
                    blendFunc.BlendFlags = 0;

                    NativeMethods.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, NativeMethods.ULW_ALPHA);
                }
                finally
                {
                    if (hBitmap != IntPtr.Zero)
                    {
                        NativeMethods.SelectObject(memDc, oldBits);
                        NativeMethods.DeleteObject(hBitmap);
                    }
                    NativeMethods.ReleaseDC(IntPtr.Zero, screenDC);
                    NativeMethods.DeleteDC(memDc);
                }
            }
        }
コード例 #3
0
ファイル: CCSkinForm.cs プロジェクト: panshuiqing/winform-ui
        public void SetBits()
        {
            //绘制绘图层背景
            Bitmap bitmap = new Bitmap(Main.Width + Main.ShadowWidth * 2, Main.Height + Main.ShadowWidth * 2);
            //Rectangle _BacklightLTRB = new Rectangle(20, 20, 20, 20);//窗体光泽重绘边界
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.HighQuality; //高质量
            g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量

            DrawShadow(g);
            //ImageDrawRect.DrawRect(g, Properties.Resources.main_light_bkg_top123, ClientRectangle, Rectangle.FromLTRB(_BacklightLTRB.X, _BacklightLTRB.Y, _BacklightLTRB.Width, _BacklightLTRB.Height), 1, 1);

            if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat))
                throw new ApplicationException("图片必须是32位带Alhpa通道的图片。");
            IntPtr oldBits = IntPtr.Zero;
            IntPtr screenDC = NativeMethods.GetDC(IntPtr.Zero);
            IntPtr hBitmap = IntPtr.Zero;
            IntPtr memDc = NativeMethods.CreateCompatibleDC(screenDC);

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

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

                blendFunc.BlendOp = AC.AC_SRC_OVER;
                blendFunc.SourceConstantAlpha = Byte.Parse("255");
                blendFunc.AlphaFormat = AC.AC_SRC_ALPHA;
                blendFunc.BlendFlags = 0;

                NativeMethods.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, NativeMethods.ULW_ALPHA);
            }
            finally
            {
                if (hBitmap != IntPtr.Zero)
                {
                    NativeMethods.SelectObject(memDc, oldBits);
                    NativeMethods.DeleteObject(hBitmap);
                }
                NativeMethods.ReleaseDC(IntPtr.Zero, screenDC);
                NativeMethods.DeleteDC(memDc);
            }
        }
コード例 #4
0
        private ScrollBarHistTest ScrollBarHitTest(IntPtr hWnd)
        {
            NativeMethods.Point point = new NativeMethods.Point();
            RECT rect = new RECT();
            Point thumbPoint = GetScrollBarThumb();

            int arrowCx = ArrowCx;
            int arrowCy = ArrowCy;

            NativeMethods.GetWindowRect(hWnd, ref rect);
            NativeMethods.OffsetRect(ref rect, -rect.Left, -rect.Top);

            RECT tp = rect;
            NativeMethods.GetCursorPos(ref point);
            NativeMethods.ScreenToClient(hWnd, ref point);

            if (Direction == Orientation.Horizontal)
            {
                if (NativeMethods.PtInRect(ref rect, point))
                {
                    // left arrow
                    tp.Right = arrowCx;
                    if (NativeMethods.PtInRect(ref tp, point))
                    {
                        return ScrollBarHistTest.LeftArrow;
                    }
                    // right arrow
                    tp.Left = rect.Right - arrowCx;
                    tp.Right = rect.Right;
                    if (NativeMethods.PtInRect(ref tp, point))
                    {
                        return ScrollBarHistTest.RightArrow;
                    }

                    // button
                    if (_owner.RightToLeft == RightToLeft.Yes)
                    {
                        tp.Left = point.y;
                        tp.Right = point.x;
                    }
                    else
                    {
                        tp.Left = thumbPoint.X;
                        tp.Right = thumbPoint.Y;
                    }
                    if (NativeMethods.PtInRect(ref tp, point))
                    {
                        return ScrollBarHistTest.Thumb;
                    }
                    // track
                    return ScrollBarHistTest.Track;
                }
            }
            else
            {
                if (NativeMethods.PtInRect(ref rect, point))
                {
                    // top arrow
                    tp.Bottom = arrowCy;
                    if (NativeMethods.PtInRect(ref tp, point))
                    {
                        return ScrollBarHistTest.TopArrow;
                    }
                    // bottom arrow
                    tp.Top = rect.Bottom - arrowCy;
                    tp.Bottom = rect.Bottom;
                    if (NativeMethods.PtInRect(ref tp, point))
                    {
                        return ScrollBarHistTest.BottomArrow;
                    }
                    // button
                    tp.Top = thumbPoint.X;
                    tp.Bottom = thumbPoint.Y;
                    if (NativeMethods.PtInRect(ref tp, point))
                    {
                        return ScrollBarHistTest.Thumb;
                    }
                    // track
                    return ScrollBarHistTest.Track;
                }
            }
            return ScrollBarHistTest.None;
        }
コード例 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hWnd">被覆盖控件句柄。</param>
        internal void CreateParamsInternal(IntPtr hWnd)
        {
            IntPtr hParent = NativeMethods.GetParent(hWnd);
            RECT rect = new RECT();
            NativeMethods.Point point = new NativeMethods.Point();

            NativeMethods.GetWindowRect(hWnd, ref rect);
            point.x = rect.Left;
            point.y = rect.Top;
            NativeMethods.ScreenToClient(hParent, ref point);

            int dwStyle =
                SS.SS_OWNERDRAW |
                WS.WS_CHILD |
                WS.WS_CLIPSIBLINGS |
                WS.WS_OVERLAPPED | WS.WS_VISIBLE;
            int dwExStyle = WS_EX.WS_EX_TOPMOST | WS_EX.WS_EX_TOOLWINDOW;
            _createParams = new CreateParams();

            _createParams.Parent = hParent;
            _createParams.ClassName = ClassName.STATIC;
            _createParams.Caption = null;
            _createParams.Style = dwStyle;
            _createParams.ExStyle = dwExStyle;
            _createParams.X = point.x;
            _createParams.Y = point.y;
            _createParams.Width = rect.Right - rect.Left;
            _createParams.Height = rect.Bottom - rect.Top;
        }
コード例 #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hWnd">被覆盖控件句柄。</param>
        internal void CheckBounds(IntPtr hWnd)
        {
            RECT controlRect = new RECT();
            RECT maskRect = new RECT();

            NativeMethods.GetWindowRect(base.Handle, ref maskRect);
            NativeMethods.GetWindowRect(hWnd, ref controlRect);

            uint uFlag =
                SWP.SWP_NOACTIVATE |
                SWP.SWP_NOOWNERZORDER |
                SWP.SWP_NOZORDER;

            if (!NativeMethods.EqualRect(ref controlRect, ref maskRect))
            {
                NativeMethods.Point point = new NativeMethods.Point(controlRect.Left, controlRect.Top);
                IntPtr hParent = NativeMethods.GetParent(base.Handle);
                NativeMethods.ScreenToClient(hParent, ref point);

                NativeMethods.SetWindowPos(
                    base.Handle,
                    IntPtr.Zero,
                    point.x,
                    point.y,
                    controlRect.Right - controlRect.Left,
                    controlRect.Bottom - controlRect.Top,
                    uFlag);
            }
        }