开发者

Win32: How to prevent DateTimePicker from accepting 2-digit years?

Microsoft's DateTimePicker common control shows ShortDate's according to the configured Locale settings. The customer's computer is configured with a 2-digit year ShortDateFormat (d/M/yy), so the DateTimePicker shows 2-digit years:

Win32: How to prevent DateTimePicker from accepting 2-digit years?

When the user puts focus in the year block of the datetime picker, Microsoft points out the issue, and shows the full 4-digit year:

Win32: How to prevent DateTimePicker from accepting 2-digit years?

But then the user, wanting to enter 1929 as a year, types a 2-digit year:

Win32: How to prevent DateTimePicker from accepting 2-digit years?

And then when they tab out they're confused when Windows interprets their 2-digit years as being between 1930 and 2029, and it is assumed to be 2029:

Win32: How to prevent DateTimePicker from accepting 2-digit years?

The customer has a global corporate policy in place which dictates that Windows regional settings be configured for 2-digit years.

So as a workaround i need to force every DateTimePicker control to use a custom date-format, using the handy DateTime_SetFormat macro:

DateTime_SetFormat(hwnd_DateOfEventPicker, "d/M/yyyy");

This helps, so that now the DateTimePicker now always shows a 4-digit year:

Win32: How to prevent DateTimePicker from accepting 2-digit years?

The problem is that the user can still type in an "invalid" 2-digit year:

Win32: How to prevent DateTimePicker from accepting 2-digit years?

Which Windows is still intpreting, according to the rules, as 2029:

Win32: How to prevent DateTimePicker from accepting 2-digit years?

i need the date-time picker to reject 2-digit years.

If this can't work, then i'm going to be forced to replac开发者_Go百科e every DateTimePicker with 3 edit boxes:

22 6 29

Where i can color invalid numbers red, and point out the invalid data entry by the user.

How can i prevent the DateTimePicker from accept y2k bugs?


If you add the DTS_APPCANPARSE window style, you can handle the WM_NOTIFY: DTN_USERSTRING message and parse the string yourself

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