-
October 19th, 2010, 02:38 AM
#1
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.
Last edited by Morbane; October 19th, 2010 at 02:42 AM.
-
October 19th, 2010, 02:51 AM
#2
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.
Victor Nijegorodov
-
October 19th, 2010, 03:15 AM
#3
Re: Month Calendar : output selected range to MessageBox - pls explain
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.
-
October 19th, 2010, 03:19 AM
#4
Re: Month Calendar : output selected range to MessageBox - pls explain
Victor Nijegorodov
-
October 19th, 2010, 04:15 AM
#5
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);
-
October 19th, 2010, 04:31 AM
#6
Re: Month Calendar : output selected range to MessageBox - pls explain
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!
Victor Nijegorodov
-
October 19th, 2010, 04:44 AM
#7
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?
-
October 19th, 2010, 04:51 AM
#8
Re: Month Calendar : output selected range to MessageBox - pls explain
Originally Posted by Morbane
But the GetDateFormat() returns an int.
But the GetDateFormat() has a parameter LPTSTR lpDateStr.
-
October 19th, 2010, 04:52 AM
#9
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
-
October 19th, 2010, 04:54 AM
#10
Re: Month Calendar : output selected range to MessageBox - pls explain
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.
-
October 19th, 2010, 04:58 AM
#11
Re: Month Calendar : output selected range to MessageBox - pls explain
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
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);
Victor Nijegorodov
-
October 19th, 2010, 05:05 AM
#12
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
Last edited by Morbane; October 19th, 2010 at 05:08 AM.
-
October 19th, 2010, 06:29 AM
#13
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?
-
October 19th, 2010, 07:07 AM
#14
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.
-
October 19th, 2010, 07:15 AM
#15
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")
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|