/// <summary> /// 現在位置を設定します。 /// 現在の設定と異なる場合、UDN_DELTAPOSの通知が発生します。 /// また、ペアとなるEditにEN_CHANGE、EN_UPDATEの通知が発生します。 /// また、WM_VSCROLLの通知も発生します。 /// </summary> /// <param name="handle">ウィンドウハンドル。</param> /// <param name="pos">現在位置。</param> private static void EmulateChangePosInTarget(IntPtr handle, int pos) { NativeMethods.SetFocus(handle); int currentPos = GetPosInTarget(handle); if (currentPos == pos) { return; } //位置変更 NativeMethods.SendMessage(handle, UDM_SETPOS32, IntPtr.Zero, NativeDataUtility.MAKELPARAM(pos, 0)); //通知 NMUPDOWN info = new NMUPDOWN(); EmulateUtility.InitNotify(handle, UDN_DELTAPOS, ref info.hdr); info.iPos = pos; info.iDelta= pos - currentPos; NativeMethods.SendMessage(NativeMethods.GetParent(handle), NativeCommonDefine.WM_NOTIFY, info.hdr.idFrom, ref info); //WM_VSCROLL NativeMethods.SendMessage(NativeMethods.GetParent(handle), NativeCommonDefine.WM_VSCROLL, NativeDataUtility.MAKELONG(SB_THUMBPOSITION, pos), handle); NativeMethods.SendMessage(NativeMethods.GetParent(handle), NativeCommonDefine.WM_VSCROLL, NativeDataUtility.MAKELONG(SB_ENDSCROLL, pos), handle); }
public void TestPosEvent() { //同期実行。 NativeSpinButton spin = new NativeSpinButton(testDlg.IdentifyFromDialogId(1021)); Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg, delegate { spin.EmulateChangePos(100); }, new CodeInfo(1020, NativeMethods.WM_COMMAND, EN_UPDATE), new CodeInfo(1020, NativeMethods.WM_COMMAND, EN_CHANGE), new CodeInfo(1021, NativeMethods.WM_NOTIFY, UDN_DELTAPOS), new CodeInfo(1021, NativeMethods.WM_VSCROLL, SB_THUMBPOSITION, 100), new CodeInfo(1021, NativeMethods.WM_VSCROLL, SB_ENDSCROLL, 100))); //詳細な通知内容の確認。 NMUPDOWN[] expectation = new NMUPDOWN[1]; expectation[0].iPos = 150; expectation[0].iDelta = 50; Assert.IsTrue(EventChecker.CheckNotifyDetail(testDlg, delegate { spin.EmulateChangePos(150); }, expectation)); }