/// <summary> /// Extension method to create a WindowScroller /// </summary> /// <param name="interopWindow">IInteropWindow</param> /// <param name="scrollBarType">ScrollBarTypes</param> /// <param name="forceUpdate">true to force a retry, even if the previous check failed</param> /// <returns>WindowScroller or null</returns> public static WindowScroller GetWindowScroller(this IInteropWindow interopWindow, ScrollBarTypes scrollBarType = ScrollBarTypes.Vertical, bool forceUpdate = false) { if (!forceUpdate && interopWindow.CanScroll.HasValue && !interopWindow.CanScroll.Value) { return(null); } var initialScrollInfo = ScrollInfo.Create(ScrollInfoMask.All); if (User32Api.GetScrollInfo(interopWindow.Handle, scrollBarType, ref initialScrollInfo) && initialScrollInfo.Minimum != initialScrollInfo.Maximum) { var windowScroller = new WindowScroller { ScrollingWindow = interopWindow, ScrollBarWindow = interopWindow, ScrollBarType = scrollBarType, InitialScrollInfo = initialScrollInfo, WheelDelta = (int)(120 * (initialScrollInfo.PageSize / WindowScroller.ScrollWheelLinesFromRegistry)) }; interopWindow.CanScroll = true; return(windowScroller); } if (User32Api.GetScrollInfo(interopWindow.Handle, ScrollBarTypes.Control, ref initialScrollInfo) && initialScrollInfo.Minimum != initialScrollInfo.Maximum) { var windowScroller = new WindowScroller { ScrollingWindow = interopWindow, ScrollBarWindow = interopWindow, ScrollBarType = ScrollBarTypes.Control, InitialScrollInfo = initialScrollInfo, WheelDelta = (int)(120 * (initialScrollInfo.PageSize / WindowScroller.ScrollWheelLinesFromRegistry)) }; interopWindow.CanScroll = true; return(windowScroller); } interopWindow.CanScroll = false; return(null); }
/// <summary> /// Get current position /// </summary> /// <returns>SCROLLINFO</returns> public bool GetPosition(out ScrollInfo scrollInfo) { scrollInfo = ScrollInfo.Create(ScrollInfoMask.All); return(User32Api.GetScrollInfo(ScrollBarWindow.Handle, ScrollBarType, ref scrollInfo)); }