tags:

views:

63

answers:

1

I'd like to use a CDateTimeCtrl to allow the user to select a non-weekend date. So, if the user increments the day (via a keypress) - and the resulting day is found to fall on a weekend - then the control should skip forward to the following Monday (don't let issues about month changes distract you, it's not relevant).

Usually it's not a problem: when I handle the DTN_DATETIMECHANGE notification I can check the new date/time and if it's found to be a weekend then I can call SetTime on the control to update the date. However, if I set the style to DTS_SHOWNONE, this call to SetTime causes the control to shift the input 'focus' (term used loosely) to the 'none' checkbox, e.g. away from the day field. This prevents the user from using keyboard input to continue incrementing the date unless they subsequently use the right arrow key to reset the 'focus', which is just nasty.

I would dearly like to prevent this focus shift from occurring. Is it even possible?

+1  A: 

Not sure, but one possible workaround:

keybd_event(VK_RIGHT, 0, 0, NULL);
keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, NULL);
Kyle Alons
Seems to work. I'm sure I can generalise it for all fields. Good answer.
WalderFrey