CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    98

    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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  3. #3
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    98

    Re: Month Calendar : output selected range to MessageBox - pls explain

    Quote Originally Posted by VictorN View Post
    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.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Month Calendar : output selected range to MessageBox - pls explain

    Victor Nijegorodov

  5. #5
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    98

    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);

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Month Calendar : output selected range to MessageBox - pls explain

    Quote Originally Posted by Morbane View Post
    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

  7. #7
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    98

    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?

  8. #8
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Month Calendar : output selected range to MessageBox - pls explain

    Quote Originally Posted by Morbane View Post
    But the GetDateFormat() returns an int.
    But the GetDateFormat() has a parameter LPTSTR lpDateStr.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  9. #9
    Join Date
    May 2008
    Posts
    38

    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

  10. #10
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Month Calendar : output selected range to MessageBox - pls explain

    Quote Originally Posted by Morbane View Post
    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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);
    Victor Nijegorodov

  12. #12
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    98

    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.

  13. #13
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    98

    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?

  14. #14
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    98

    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.

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured