topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 8:17 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: TimeDatePicker (Out Of) Control  (Read 5444 times)

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
TimeDatePicker (Out Of) Control
« on: January 30, 2010, 03:10 PM »
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.
More on the bold part later...

My Code (relevent parts only):
Code: C++ [Select]
  1. SYSTEMTIME st[2]; // Used to Set Maximum DateTimePicker Control Date
  2.                  // That should give me a 2 element array of 0 & 1
  3.  GetLocalTime(&st[1]); // This is Today...There IS NO Tomorrow...
  4.  DateTime_SetRange(GetDlgItem(hDlg, IDCDT_CRS_ANALDATE), GDTR_MIN, &st[1]);
  5.  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

  • Developer
  • Joined in 2005
  • ***
  • Posts: 1,187
    • View Profile
    • Donate to Member
Re: TimeDatePicker (Out Of) Control
« Reply #1 on: January 30, 2010, 05:08 PM »
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.
« Last Edit: January 30, 2010, 05:10 PM by Jibz »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
Re: TimeDatePicker (Out Of) Control
« Reply #2 on: January 30, 2010, 06:53 PM »
(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?