简体   繁体   中英

MFC: Can you change the acceleration of the spin in a CDateTimeCtrl?

I am using VS-2015 and I'm trying to extend CDateTimeCtrl to detect when it surpasses 59' and change the hour accordingly.

The problem is now that when I hold the arrow to increment or decrement, it accelerates and I can no longer check if it changed from 59 to 00 or vice-versa because increasing or decreasing in more than 1' you can go from 50 to 10.

I know about CEdit + CSpinButtonCtrl but I want to know if it is possible to change the acceleration to one by one minute only.

You can retrieve the handle of your CDateTimeCtrl object's contained 'spin button' using the class GetDateTimePickerInfo() member function, which will be in the hwndUD member of the returned DATETIMEPICKERINFO structure.

You can then effectively disable acceleration for that spin control by sending it the UDM_SETACCEL message, with wParam set to 1 and lParam pointing to a 1-element array of UDACCEL structures; set that structure element's time-to-acceleration ( nSec ) to a very large value and (just to be sure) set the accelerated increment value ( nInc ) to 'remain' at 1:

    CDateTimeCtrl MyDTC;
    ///...
    DATETIMEPICKERINFO dtInfo{};
    MyDTC.GetDateTimePickerInfo(&dtInfo);
    UDACCEL AccelList[1] = { {UINT_MAX, 1} };
    ::SendMessage(dtInfo.hwndUD, UDM_SETACCEL, 1, reinterpret_cast<LPARAM>(AccelList));

If ~8,166 years ( UINT_MAX seconds) is too short a time, you could just add more (identical) UDACCEL structures to the list.

You may be able to disable acceleration altogether by passing 0 as the wParam argument to the SetAccel function (and NULL for `lParam) but this is not a documented feature. (Worth a try, though?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM