public void TestEmulateSelectDayEvent() { //イベント確認。 NativeDateTimePicker picker = new NativeDateTimePicker(testDlg.IdentifyFromDialogId(1013)); picker.EmulateSelectDay(DateTime.Today); DateTime setDay = DateTime.Today.AddDays(1); Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg, delegate { picker.EmulateSelectDay(setDay); }, new CodeInfo(1013, NativeMethods.WM_NOTIFY, DTN_DATETIMECHANGE))); //詳細な通知内容をテスト。 setDay = setDay.AddDays(1); NMDATETIMECHANGE[] expectation = new NMDATETIMECHANGE[1]; expectation[0].dwFlags = 0; expectation[0].st = NativeDataUtility.ToSYSTEMTIME(setDay); Assert.IsTrue(EventChecker.CheckNotifyDetail(testDlg, delegate { picker.EmulateSelectDay(setDay); }, expectation)); }
/// <summary> /// 現在時間を設定します。 /// DTN_DATETIMECHANGEの通知が発生します。 /// </summary> /// <param name="handle">ウィンドウハンドル。</param> /// <param name="day">選択する日時。</param> private static void EmulateSelectDayInTarget(IntPtr handle, DateTime day) { NativeMethods.SetFocus(handle); //変更 SYSTEMTIME native = NativeDataUtility.ToSYSTEMTIME(day); NativeMethods.SendMessage(handle, DTM_SETSYSTEMTIME, new IntPtr(GDT_VALID), ref native); //WM_NOTIFY送信 NMDATETIMECHANGE nmdata = new NMDATETIMECHANGE(); EmulateUtility.InitNotify(handle, DTN_DATETIMECHANGE, ref nmdata.nmhdr); nmdata.dwFlags = GDT_VALID; nmdata.st = native; NativeMethods.SendMessage(NativeMethods.GetParent(handle), NativeCommonDefine.WM_NOTIFY, nmdata.nmhdr.idFrom, ref nmdata); }