Exemplo n.º 1
0
        private Boolean HitTest(Orientation orient)
        {
            Point         pt = new Point();
            RECT          tr = new RECT();
            RECT          tp = new RECT();
            SCROLLBARINFO sb = new SCROLLBARINFO();

            sb.cbSize = Marshal.SizeOf(sb);

            GetCursorPos(ref pt);

            if (orient == Orientation.Horizontal)
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = sb.rcScrollBar;
                tp = tr;
                if (PtInRect(ref tr, pt))
                {
                    return(true);
                }
            }
            else
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr = sb.rcScrollBar;
                tp = tr;
                if (PtInRect(ref tr, pt))
                {
                    return(true);
                }
            }
            return(false);
        }
        public static int AutoCalcWidth(this ListView listView)
        {
            var sbi = new SCROLLBARINFO();

            sbi.cbSize = Marshal.SizeOf(sbi);

            if (GetScrollBarInfo(listView.Handle, (uint)ScrollObjMask.OBJID_HSCROLL, ref sbi) != 0)
            {
                const int minWidth       = 100;
                var       borderWidth    = SystemInformation.Border3DSize.Width;
                var       scrollBarWidth = SystemInformation.VerticalScrollBarWidth;
                var       scrollBars     = GetVisibleScrollbars(listView);

                if (scrollBars == ScrollBars.Both || scrollBars == ScrollBars.Horizontal)
                {
                    scrollBarWidth = SystemInformation.VerticalScrollBarWidth;
                }
                else
                {
                    scrollBarWidth = 0;
                }

                int state = sbi.rgstate[0];

                var iWidth = 0;
//                var iWidth = si.nMax - si.nMin + 2 * borderWidth + scrollBarWidth + 2;
                return(Math.Max(minWidth, iWidth));
            }
            var error = Marshal.GetLastWin32Error();

            throw new Exception($"Pinvoked GetScrollBarInfo error:{error}");
        }
Exemplo n.º 3
0
            public bool PreFilterMessage(ref Message m)
            {
                Point point;

                switch (m.Msg)
                {
                case 0x201:    //WM_LBUTTONDOWN
                    //Debug.WriteLine(m.HWnd.ToString("X8") + "\t" + m.WParam + "\t" + GetPoint(m.LParam));

                    if ((int)m.WParam != 1)
                    {
                        break;
                    }                                     //仅处理单纯的左键单击

                    var c = Control.FromHandle(m.HWnd);
                    if (c != null && CanDrag(c, (point = GetPoint(m.LParam))))
                    {
                        return(DoDrag(c, point, true));
                    }
                    break;

                case 0xA1:                  //WM_NCLBUTTONDOWN
                    var ht = (int)m.WParam;
                    if (ht == 5 /*HTMENU*/) //点到MainMenu时
                    {
                        //判断是否点到菜单项。若不是或菜单项不可用则拖拽
                        //点击菜单时m.HWnd为窗体句柄而非菜单句柄
                        point = GetPoint(m.LParam);
                        var menu = GetMenu(m.HWnd);
                        var item = MenuItemFromPoint(m.HWnd, menu, (POINT)point);
                        if (item == -1 ||
                            (GetMenuState(menu, item, 0x400 /*MF_BYPOSITION*/) & 2 /*MF_DISABLED*/) == 2)
                        {
                            return(DoDrag(Control.FromHandle(m.HWnd), point, false));
                        }
                    }
                    else if (ht == 4 /*HTSIZE*/ || ht == 18 /*HTBORDER*/)  //点到两个滚动条右下空白、控件边框时
                    {
                        return(DoDrag(Control.FromHandle(m.HWnd), GetPoint(m.LParam), false));
                    }
                    else if (ht == 6 /*HTHSCROLL*/ || ht == 7 /*HTVSCROLL*/)  //点到滚动条时
                    {
                        //获取滚动条状态,若处于无效则拖拽
                        //OBJID_HSCROLL=0xFFFFFFFA
                        //OBJID_VSCROLL=0xFFFFFFFB
                        var           idObject = unchecked ((int)(ht + 0xFFFFFFF4));
                        SCROLLBARINFO sbi      = new SCROLLBARINFO {
                            cbSize = SizeOfSCROLLBARINFO
                        };
                        if (GetScrollBarInfo(m.HWnd, idObject, ref sbi) &&
                            sbi.scrollBarInfo == 1 /*STATE_SYSTEM_UNAVAILABLE*/)
                        {
                            return(DoDrag(Control.FromHandle(m.HWnd), GetPoint(m.LParam), false));
                        }
                    }
                    break;
                }
                return(false);
            }
