/// <summary> /// 現在位置を設定します。 /// WM_HSCROLL、もしくはWM_VSCROLLの通知が発生します。 /// スクロールのタイプはSB_THUMBTRACKです。 /// Notify設定がある場合はTRBN_THUMBPOSCHANGINGの通知も発生します。 /// nReasonはTB_THUMBTRACKです。 /// </summary> /// <param name="handle">ウィンドウハンドル。</param> /// <param name="isVertical">縦方向か。</param> /// <param name="pos">現在位置。</param> private static void EmulateChangePosInTarget(IntPtr handle, bool isVertical, int pos) { NativeMethods.SetFocus(handle); NativeMethods.SendMessage(handle, TBM_SETPOS, new IntPtr(1), new IntPtr(pos)); //Notify設定がある場合はTRBN_THUMBPOSCHANGINGの通知も発生します if ((NativeMethods.GetWindowLongPtr(handle, NativeCommonDefine.GWL_STYLE).ToInt64() & TBS_NOTIFYBEFOREMOVE) == TBS_NOTIFYBEFOREMOVE) { NMTRBTHUMBPOSCHANGING notify = new NMTRBTHUMBPOSCHANGING(); EmulateUtility.InitNotify(handle, TRBN_THUMBPOSCHANGING, ref notify.hdr); notify.dwPos = pos;//変更予定の値が入る。 notify.nReason = TB_THUMBTRACK; NativeMethods.SendMessage(NativeMethods.GetParent(handle), NativeCommonDefine.WM_NOTIFY, notify.hdr.idFrom, ref notify); } //設定変更 NativeMethods.SendMessage(NativeMethods.GetParent(handle), (isVertical ? NativeScrollBar.WM_VSCROLL : NativeScrollBar.WM_HSCROLL), NativeDataUtility.MAKELONG(NativeScrollBar.SB_THUMBTRACK, pos), handle); }
public void TestPosEvent() { NativeSlider slider = new NativeSlider(testDlg.IdentifyFromDialogId(1019)); NativeSlider vslider = new NativeSlider(testDlg.IdentifyFromDialogId(1026)); //同期実行。 Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg, delegate { slider.EmulateChangePos(100); }, new CodeInfo(1019, NativeMethods.WM_NOTIFY, TRBN_THUMBPOSCHANGING), new CodeInfo(1019, NativeMethods.WM_HSCROLL, SB_THUMBPOSITION, 100))); //同期実行 縦方向。 Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg, delegate { vslider.EmulateChangePos(100); }, new CodeInfo(1026, NativeMethods.WM_NOTIFY, TRBN_THUMBPOSCHANGING), new CodeInfo(1026, NativeMethods.WM_VSCROLL, SB_THUMBPOSITION, 100))); //詳細な通知内容の確認。 NMTRBTHUMBPOSCHANGING[] expectation = new NMTRBTHUMBPOSCHANGING[1]; expectation[0].nReason = TB_THUMBTRACK; expectation[0].dwPos = 150; Assert.IsTrue(EventChecker.CheckNotifyDetail(testDlg, delegate { slider.EmulateChangePos(150); }, expectation)); }