/// <summary>
 /// DateTime→SYSTEMTIME変換。
 /// </summary>
 /// <param name="time">DateTime。</param>
 /// <returns>SYSTEMTIME。</returns>
 internal static SYSTEMTIME ToSYSTEMTIME(DateTime time)
 {
     SYSTEMTIME system = new SYSTEMTIME();
     time = time.ToLocalTime();
     system.Year = Convert.ToInt16(time.Year);
     system.Month = Convert.ToInt16(time.Month);
     system.DayOfWeek = Convert.ToInt16(time.DayOfWeek);
     system.Day = Convert.ToInt16(time.Day);
     system.Hour = Convert.ToInt16(time.Hour);
     system.Minute = Convert.ToInt16(time.Minute);
     system.Second = Convert.ToInt16(time.Second);
     system.Milliseconds = Convert.ToInt16(time.Millisecond);
     return system;
 }
 /// <summary>
 /// SYSTEMTIME→DateTime変換。
 /// </summary>
 /// <param name="time">SYSTEMTIME。</param>
 /// <returns>DateTime。</returns>
 internal static DateTime ToDateTime(SYSTEMTIME time)
 {
     return new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second, time.Milliseconds, DateTimeKind.Local);
 }
        /// <summary>
        /// 現在の選択日付を設定します。
        /// MCN_SELCHANGE、MCN_SELECTの通知が発生します。
        /// </summary>
        /// <param name="handle">ウィンドウハンドル。</param>
        /// <param name="min">最小日付。</param>
        /// <param name="max">最大日付。</param>
        private static void EmulateSelectDayInTarget(IntPtr handle, DateTime min, DateTime max)
        {
            NativeMethods.SetFocus(handle);

            SYSTEMTIME[] sysTimes = new SYSTEMTIME[] { NativeDataUtility.ToSYSTEMTIME(min), NativeDataUtility.ToSYSTEMTIME(max) };
            NativeMethods.SendMessage(handle, MCM_SETSELRANGE, IntPtr.Zero, sysTimes);

            //通知
            foreach (int message in new int[] { MCN_SELCHANGE, MCN_SELECT })
            {
                NMSELCHANGE notify = new NMSELCHANGE();
                EmulateUtility.InitNotify(handle, message, ref notify.nmhdr);
                notify.stSelStart = sysTimes[0];
                notify.stSelEnd = sysTimes[1];
                NativeMethods.SendMessage(NativeMethods.GetParent(handle), NativeCommonDefine.WM_NOTIFY, notify.nmhdr.idFrom, ref notify);
            }
        }
 /// <summary>
 /// ユーザーによって現在選択されている日付範囲を取得します。
 /// 複数選択の場合に使用します。
 /// </summary>
 /// <param name="handle">ウィンドウハンドル。</param>
 /// <param name="minMax">最小日付、最大日付。</param>
 /// <returns>成否。</returns>
 private static bool GetSelectionRangeInTarget(IntPtr handle, SYSTEMTIME[] minMax)
 {
     return NativeDataUtility.ToBool(NativeMethods.SendMessage(handle, MCM_GETSELRANGE, IntPtr.Zero, minMax));
 }