Exemplo n.º 4
0
        private void DrawScrollBar()
        {
            RECT          tr  = new RECT();
            IntPtr        hdc = IntPtr.Zero;
            SCROLLBARINFO sb  = new SCROLLBARINFO();

            sb.cbSize = Marshal.SizeOf(sb);

            if (HasHorizontal())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = sb.rcScrollBar;
                OffsetRect(ref tr, -tr.Left, -tr.Top);
                hdc = GetDC(_hHorizontalMaskWnd);
                Boolean isMouseOver = HitTest(Orientation.Horizontal);
                Boolean isClick     = IsLeftKeyPressed();
                if (isMouseOver == true)
                {
                    _isFocus = true;
                }
                using (Graphics g = Graphics.FromHdc(hdc))
                {
                    DrawHorizontalScrollBar(g, tr.Right, tr.Bottom, sb.xyThumbTop, sb.xyThumbBottom, _iArrowCx,
                                            isMouseOver, isClick);
                }
                ReleaseDC(_hHorizontalMaskWnd, hdc);
            }

            if (HasSizer())
            {
                hdc = GetDC(_hSizerMaskWnd);
                using (Graphics g = Graphics.FromHdc(hdc))
                {
                    DrawSizer(g, _iArrowCx, _iArrowCy);
                }
                ReleaseDC(_hSizerMaskWnd, hdc);
            }

            if (HasVertical())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr = sb.rcScrollBar;
                OffsetRect(ref tr, -tr.Left, -tr.Top);
                Boolean isMouseOver = HitTest(Orientation.Vertical);
                Boolean isClick     = IsLeftKeyPressed();
                if (isMouseOver == true)
                {
                    _isFocus = true;
                }
                hdc = GetDC(_hVerticalMaskWnd);
                using (Graphics g = Graphics.FromHdc(hdc))
                {
                    DrawVerticalScrollBar(g, tr.Right, tr.Bottom, sb.xyThumbTop, sb.xyThumbBottom, _iArrowCy,
                                          isMouseOver, isClick);
                }
                ReleaseDC(_hVerticalMaskWnd, hdc);
            }
        }
Exemplo n.º 5
0
        private SCROLLBARINFO GetScrollBarInfo(IntPtr hWnd, uint objid)
        {
            SCROLLBARINFO sbi = new SCROLLBARINFO();

            sbi.cbSize = Marshal.SizeOf(sbi);

            NativeMethods.GetScrollBarInfo(hWnd, objid, ref sbi);
            return(sbi);
        }
Exemplo n.º 6
0
        private SCROLLBARINFO GetScrollBarInfo(IntPtr hWnd)
        {
            SCROLLBARINFO scrollbarinfo = new SCROLLBARINFO();

            scrollbarinfo = new SCROLLBARINFO {
                cbSize = Marshal.SizeOf(scrollbarinfo)
            };
            Win32.NativeMethods.SendMessage(hWnd, 0xeb, 0, ref scrollbarinfo);
            return(scrollbarinfo);
        }
Exemplo n.º 7
0
        private SCROLLBARINFO GetScrollBarInfo(IntPtr hWnd, uint objid)
        {
            SCROLLBARINFO scrollbarinfo = new SCROLLBARINFO();

            scrollbarinfo = new SCROLLBARINFO {
                cbSize = Marshal.SizeOf(scrollbarinfo)
            };
            Win32.NativeMethods.GetScrollBarInfo(hWnd, objid, ref scrollbarinfo);
            return(scrollbarinfo);
        }
        /// <summary>
        /// Scroll to the bottom of the current text.
        /// </summary>
        public void ScrollToBottom()
        {
            SCROLLBARINFO sbi = GetBars();

            if (sbi.rgstate[0] == 0)
            {
                SCROLLINFO si = GetScroll();
                SendMessage(this.Handle, EM_SETSCROLLPOS, 0, new POINT(0, si.nMax - (int)si.nPage + 5));
            }
        }
Exemplo n.º 9
0
        private SCROLLBARINFO GetScrollBarInfo(IntPtr hWnd)
        {
            SCROLLBARINFO sbi = new SCROLLBARINFO();

            sbi.cbSize = Marshal.SizeOf(sbi);
            NativeMethods.SendMessage(
                hWnd,
                SBM.SBM_GETSCROLLBARINFO,
                0,
                ref sbi);
            return(sbi);
        }
Exemplo n.º 10
0
        private SCROLLBARINFO GetBars()
        {
            SCROLLBARINFO si = new SCROLLBARINFO();

            si.cbSize = Marshal.SizeOf(si);
            int ret = GetScrollBarInfo(this.Handle, OBJID_VSCROLL, ref si);

            if (ret == 0)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            return(si);
        }
Exemplo n.º 11
0
        public static bool IsVScrollBarVisible(Control control)
        {
            var scrollbarInfo = new SCROLLBARINFO();

            scrollbarInfo.cbSize = (UInt32)Marshal.SizeOf(scrollbarInfo);
            int result = GetScrollBarInfo(control.Handle, NativeMethods.OBJID_VSCROLL, ref scrollbarInfo);

            if (result == 0)
            {
                throw LastWin32Error();
            }
            else
            {
                return(scrollbarInfo.rgstate[0] != STATE_SYSTEM_INVISIBLE);
            }
        }
Exemplo n.º 12
0
        protected override void OnSelectedIndexChanged(EventArgs e)
        {
            base.OnSelectedIndexChanged (e);
            SCROLLBARINFO psbi = new SCROLLBARINFO();
            psbi.cbSize = Marshal.SizeOf(psbi);

            int nResult = GetScrollBarInfo(this.Handle, OBJID_VSCROLL, ref psbi); //"this" is a scrollbar

            if (nResult == 0)
            {
            int nLatError = Marshal.GetLastWin32Error(); // in kernel32.dll
            }

            fCheck=true;
            oldval=psbi.xyThumbTop;
            Console.WriteLine(psbi.xyThumbTop.ToString());
        }
