ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

TimeDatePicker (Out Of) Control

(1/1)

Stoic Joker:
Okay, as usual I'm working with pure Win32 API C++...

I'm trying to set the maximum selectable date for a DateTimePicker (Calendar) control - and it ain't working.

MSDN Says:hwndDT
Handle to a DTP control.
flags
Value that specifies which range values are valid. This value can be a combination of the following:
GDTR_MIN
The first element in the SYSTEMTIME structure array is valid and will be used to set the minimum allowable system time.
GDTR_MAX
The second element in the SYSTEMTIME structure array is valid and will be used to set the maximum allowable system time.
lpSysTimeArray
Pointer to a two-element array of SYSTEMTIME structures. The first element of the SYSTEMTIME array contains the minimum allowable time. The second element of the SYSTEMTIME array contains the maximum allowable time. It is not necessary to fill an array element that is not specified in the flags parameter.
--- End quote ---
More on the bold part later...

My Code (relevent parts only):
--- Code: C++ ---SYSTEMTIME st[2]; // Used to Set Maximum DateTimePicker Control Date                 // That should give me a 2 element array of 0 & 1 GetLocalTime(&st[1]); // This is Today...There IS NO Tomorrow... DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_ANALDATE), GDTR_MIN, &st[1]); DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_PRODATE),  GDTR_MAX, &st[1]);
Now, no matter WTF I do GDTR_MAX has no effect. Regardless of how I try to define this mythical array element 2 item... GDTR_MIN works fine, even if (as mentioned above) array element is left empty. I have to be able to (lock out cheaters) set the Maxamum selectable date to the current day. Code above works perfectly for the minimum date value (even tho it should not), and has no effect on the max.

Note: ultimately both controls will be set to/with/by GDTR_MAX only... I'm only using GDTR_MIN for testing/demonstration purposes.


What Am I Missing?!?!?!?

Jibz:
If the third parameter of the DateTime_SetRange macro is supposed to be a two-element array, shouldn't it be &st[0]?

When you specify GDTR_MIN it uses the first element, which works ok even though you point at the second, but when you specify GDTR_MAX it uses the second, which is outside the array if I understand it right.

Stoic Joker:
(Granted it's working now, but...) Either I'm completely retarded or somebody at MS needs to be beaten with a claw hammer.

Here's my train of thought:

SYSTEMTIME st[2]; <- array of two Items st[0] & st[1]

Which allows the assumption that:
GDTR_MIN = element 1 or st[0]
GDTR_MAX = element 2 or st[1]

So... (I'll drop to using only one control for clarity) ...This Should Work:

GetLocalTime(&st[0]); populate ele1
GetLocalTime(&st[1]); populate ele2

DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_ANALDATE), GDTR_MIN, &st[0]);
DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_ANALDATE), GDTR_MAX, &st[1]);

But it doesn't - However...

GetLocalTime(&st[1]); populate ele2 only

DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_ANALDATE), GDTR_MIN, &st[0]);
DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_ANALDATE), GDTR_MAX, &st[1]);

Results in MIN working & MAX Failing

Now the weird part...

GetLocalTime(&st[1]); Once again populate ele2 only

DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_ANALDATE), GDTR_MIN, &st[1]);
DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_ANALDATE), GDTR_MAX, &st[0]);

Results in both MIN & MAX Working, even tho st[0] is pointing at an empty array element.


...Now can anybody explain this? ...or do I need to go get a hammer?

Navigation

[0] Message Index

Go to full version