Ejemplo n.º 1
0
        /// <summary>
        ///     Method to set the ScrollbarInfo, if we can get it
        /// </summary>
        /// <param name="forceUpdate">set to true to force an update, default is false</param>
        /// <returns>ScrollBarInfo?</returns>
        public ScrollBarInfo?GetScrollbarInfo(bool forceUpdate = false)
        {
            // Prevent updates, if there is already a value
            if (ScrollBar.HasValue && !forceUpdate)
            {
                return(ScrollBar);
            }
            var objectId = ObjectIdentifiers.Client;

            switch (ScrollBarType)
            {
            case ScrollBarTypes.Control:
                objectId = ObjectIdentifiers.Client;
                break;

            case ScrollBarTypes.Vertical:
                objectId = ObjectIdentifiers.VerticalScrollbar;
                break;

            case ScrollBarTypes.Horizontal:
                objectId = ObjectIdentifiers.HorizontalScrollbar;
                break;
            }
            var scrollbarInfo    = ScrollBarInfo.Create();
            var hasScrollbarInfo = User32Api.GetScrollBarInfo(ScrollBarWindow.Handle, objectId, ref scrollbarInfo);

            if (!hasScrollbarInfo)
            {
                var error = Win32.GetLastErrorCode();
                Log.Verbose().WriteLine("Error retrieving Scrollbar info : {0}", Win32.GetMessage(error));
                return(null);
            }
            ScrollBar = scrollbarInfo;
            return(scrollbarInfo);
        }