Exemplo n.º 13
0
        public static int CalculateRichTextHeight(RichTextBox _rtb)
        {
            int nHeight = 0;

            SCROLLBARINFO psbi = new SCROLLBARINFO();

            psbi.cbSize     = Marshal.SizeOf(psbi);
            _rtb.ScrollBars = RichTextBoxScrollBars.Vertical;
            int nResult = GetScrollBarInfo(_rtb.Handle, OBJID_VSCROLL, ref psbi);

            if (psbi.rgstate[0] == 0)
            {
                int nMin = 0, nMax = 0;
                GetScrollRange(_rtb.Handle, SB_VERT, out nMin, out nMax);
                nHeight = (nMax - nMin);
            }

            return(nHeight);
        }
Exemplo n.º 14
0
        private void ResizeMask()
        {
            RECT          tr = new RECT();
            SCROLLBARINFO sb = new SCROLLBARINFO();

            sb.cbSize = Marshal.SizeOf(sb);
            IntPtr hParent = GetParent(_hControlWnd);
            Point  pt      = new Point();

            if (HasVertical())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr   = sb.rcScrollBar;
                pt.X = tr.Left;
                pt.Y = tr.Top;
                ScreenToClient(hParent, ref pt);
                SetWindowPos(_hVerticalMaskWnd, IntPtr.Zero, pt.X, pt.Y, tr.Right - tr.Left, tr.Bottom - tr.Top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_SHOWWINDOW);
            }
            if (HasHorizontal())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr   = sb.rcScrollBar;
                pt.X = tr.Left;
                pt.Y = tr.Top;
                ScreenToClient(hParent, ref pt);
                SetWindowPos(_hHorizontalMaskWnd, IntPtr.Zero, pt.X, pt.Y, tr.Right - tr.Left, tr.Bottom - tr.Top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_SHOWWINDOW);
            }
            if (HasSizer())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr   = new RECT(sb.rcScrollBar.Right, sb.rcScrollBar.Top, sb.rcScrollBar.Right + _iArrowCx, sb.rcScrollBar.Bottom);
                pt.X = tr.Left;
                pt.Y = tr.Top;
                ScreenToClient(hParent, ref pt);
                SetWindowPos(_hSizerMaskWnd, IntPtr.Zero, pt.X, pt.Y, tr.Right - tr.Left, tr.Bottom - tr.Top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_SHOWWINDOW);
            }
        }
        private void reSizeMask()
        {
            RECT tr = new RECT();
            SCROLLBARINFO sb = new SCROLLBARINFO();
            sb.cbSize = Marshal.SizeOf(sb);
            IntPtr hParent = GetParent(_hControlWnd);
            Point pt = new Point();

            if (hasVertical())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr = sb.rcScrollBar;
                pt.X = tr.Left;
                pt.Y = tr.Top;
                ScreenToClient(hParent, ref pt);
                SetWindowPos(_hVerticalMaskWnd, IntPtr.Zero, pt.X, pt.Y, tr.Right - tr.Left, tr.Bottom - tr.Top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_SHOWWINDOW);
            }
            if (hasHorizontal())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = sb.rcScrollBar;
                pt.X = tr.Left;
                pt.Y = tr.Top;
                ScreenToClient(hParent, ref pt);
                SetWindowPos(_hHorizontalMaskWnd, IntPtr.Zero, pt.X, pt.Y, tr.Right - tr.Left, tr.Bottom - tr.Top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_SHOWWINDOW);
            }
            if (hasSizer())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = new RECT(sb.rcScrollBar.Right, sb.rcScrollBar.Top, sb.rcScrollBar.Right + _iArrowCx, sb.rcScrollBar.Bottom);
                pt.X = tr.Left;
                pt.Y = tr.Top;
                ScreenToClient(hParent, ref pt);
                SetWindowPos(_hSizerMaskWnd, IntPtr.Zero, pt.X, pt.Y, tr.Right - tr.Left, tr.Bottom - tr.Top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_SHOWWINDOW);
            }
        }
        private SB_HITEST scrollbarHitTest(Orientation orient)
        {
            Point pt = new Point();
            RECT tr = new RECT();
            RECT tp = new RECT();
            SCROLLBARINFO sb = new SCROLLBARINFO();
            sb.cbSize = Marshal.SizeOf(sb);

            GetCursorPos(ref pt);

            if (orient == Orientation.Horizontal)
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = sb.rcScrollBar;
                //OffsetRect(ref tr, -tr.Left, -tr.Top);
                tp = tr;
                if (PtInRect(ref tr, pt))
                {
                    // left arrow
                    tp.Right = tp.Left + _iArrowCx;
                    if (PtInRect(ref tp, pt))
                        return SB_HITEST.leftArrow;
                    // right arrow
                    tp.Left = tr.Right - _iArrowCx;
                    tp.Right = tr.Right;
                    if (PtInRect(ref tp, pt))
                        return SB_HITEST.rightArrow;
                    // button
                    tp.Left = tr.Left + sb.xyThumbTop;
                    tp.Right = tr.Left + sb.xyThumbBottom;
                    if (PtInRect(ref tp, pt))
                        return SB_HITEST.button;
                    // track
                    return SB_HITEST.track;
                }
            }
            else
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr = sb.rcScrollBar;
                tp = tr;

                if (PtInRect(ref tr, pt))
                {
                    // top arrow
                    tp.Bottom = tr.Top + _iArrowCy;
                    if (PtInRect(ref tp, pt))
                        return SB_HITEST.topArrow;
                    // bottom arrow
                    tp.Top = tr.Bottom - _iArrowCy;
                    tp.Bottom = tr.Bottom;
                    if (PtInRect(ref tp, pt))
                        return SB_HITEST.bottomArrow;
                    // button
                    tp.Top = tr.Top + sb.xyThumbTop;
                    tp.Bottom = tr.Bottom + sb.xyThumbBottom;
                    if (PtInRect(ref tp, pt))
                        return SB_HITEST.button;
                    // track
                    return SB_HITEST.track;
                }
            }
            return SB_HITEST.offControl;
        }
        private void scrollFader()
        {
            if (TransitionGraphic != null)
            {
                SB_HITEST hitTest;
                SCROLLBARINFO sb = new SCROLLBARINFO();
                sb.cbSize = Marshal.SizeOf(sb);
                if (hasHorizontal())
                {
                    hitTest = scrollbarHitTest(Orientation.Horizontal);

                    if ((hitTest == SB_HITEST.button) && (!leftKeyPressed()))
                    {
                        GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                        // start the transition routines here
                        // size of mask - new Rectangle(sb.xyThumbTop, 2, sb.xyThumbBottom - sb.xyThumbTop, sb.rcScrollBar.Bottom)
                    }
                }
                if (hasVertical())
                {
                    hitTest = scrollbarHitTest(Orientation.Vertical);

                    if ((hitTest == SB_HITEST.button) && (!leftKeyPressed()))
                    {
                        GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                        // start the transition routines here
                        // size of mask - new Rectangle(sb.xyThumbTop, 2, sb.xyThumbBottom - sb.xyThumbTop, sb.rcScrollBar.Bottom)
                    }
                }
            }


        }
