Month Calendar : output selected range to MessageBox - pls explain
Hello,
I have created a Month Calendar Control and have enabled MCS_MULTISELECT.
I am trying to implement the MonthCal_GetSelRange() macro to capture a selected range in the Calendar Control. So far my switch looks like this:
Code:
case IDC_BTN_MOON:
{
SYSTEMTIME rng[2];
MonthCal_GetSelRange(hWndMonthCal, &rng);
}
How do I get that range to display in a MessageBox?
Code:
MessageBox(hwndDlg, ??, 0);
I have tried passing SYSTEMTIME WORDs ( rng.wDayOfWeek) but I simply cant get it right. I know it is likely that such usage is no good, but I am trying...
I have been using the Method approach to creating the Month Calendar and other controls.
Re: Month Calendar : output selected range to MessageBox - pls explain
You must first format SYSTEMTIME values to text (character array) and then pass in this array to MessageBox.
You can use GetTimeFormat to format SYSTEMTIME to text.
Re: Month Calendar : output selected range to MessageBox - pls explain
Quote:
Originally Posted by
VictorN
You must first format SYSTEMTIME values to text (character array) and then pass in this array to MessageBox.
You can use GetTimeFormat to format SYSTEMTIME to text.
Code:
SYSTEMTIME* rng[2];
MonthCal_GetSelRange(hWndMonthCal, rng);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, TIME_NOMINUTESORSECONDS, rng, ?, 30);
Thanks Victor, but could you please elaborate? I don't know how to declare a buffer pointer "?". The other parameters should be ok, but I am not sure about how to use the GetTimeFormat function either.
Re: Month Calendar : output selected range to MessageBox - pls explain
Re: Month Calendar : output selected range to MessageBox - pls explain
Is there a method of conversion that will include the Date - which for my purpose is more important than the Time? GetTimeFormat does not recognise dates.
By the way, here is the function with parameters I chose:
Code:
GetTimeFormat(NULL, TIME_NOMINUTESORSECONDS, rng, NULL, NULL, 0);
Re: Month Calendar : output selected range to MessageBox - pls explain
Quote:
Originally Posted by
Morbane
Is there a method of conversion that will include the Date - which for my purpose is more important than the Time? GetTimeFormat does not recognise dates.
Ahh, sorry!
It should have been GetDateFormat API!
Re: Month Calendar : output selected range to MessageBox - pls explain
Cool.
But the GetDateFormat() returns an int. I can't seem to figure out how it converts to char* (or c_str() ).
Moreover, MonthCal_GetSelRange() returns a BOOL. How is that supposed to reveal a range of two dates?
Re: Month Calendar : output selected range to MessageBox - pls explain
Quote:
Originally Posted by
Morbane
But the GetDateFormat() returns an int.
But the GetDateFormat() has a parameter LPTSTR lpDateStr.
Re: Month Calendar : output selected range to MessageBox - pls explain
According to http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx the int returned simply tells you the number of chars written to the buffer that the result is stored in. ie the fifth argument that you pass to the function. so that's where you wanna be looking for the formatted date...
edit: oops beat me to it ovidiucucu
Re: Month Calendar : output selected range to MessageBox - pls explain
Quote:
Originally Posted by
Morbane
Moreover, MonthCal_GetSelRange() returns a BOOL. How is that supposed to reveal a range of two dates?
Moreover, MonthCal_GetSelRange has a parameter LPSYSTEMTIME lprgSysTimeArray.
Re: Month Calendar : output selected range to MessageBox - pls explain
Quote:
Originally Posted by Morbane
But the GetDateFormat() returns an int. I can't seem to figure out how it converts to char* (or c_str() ).
getdateformat c++ example
Quote:
Originally Posted by Morbane
Moreover, MonthCal_GetSelRange() returns a BOOL. How is that supposed to reveal a range of two dates?
PLease, look at your OP:
Code:
case IDC_BTN_MOON:
{
SYSTEMTIME rng[2];
MonthCal_GetSelRange(hWndMonthCal, &rng);
}
how do you think, why are you passing SYSTEMTIME array in this macro?
And, BTW, your code contains a bug. There must be
Code:
MonthCal_GetSelRange(hWndMonthCal, rng);
Re: Month Calendar : output selected range to MessageBox - pls explain
OK! Thanks Cheezewizz and ovidiucucu - very much - it makes so much sense now. The descriptions on the msdn pages state (in) or (out) for any given parameter. Now I know why ;)
Also Thanks to you VictorN!
All you guys are very helpful - and patient.
Here is the working switch:
Code:
case IDC_BTN_MOON:
{
SYSTEMTIME rng[2];
char buf[50];
MonthCal_GetSelRange(hWndMonthCal, rng); //BOOL
GetDateFormat(NULL, DATE_SHORTDATE, rng, NULL, buf, 50); //int
MessageBox(hwndDlg, buf, "Current Date", 0);
}
Next, I am trying to output the range captured by MonthCal_GetSelRange
Re: Month Calendar : output selected range to MessageBox - pls explain
For MonthCal_GetSelRange(), shouldn't the rng variable have stored an actual date range?
The code in my previous post only seems to result in the current date even though the rng variable is passed into GetDateFormat() - the buf variable doesn't seem to hold the full string.
What am I doing wrong?
Re: Month Calendar : output selected range to MessageBox - pls explain
There must be a way to specify the elements of the rng array so that they can be passed into GetDateFormat, either separately or together, but I m having trouble finding a reference for this scenario.
Advice is humbly requested.
Re: Month Calendar : output selected range to MessageBox - pls explain
No, GetDateFormat works only with a single SYSTEMTIME instance, not with an array.
You should either format two different substrings and then concatenate them or use sprintf and pass in all needed members of both SYSTEMTIME instances (with all are WORD or "unsigned short")