From 022416f9598b1e73159c941bde918bc9c23b1fea Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Sun, 13 Jul 2014 09:03:47 +0900 Subject: [PATCH] =?utf8?q?DetailsListView.GetScrollInfo()=20=E3=83=A1?= =?utf8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=81=A8=E9=96=A2=E9=80=A3=E3=81=99?= =?utf8?q?=E3=82=8B=E5=88=97=E6=8C=99=E5=9E=8B=E3=81=AA=E3=81=A9=E3=82=92N?= =?utf8?q?ativeMethods=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AB=E7=A7=BB?= =?utf8?q?=E5=8B=95=20(CA1060)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit http://msdn.microsoft.com/ja-jp/library/ms182161.aspx --- OpenTween/DetailsListView.cs | 48 ++++---------------------------------------- OpenTween/NativeMethods.cs | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/OpenTween/DetailsListView.cs b/OpenTween/DetailsListView.cs index 2b91f1a9..d437b57c 100644 --- a/OpenTween/DetailsListView.cs +++ b/OpenTween/DetailsListView.cs @@ -223,44 +223,6 @@ namespace OpenTween.OpenTweenCustomControl } } - [StructLayout(LayoutKind.Sequential)] - private struct SCROLLINFO - { - public int cbSize; - public int fMask; - public int nMin; - public int nMax; - public int nPage; - public int nPos; - public int nTrackPos; - } - - private enum ScrollBarDirection - { - SB_HORZ = 0, - SB_VERT = 1, - SB_CTL = 2, - SB_BOTH = 3, - } - - private enum ScrollInfoMask - { - SIF_RANGE = 0x1, - SIF_PAGE = 0x2, - SIF_POS = 0x4, - SIF_DISABLENOSCROLL = 0x8, - SIF_TRACKPOS = 0x10, - SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS), - } - - [DllImport("user32.dll")] - private static extern int GetScrollInfo(IntPtr hWnd, ScrollBarDirection fnBar, ref SCROLLINFO lpsi); - - private SCROLLINFO si = new SCROLLINFO { - cbSize = Marshal.SizeOf(new SCROLLINFO()), - fMask = (int)ScrollInfoMask.SIF_POS - }; - [DebuggerStepThrough()] protected override void WndProc(ref Message m) { @@ -304,10 +266,8 @@ namespace OpenTween.OpenTweenCustomControl case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL: case WM_KEYDOWN: - if (GetScrollInfo(this.Handle, ScrollBarDirection.SB_VERT, ref si) != 0) - vPos = si.nPos; - if (GetScrollInfo(this.Handle, ScrollBarDirection.SB_HORZ, ref si) != 0) - hPos = si.nPos; + vPos = NativeMethods.GetScrollPosition(this, NativeMethods.ScrollBarDirection.SB_VERT); + hPos = NativeMethods.GetScrollPosition(this, NativeMethods.ScrollBarDirection.SB_HORZ); break; case WM_CONTEXTMENU: if (m.WParam != this.Handle) @@ -338,11 +298,11 @@ namespace OpenTween.OpenTweenCustomControl if (this.IsDisposed) return; if (vPos != -1) - if (GetScrollInfo(this.Handle, ScrollBarDirection.SB_VERT, ref si) != 0 && vPos != si.nPos) + if (vPos != NativeMethods.GetScrollPosition(this, NativeMethods.ScrollBarDirection.SB_VERT)) if (VScrolled != null) VScrolled(this, EventArgs.Empty); if (hPos != -1) - if (GetScrollInfo(this.Handle, ScrollBarDirection.SB_HORZ, ref si) != 0 && hPos != si.nPos) + if (hPos != NativeMethods.GetScrollPosition(this, NativeMethods.ScrollBarDirection.SB_HORZ)) if (HScrolled != null) HScrolled(this, EventArgs.Empty); } diff --git a/OpenTween/NativeMethods.cs b/OpenTween/NativeMethods.cs index 57f4c9ba..669c248f 100644 --- a/OpenTween/NativeMethods.cs +++ b/OpenTween/NativeMethods.cs @@ -25,6 +25,7 @@ // Boston, MA 02110-1301, USA. using System; +using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Net; @@ -385,5 +386,52 @@ namespace OpenTween RefreshProxyAccount(username, password); } #endregion + + [StructLayout(LayoutKind.Sequential)] + private struct SCROLLINFO + { + public int cbSize; + public ScrollInfoMask fMask; + public int nMin; + public int nMax; + public int nPage; + public int nPos; + public int nTrackPos; + } + + public enum ScrollBarDirection + { + SB_HORZ = 0, + SB_VERT = 1, + SB_CTL = 2, + SB_BOTH = 3, + } + + private enum ScrollInfoMask + { + SIF_RANGE = 0x1, + SIF_PAGE = 0x2, + SIF_POS = 0x4, + SIF_DISABLENOSCROLL = 0x8, + SIF_TRACKPOS = 0x10, + SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS), + } + + [DllImport("user32.dll")] + private static extern int GetScrollInfo(IntPtr hWnd, ScrollBarDirection fnBar, ref SCROLLINFO lpsi); + + public static int GetScrollPosition(Control control, ScrollBarDirection direction) + { + var si = new SCROLLINFO + { + cbSize = Marshal.SizeOf(), + fMask = ScrollInfoMask.SIF_POS, + }; + + if (NativeMethods.GetScrollInfo(control.Handle, direction, ref si) == 0) + throw new Win32Exception(); + + return si.nPos; + } } } -- 2.11.0