Exemplo n.º 18
0
 public static extern bool GetScrollBarInfo(IntPtr hWnd, long idObject, ref SCROLLBARINFO barInfo);
Exemplo n.º 19
0
 private  SCROLLBARINFO GetScrollBarInfo(IntPtr hWnd)
 {
     SCROLLBARINFO scrollbarinfo = new SCROLLBARINFO();
     scrollbarinfo = new SCROLLBARINFO {
         cbSize = Marshal.SizeOf(scrollbarinfo)
     };
     Win32.NativeMethods.SendMessage(hWnd, 0xeb, 0, ref scrollbarinfo);
     return scrollbarinfo;
 }
Exemplo n.º 20
0
        private void drawScrollBar()
        {
            SCROLLBARINFO sbi = new SCROLLBARINFO();
            RECT tr = new RECT();
            cStoreDc tempDc = new cStoreDc();
            int offset = 0;
            int width = 0;
            int section = 0;

            GetWindowRect(_hScrollBarWnd, ref tr);
            OffsetRect(ref tr, -tr.Left, -tr.Top);
            tempDc.Width = tr.Right;
            tempDc.Height = tr.Bottom;
            SB_HITEST hitTest = scrollbarHitTest();

            sbi.cbSize = Marshal.SizeOf(sbi);
            SendMessage(_hScrollBarWnd, SBM_GETSCROLLBARINFO, 0, ref sbi);

            if (Direction == Orientation.Horizontal)
            {
                // draw the track
                using (StretchImage si = new StretchImage(_cTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cTrackDc.Width, _cTrackDc.Height), new Rectangle(_iArrowCx, 0, tr.Right - (2 * _iArrowCx), tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
                // draw the arrows
                section = 7;
                width = _cArrowDc.Width / section;
                // left arrow
                if (hitTest == SB_HITEST.leftArrow)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;
                }
                else
                {
                    offset = 0;
                }
                using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // right arrow
                if (hitTest == SB_HITEST.rightArrow)
                {
                    if (leftKeyPressed())
                        offset = 5;
                    else
                        offset = 4;
                }
                else
                {
                    offset = 3;
                }
                using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(tr.Right - _iArrowCx, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // draw the thumb
                section = 3;
                width = _cThumbDc.Width / section;
                if (hitTest == SB_HITEST.button)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;
                }
                else
                {
                    offset = 0;
                }
                Point pst = getScrollBarThumb();
                using (StretchImage si = new StretchImage(_cThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cThumbDc.Height), new Rectangle(pst.X, 0, pst.Y - pst.X, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
            }
            else
            {
                // draw the track
                using (StretchImage si = new StretchImage(_cTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cTrackDc.Width, _cTrackDc.Height), new Rectangle(0, _iArrowCy, tr.Right, tr.Bottom - (2 * _iArrowCy)), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
                section = 6;
                width = _cArrowDc.Width / section;

                // top arrow
                if (hitTest == SB_HITEST.topArrow)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;
                }
                else
                {
                    offset = 0;
                }
                using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, 0, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // bottom arrow
                if (hitTest == SB_HITEST.bottomArrow)
                {
                    if (leftKeyPressed())
                        offset = 5;
                    else
                        offset = 4;
                }
                else
                {
                    offset = 3;
                }
                using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, tr.Bottom - _iArrowCy, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // draw the thumb
                section = 3;
                width = _cThumbDc.Width / section;
                if (hitTest == SB_HITEST.button)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;
                }
                else
                {
                    offset = 0;
                }
                Point pst = getScrollBarThumb();
                using (StretchImage si = new StretchImage(_cThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cThumbDc.Height), new Rectangle(0, pst.X, _iArrowCx, pst.Y - pst.X), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
            }
            IntPtr hdc = GetDC(_hMaskWnd);
            BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
            ReleaseDC(_hMaskWnd, hdc);
            tempDc.Dispose();
        }
Exemplo n.º 21
0
 private SCROLLBARINFO GetBars()
 {
     SCROLLBARINFO si = new SCROLLBARINFO();
     si.cbSize = Marshal.SizeOf(si);
     int ret = GetScrollBarInfo(this.Handle, OBJID_VSCROLL, ref si);
     if (ret == 0)
         Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
     return si;
 }
Exemplo n.º 22
0
 public static extern int GetScrollBarInfo(IntPtr hWnd, ObjId idObject, ref SCROLLBARINFO psbi);
Exemplo n.º 23
0
 private SCROLLBARINFO GetScrollBarInfo(IntPtr hWnd, uint objid)
 {
     SCROLLBARINFO scrollbarinfo = new SCROLLBARINFO();
     scrollbarinfo = new SCROLLBARINFO {
         cbSize = Marshal.SizeOf(scrollbarinfo)
     };
     Win32.NativeMethods.GetScrollBarInfo(hWnd, objid, ref scrollbarinfo);
     return scrollbarinfo;
 }
Exemplo n.º 24
0
 private static extern Int32 GetScrollBarInfo(IntPtr hWnd, UInt32 idObject, ref SCROLLBARINFO psbi);
Exemplo n.º 25
0
        /// <summary>
        /// Sets formatting client rectangle of the control
        /// </summary>
        public void SetFormattingRectangle()
        {
            if (!base.IsHandleCreated)
            {
                return;
            }

            RECT rect = new RECT();

            rect.left   = 2;
            rect.right  = Width - 5;
            rect.top    = 2;
            rect.bottom = Height - 3;
            SCROLLBARINFO info = new SCROLLBARINFO();
            bool          val;

            switch (ScrollBars)
            {
            case RichTextBoxScrollBars.None:
                break;

            case RichTextBoxScrollBars.Both:
                info.cbSize = Marshal.SizeOf(info);
                val         = GetScrollBarInfo(Handle, SC_HSCROLL, ref info);
                if (val && info.rcScrollBar.Height != 0)
                {
                    rect.bottom -= SystemInformation.HorizontalScrollBarHeight;
                }
                val = GetScrollBarInfo(Handle, SC_VSCROLL, ref info);
                if (val && info.rcScrollBar.Width != 0)
                {
                    rect.right -= SystemInformation.VerticalScrollBarWidth;
                }
                break;

            case RichTextBoxScrollBars.ForcedBoth:
                rect.bottom -= SystemInformation.HorizontalScrollBarHeight;
                rect.right  -= SystemInformation.VerticalScrollBarWidth;
                break;

            case RichTextBoxScrollBars.ForcedHorizontal:
                rect.bottom -= SystemInformation.HorizontalScrollBarHeight;
                info.cbSize  = Marshal.SizeOf(info);
                val          = GetScrollBarInfo(Handle, SC_VSCROLL, ref info);
                if (val && info.rcScrollBar.Width != 0)
                {
                    rect.right -= SystemInformation.VerticalScrollBarWidth;
                }
                break;

            case RichTextBoxScrollBars.ForcedVertical:
                rect.right -= SystemInformation.VerticalScrollBarWidth;
                info.cbSize = Marshal.SizeOf(info);
                val         = GetScrollBarInfo(Handle, SC_HSCROLL, ref info);
                if (val && info.rcScrollBar.Height != 0)
                {
                    rect.bottom -= SystemInformation.HorizontalScrollBarHeight;
                }
                break;

            case RichTextBoxScrollBars.Horizontal:
                info.cbSize = Marshal.SizeOf(info);
                val         = GetScrollBarInfo(Handle, SC_HSCROLL, ref info);
                if (val && info.rcScrollBar.Height != 0)
                {
                    rect.bottom -= SystemInformation.HorizontalScrollBarHeight;
                }
                break;

            case RichTextBoxScrollBars.Vertical:
                info.cbSize = Marshal.SizeOf(info);
                val         = GetScrollBarInfo(Handle, SC_VSCROLL, ref info);
                if (val && info.rcScrollBar.Width != 0)
                {
                    rect.right -= SystemInformation.VerticalScrollBarWidth;
                }
                break;
            }

            int hr = SendMessage(Handle, EM_SETRECT,
                                 0, ref rect);

            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
Exemplo n.º 26
0
        private void CreateScrollBarMask()
        {
            Type          t         = typeof(ScrollBarSkin);
            Module        m         = t.Module;
            IntPtr        hInstance = Marshal.GetHINSTANCE(m);
            IntPtr        hParent   = GetParent(_hControlWnd);
            RECT          tr        = new RECT();
            Point         pt        = new Point();
            SCROLLBARINFO sb        = new SCROLLBARINFO();

            sb.cbSize = Marshal.SizeOf(sb);

            // vertical scrollbar
            // get the size and position
            GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
            tr   = sb.rcScrollBar;
            pt.X = tr.Left;
            pt.Y = tr.Top;
            ScreenToClient(hParent, ref pt);

            // create the window
            _hVerticalMaskWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
                                               "STATIC", "",
                                               SS_OWNERDRAW | WS_CHILD | WS_CLIPSIBLINGS | WS_OVERLAPPED | WS_VISIBLE,
                                               pt.X, pt.Y,
                                               (tr.Right - tr.Left), (tr.Bottom - tr.Top),
                                               hParent,
                                               IntPtr.Zero, hInstance, IntPtr.Zero);

            // set z-order
            SetWindowPos(_hVerticalMaskWnd, HWND_TOP,
                         0, 0,
                         0, 0,
                         SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);

            // horizontal scrollbar
            GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
            tr   = sb.rcScrollBar;
            pt.X = tr.Left;
            pt.Y = tr.Top;
            ScreenToClient(hParent, ref pt);

            _hHorizontalMaskWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
                                                 "STATIC", "",
                                                 SS_OWNERDRAW | WS_CHILD | WS_CLIPSIBLINGS | WS_OVERLAPPED | WS_VISIBLE,
                                                 pt.X, pt.Y,
                                                 (tr.Right - tr.Left), (tr.Bottom - tr.Top),
                                                 hParent,
                                                 IntPtr.Zero, hInstance, IntPtr.Zero);

            SetWindowPos(_hHorizontalMaskWnd, HWND_TOP,
                         0, 0,
                         0, 0,
                         SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);

            // sizer
            _hSizerMaskWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
                                            "STATIC", "",
                                            SS_OWNERDRAW | WS_CHILD | WS_CLIPSIBLINGS | WS_OVERLAPPED | WS_VISIBLE,
                                            pt.X + (tr.Right - tr.Left), pt.Y,
                                            _iArrowCx, _iArrowCy,
                                            hParent,
                                            IntPtr.Zero, hInstance, IntPtr.Zero);

            SetWindowPos(_hSizerMaskWnd, HWND_TOP,
                         0, 0,
                         0, 0,
                         SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
            ResizeMask();
        }
Exemplo n.º 27
0
 private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, ref SCROLLBARINFO lParam);
Exemplo n.º 28
0
 private static extern int GetScrollBarInfo(IntPtr hWnd, uint idObject, ref SCROLLBARINFO psbi);
Exemplo n.º 29
0
        private void DrawScrollBar()
        {
            RECT tr = new RECT();
            IntPtr hdc = IntPtr.Zero;
            SCROLLBARINFO sb = new SCROLLBARINFO();
            sb.cbSize = Marshal.SizeOf(sb);

            if (HasHorizontal())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = sb.rcScrollBar;
                OffsetRect(ref tr, -tr.Left, -tr.Top);
                hdc = GetDC(_hHorizontalMaskWnd);
                Boolean isMouseOver = HitTest(Orientation.Horizontal);
                Boolean isClick = IsLeftKeyPressed();
                if (isMouseOver == true) _isFocus = true;
                using (Graphics g = Graphics.FromHdc(hdc))
                {
                    DrawHorizontalScrollBar(g, tr.Right, tr.Bottom, sb.xyThumbTop, sb.xyThumbBottom, _iArrowCx,
                        isMouseOver, isClick);
                }
                ReleaseDC(_hHorizontalMaskWnd, hdc);
            }

            if (HasSizer())
            {
                hdc = GetDC(_hSizerMaskWnd);
                using (Graphics g = Graphics.FromHdc(hdc))
                {
                    DrawSizer(g, _iArrowCx, _iArrowCy);
                }
                ReleaseDC(_hSizerMaskWnd, hdc);
            }

            if (HasVertical())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr = sb.rcScrollBar;
                OffsetRect(ref tr, -tr.Left, -tr.Top);
                Boolean isMouseOver = HitTest(Orientation.Vertical);
                Boolean isClick = IsLeftKeyPressed();
                if (isMouseOver == true) _isFocus = true;
                hdc = GetDC(_hVerticalMaskWnd);
                using (Graphics g = Graphics.FromHdc(hdc))
                {
                    DrawVerticalScrollBar(g, tr.Right, tr.Bottom, sb.xyThumbTop, sb.xyThumbBottom, _iArrowCy,
                        isMouseOver, isClick);
                }
                ReleaseDC(_hVerticalMaskWnd, hdc);
            }
        }
Exemplo n.º 30
0
        private Boolean HitTest(Orientation orient)
        {
            Point pt = new Point();
            RECT tr = new RECT();
            RECT tp = new RECT();
            SCROLLBARINFO sb = new SCROLLBARINFO();
            sb.cbSize = Marshal.SizeOf(sb);

            GetCursorPos(ref pt);

            if (orient == Orientation.Horizontal)
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = sb.rcScrollBar;
                tp = tr;
                if (PtInRect(ref tr, pt))
                {
                    return true;
                }
            }
            else
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr = sb.rcScrollBar;
                tp = tr;
                if (PtInRect(ref tr, pt))
                {
                    return true;
                }
            }
            return false;
        }
Exemplo n.º 31
0
        public static int AutoCalcWidth(this ListView listView)
        {
            var sbi = new SCROLLBARINFO();
            sbi.cbSize = Marshal.SizeOf(sbi);

            if (GetScrollBarInfo(listView.Handle, (uint) ScrollObjMask.OBJID_HSCROLL, ref sbi) != 0)
            {
                const int minWidth = 100;
                var borderWidth = SystemInformation.Border3DSize.Width;
                var scrollBarWidth = SystemInformation.VerticalScrollBarWidth;
                var scrollBars = GetVisibleScrollbars(listView);

                if (scrollBars == ScrollBars.Both || scrollBars == ScrollBars.Horizontal)
                    scrollBarWidth = SystemInformation.VerticalScrollBarWidth;
                else
                {
                    scrollBarWidth = 0;
                }

                int state = sbi.rgstate[0];

                var iWidth = 0;
//                var iWidth = si.nMax - si.nMin + 2 * borderWidth + scrollBarWidth + 2;
                return Math.Max(minWidth, iWidth);
            }
            var error = Marshal.GetLastWin32Error();
            throw new Exception($"Pinvoked GetScrollBarInfo error:{error}");
        }
Exemplo n.º 32
0
 private static extern bool GetScrollBarInfo(IntPtr hwnd, int idObject, ref SCROLLBARINFO psbi);
Exemplo n.º 33
0
 internal static extern bool GetScrollBarInfo(IntPtr hwnd, int idObject, ref SCROLLBARINFO psbi);
Exemplo n.º 34
0
 private static extern int GetScrollBarInfo(IntPtr hWnd, uint idObject, ref SCROLLBARINFO psbi);
Exemplo n.º 35
0
 public static extern bool GetScrollBarInfo(IntPtr hWnd, uint idObject, ref SCROLLBARINFO psbi);
Exemplo n.º 36
0
 private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, ref SCROLLBARINFO lParam);
        private void createScrollBarMask()
        {
            Type t = typeof(cScrollBar);
            Module m = t.Module;
            IntPtr hInstance = Marshal.GetHINSTANCE(m);
            IntPtr hParent = GetParent(_hControlWnd);
            RECT tr = new RECT();
            Point pt = new Point();
            SCROLLBARINFO sb = new SCROLLBARINFO();
            sb.cbSize = Marshal.SizeOf(sb);

            // vertical scrollbar
            // get the size and position
            GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
            tr = sb.rcScrollBar;
            pt.X = tr.Left;
            pt.Y = tr.Top;
            ScreenToClient(hParent, ref pt);

            // create the window
            _hVerticalMaskWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
                "STATIC", "",
                SS_OWNERDRAW | WS_CHILD | WS_CLIPSIBLINGS | WS_OVERLAPPED | WS_VISIBLE,
                pt.X, pt.Y,
                (tr.Right - tr.Left), (tr.Bottom - tr.Top),
                hParent,
                IntPtr.Zero, hInstance, IntPtr.Zero);

            // set z-order
            SetWindowPos(_hVerticalMaskWnd, HWND_TOP,
                0, 0,
                0, 0,
                SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);

            // horizontal scrollbar
            GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
            tr = sb.rcScrollBar;
            pt.X = tr.Left;
            pt.Y = tr.Top;
            ScreenToClient(hParent, ref pt);

            _hHorizontalMaskWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
                "STATIC", "",
                SS_OWNERDRAW | WS_CHILD | WS_CLIPSIBLINGS | WS_OVERLAPPED | WS_VISIBLE,
                pt.X, pt.Y,
                (tr.Right - tr.Left), (tr.Bottom - tr.Top),
                hParent,
                IntPtr.Zero, hInstance, IntPtr.Zero);

            SetWindowPos(_hHorizontalMaskWnd, HWND_TOP,
                0, 0,
                0, 0,
                SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);

            // sizer
            _hSizerMaskWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
                "STATIC", "",
                SS_OWNERDRAW | WS_CHILD | WS_CLIPSIBLINGS | WS_OVERLAPPED | WS_VISIBLE,
                pt.X + (tr.Right - tr.Left), pt.Y,
                _iArrowCx, _iArrowCy,
                hParent,
                IntPtr.Zero, hInstance, IntPtr.Zero);

            SetWindowPos(_hSizerMaskWnd, HWND_TOP,
                0, 0,
                0, 0,
                SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
            reSizeMask();
        }
Exemplo n.º 38
0
 private RECT getScrollBarRect()
 {
     SCROLLBARINFO sbi = new SCROLLBARINFO();
     sbi.cbSize = Marshal.SizeOf(sbi);
     SendMessage(_hScrollBarWnd, SBM_GETSCROLLBARINFO, 0, ref sbi);
     return sbi.rcScrollBar;
 }
        private void drawScrollBar()
        {
            RECT tr = new RECT();
            Point pst = new Point();
            cStoreDc tempDc = new cStoreDc();
            IntPtr hdc = IntPtr.Zero;
            int offset = 0;
            int width = 0;
            int section = 0;
            SCROLLBARINFO sb = new SCROLLBARINFO();
            sb.cbSize = Marshal.SizeOf(sb);

            if (hasHorizontal())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = sb.rcScrollBar;
                OffsetRect(ref tr, -tr.Left, -tr.Top);
                tempDc.Width = tr.Right;
                tempDc.Height = tr.Bottom;
                SB_HITEST hitTest = scrollbarHitTest(Orientation.Horizontal);

                // draw the track
                using (StretchImage si = new StretchImage(_cHorizontalTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cHorizontalTrackDc.Width, _cHorizontalTrackDc.Height), new Rectangle(_iArrowCx, 0, tr.Right - (2 * _iArrowCx), tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
                // draw the arrows
                section = 7;
                width = _cHorizontalArrowDc.Width / section;
                // left arrow
                if (hitTest == SB_HITEST.leftArrow)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;

                }
                else
                {
                    offset = 0;
                }
                using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(0, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // right arrow
                if (hitTest == SB_HITEST.rightArrow)
                {
                    if (leftKeyPressed())
                        offset = 5;
                    else
                        offset = 4;

                }
                else
                {
                    offset = 3;
                }
                using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(tr.Right - _iArrowCx, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // draw the thumb
                section = 3;
                width = _cHorizontalThumbDc.Width / section;
                if (hitTest == SB_HITEST.button)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;

                }
                else
                {
                    offset = 0;
                }
                pst.X = sb.xyThumbTop;
                pst.Y = sb.xyThumbBottom;
                using (StretchImage si = new StretchImage(_cHorizontalThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalThumbDc.Height), new Rectangle(pst.X, 2, pst.Y - pst.X, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                hdc = GetDC(_hHorizontalMaskWnd);
                BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
                ReleaseDC(_hHorizontalMaskWnd, hdc);
            }

            if (hasSizer())
            {
                tempDc.Width = _iArrowCx;
                tempDc.Height = _iArrowCy;
                offset = 6;
                section = 7;
                width = _cHorizontalArrowDc.Width / section;

                using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(0, 0, _iArrowCx, _iArrowCy), 0, StretchModeEnum.STRETCH_HALFTONE)) { }
                hdc = GetDC(_hSizerMaskWnd);
                BitBlt(hdc, 0, 0, _iArrowCx, _iArrowCy, tempDc.Hdc, 0, 0, 0xCC0020);
                ReleaseDC(_hSizerMaskWnd, hdc);
            }

            if (hasVertical())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr = sb.rcScrollBar;
                OffsetRect(ref tr, -tr.Left, -tr.Top);
                tempDc.Width = tr.Right;
                tempDc.Height = tr.Bottom;
                SB_HITEST hitTest = scrollbarHitTest(Orientation.Vertical);

                // draw the track
                using (StretchImage si = new StretchImage(_cVerticalTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cVerticalTrackDc.Width, _cVerticalTrackDc.Height), new Rectangle(0, _iArrowCy, tr.Right, tr.Bottom - (2 * _iArrowCy)), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
                section = 6;
                width = _cVerticalArrowDc.Width / section;

                // top arrow
                if (hitTest == SB_HITEST.topArrow)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;

                }
                else
                {
                    offset = 0;
                }
                using (StretchImage si = new StretchImage(_cVerticalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalArrowDc.Height), new Rectangle(0, 0, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // bottom arrow
                if (hitTest == SB_HITEST.bottomArrow)
                {
                    if (leftKeyPressed())
                        offset = 5;
                    else
                        offset = 4;

                }
                else
                {
                    offset = 3;
                }
                using (StretchImage si = new StretchImage(_cVerticalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalArrowDc.Height), new Rectangle(0, tr.Bottom - _iArrowCy, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // draw the thumb
                section = 3;
                width = _cVerticalThumbDc.Width / section;
                if (hitTest == SB_HITEST.button)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;

                }
                else
                {
                    offset = 0;
                }

                pst.X = sb.xyThumbTop;
                pst.Y = sb.xyThumbBottom;
                using (StretchImage si = new StretchImage(_cVerticalThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalThumbDc.Height), new Rectangle(0, pst.X, _iArrowCx, pst.Y - pst.X), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                hdc = GetDC(_hVerticalMaskWnd);
                BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
                ReleaseDC(_hVerticalMaskWnd, hdc);
            }
            tempDc.Dispose();
        }
Exemplo n.º 40
0
 internal static extern int SendMessage(
     IntPtr hWnd, int msg, int wParam, ref SCROLLBARINFO lParam);
Exemplo n.º 41
0
 public static extern bool GetScrollBarInfo(IntPtr hWnd, int idObject, ref SCROLLBARINFO psbi);