Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CDateTimeCtrl

CDateTimeCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
21 Posts 5 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sschilachi
    wrote on last edited by
    #1

    I am responding to an DTN_DROPDOWN message from a CDateTimeCtrl in order to set the day states for the Month Calendar Control that appears when you click the dropdown button. I am using the following code to set the day states, where pCalCtrl is a pointer to the Calender Control that I obtained using CDateTimeCtrl::GetMonthCalCtrl(): pCalCtrl->SetDayState(nMonths,pStates); The problem is that I get the following line asserts from the SetDayState Function: ASSERT(GetStyle()&MCS_DAYSTATE); Why is this happening and how can I resolve it? Thanks

    D 1 Reply Last reply
    0
    • S sschilachi

      I am responding to an DTN_DROPDOWN message from a CDateTimeCtrl in order to set the day states for the Month Calendar Control that appears when you click the dropdown button. I am using the following code to set the day states, where pCalCtrl is a pointer to the Calender Control that I obtained using CDateTimeCtrl::GetMonthCalCtrl(): pCalCtrl->SetDayState(nMonths,pStates); The problem is that I get the following line asserts from the SetDayState Function: ASSERT(GetStyle()&MCS_DAYSTATE); Why is this happening and how can I resolve it? Thanks

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      sschilachi wrote: Why is this happening and how can I resolve it? The control does not have the MCS_DAYSTATE style, therefore setting the day states makes no sense.


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      S 1 Reply Last reply
      0
      • D David Crow

        sschilachi wrote: Why is this happening and how can I resolve it? The control does not have the MCS_DAYSTATE style, therefore setting the day states makes no sense.


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        S Offline
        S Offline
        sschilachi
        wrote on last edited by
        #3

        How can I set the MCS_DAYSTATE flag, i have tried but i have had no luck?

        D R 2 Replies Last reply
        0
        • S sschilachi

          How can I set the MCS_DAYSTATE flag, i have tried but i have had no luck?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          void CMyDialog::OnClick( UINT uId, LPNMHDR, LRESULT * )
          {
          CDateTimeCtrl *pDateTimeCtrl;
          CMonthCalCtrl *pMonthCalCtrl;

          pDateTimeCtrl = (CDateTimeCtrl \*) GetDlgItem(uId);
          
          pMonthCalCtrl = pDateTimeCtrl->GetMonthCalCtrl();
          pMonthCalCtrl->ModifyStyle(0, MCS\_DAYSTATE);
          ...
          

          }


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          S 3 Replies Last reply
          0
          • S sschilachi

            How can I set the MCS_DAYSTATE flag, i have tried but i have had no luck?

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            I think this should work:

            // Get handle to MonthCalendar control
            HWND hwndDP = pCalCtrl->GetSafeHwnd();
            ASSERT (hwndDP != NULL);
            HWND hwndMC = DateTime_GetMonthCal (hwndDP);
            ASSERT (hwndMC != NULL);
            CWnd* pMCCtrl = CWnd::FromHandle (hwndMC);
            ASSERT (pMCCtrl != NULL);

            // Set its style
            DWORD dwStyle = pMCCtrl->GetStyle();
            dwStyle |= MCS_DAYSTATE;
            pMCCtrl->SetStyle (dwStyle);

            /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

            P 1 Reply Last reply
            0
            • R Ravi Bhavnani

              I think this should work:

              // Get handle to MonthCalendar control
              HWND hwndDP = pCalCtrl->GetSafeHwnd();
              ASSERT (hwndDP != NULL);
              HWND hwndMC = DateTime_GetMonthCal (hwndDP);
              ASSERT (hwndMC != NULL);
              CWnd* pMCCtrl = CWnd::FromHandle (hwndMC);
              ASSERT (pMCCtrl != NULL);

              // Set its style
              DWORD dwStyle = pMCCtrl->GetStyle();
              dwStyle |= MCS_DAYSTATE;
              pMCCtrl->SetStyle (dwStyle);

              /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

              P Offline
              P Offline
              palbano
              wrote on last edited by
              #6

              X|

              "No matter where you go, there your are." - Buckaroo Banzai

              -pete

              R 1 Reply Last reply
              0
              • P palbano

                X|

                "No matter where you go, there your are." - Buckaroo Banzai

                -pete

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #7

                The intent was to show every step in detail. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                P 1 Reply Last reply
                0
                • R Ravi Bhavnani

                  The intent was to show every step in detail. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                  P Offline
                  P Offline
                  palbano
                  wrote on last edited by
                  #8

                  pMCCtrl->SetStyle (dwStyle);

                  No such function as CWnd::SetStyle()

                  "No matter where you go, there your are." - Buckaroo Banzai

                  -pete

                  R 1 Reply Last reply
                  0
                  • P palbano

                    pMCCtrl->SetStyle (dwStyle);

                    No such function as CWnd::SetStyle()

                    "No matter where you go, there your are." - Buckaroo Banzai

                    -pete

                    R Offline
                    R Offline
                    Ravi Bhavnani
                    wrote on last edited by
                    #9

                    Gak! What was I thinking!? :-O Thank you! /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                    1 Reply Last reply
                    0
                    • D David Crow

                      void CMyDialog::OnClick( UINT uId, LPNMHDR, LRESULT * )
                      {
                      CDateTimeCtrl *pDateTimeCtrl;
                      CMonthCalCtrl *pMonthCalCtrl;

                      pDateTimeCtrl = (CDateTimeCtrl \*) GetDlgItem(uId);
                      
                      pMonthCalCtrl = pDateTimeCtrl->GetMonthCalCtrl();
                      pMonthCalCtrl->ModifyStyle(0, MCS\_DAYSTATE);
                      ...
                      

                      }


                      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                      S Offline
                      S Offline
                      sschilachi
                      wrote on last edited by
                      #10

                      The Modify style returned true, but it did not work as the line still asserted. Can anyone find the code that creates the CMonthCalCtrl object when the dropdown button is clicked, because then I will create my own instance of CMonthCalCtrl, it is just I cannot find the code to mimic its behaviour? Thanks

                      D 1 Reply Last reply
                      0
                      • D David Crow

                        void CMyDialog::OnClick( UINT uId, LPNMHDR, LRESULT * )
                        {
                        CDateTimeCtrl *pDateTimeCtrl;
                        CMonthCalCtrl *pMonthCalCtrl;

                        pDateTimeCtrl = (CDateTimeCtrl \*) GetDlgItem(uId);
                        
                        pMonthCalCtrl = pDateTimeCtrl->GetMonthCalCtrl();
                        pMonthCalCtrl->ModifyStyle(0, MCS\_DAYSTATE);
                        ...
                        

                        }


                        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                        S Offline
                        S Offline
                        sschilachi
                        wrote on last edited by
                        #11

                        I just checked the result of pMonthCalCtrl->GetStyle() before and after the use of the ModifyStyle function and the result is the same. (The ModifyStyle seems to be affecting the wrong style?) Thanks for all your help so far

                        1 Reply Last reply
                        0
                        • D David Crow

                          void CMyDialog::OnClick( UINT uId, LPNMHDR, LRESULT * )
                          {
                          CDateTimeCtrl *pDateTimeCtrl;
                          CMonthCalCtrl *pMonthCalCtrl;

                          pDateTimeCtrl = (CDateTimeCtrl \*) GetDlgItem(uId);
                          
                          pMonthCalCtrl = pDateTimeCtrl->GetMonthCalCtrl();
                          pMonthCalCtrl->ModifyStyle(0, MCS\_DAYSTATE);
                          ...
                          

                          }


                          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                          S Offline
                          S Offline
                          sschilachi
                          wrote on last edited by
                          #12

                          I also tried ModifyStyleEx and that had no effect either.

                          1 Reply Last reply
                          0
                          • S sschilachi

                            The Modify style returned true, but it did not work as the line still asserted. Can anyone find the code that creates the CMonthCalCtrl object when the dropdown button is clicked, because then I will create my own instance of CMonthCalCtrl, it is just I cannot find the code to mimic its behaviour? Thanks

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #13

                            sschilachi wrote: Can anyone find the code that creates the CMonthCalCtrl object when the dropdown button is clicked... The code I provided was from a working project that does just that, except that it adds the MCS_NOTODAY style. Remember that GetMonthCalCtrl() will only return a pointer to the month calendar control while the control actually exists--that is, while it has been dropped-down by the user. Once it has been dismissed (e.g., selecting a date), the control does not actually exist.


                            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                            S 1 Reply Last reply
                            0
                            • D David Crow

                              sschilachi wrote: Can anyone find the code that creates the CMonthCalCtrl object when the dropdown button is clicked... The code I provided was from a working project that does just that, except that it adds the MCS_NOTODAY style. Remember that GetMonthCalCtrl() will only return a pointer to the month calendar control while the control actually exists--that is, while it has been dropped-down by the user. Once it has been dismissed (e.g., selecting a date), the control does not actually exist.


                              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                              S Offline
                              S Offline
                              sschilachi
                              wrote on last edited by
                              #14

                              I know that, I am using the following code in an OnDtnDropdown() message handler for my own wrapper of the CTimeDateCtrl object that is an object in my own custom Toolbar: CMonthCalCtrl* pCtrl = (CMonthCalCtrl*) GetMonthCalCtrl(); ASSERT(pCtrl != NULL); pCtrl->ModifyStyle(0, MCS_DAYSTATE); SYSTEMTIME timeFrom; SYSTEMTIME timeUntil; int nCount = pCtrl->GetMonthRange(&timeFrom, &timeUntil, GMR_DAYSTATE); LPMONTHDAYSTATE pDayState; pDayState = new MONTHDAYSTATE[nCount]; memset(pDayState, 0, sizeof(MONTHDAYSTATE) * nCount); int nIndex = (timeFrom.wDay == 1) ? 0 : 1; pDayState[nIndex] |= BIT4; pDayState[nIndex] |= BIT19; pDayState[nIndex] |= BIT25; pCtrl->SetDayState(nCount, pDayState); delete [] pDayState; However when I call pCtrl->SetDayState(), it is there that the problem occurs and it directs me to the line that asserts that i previously mentioned. The ModifyStyle function used in the third line seems to have no effect, as I checked the return value from pCtrl->GetStyle() before and after the call to ModifyStyle and the result was the same. By the code to create the CMonthCalCtrl I meant the code that is prewritten in the source code provided with Visual C++, not the code the user writes. Thanks

                              P 1 Reply Last reply
                              0
                              • S sschilachi

                                I know that, I am using the following code in an OnDtnDropdown() message handler for my own wrapper of the CTimeDateCtrl object that is an object in my own custom Toolbar: CMonthCalCtrl* pCtrl = (CMonthCalCtrl*) GetMonthCalCtrl(); ASSERT(pCtrl != NULL); pCtrl->ModifyStyle(0, MCS_DAYSTATE); SYSTEMTIME timeFrom; SYSTEMTIME timeUntil; int nCount = pCtrl->GetMonthRange(&timeFrom, &timeUntil, GMR_DAYSTATE); LPMONTHDAYSTATE pDayState; pDayState = new MONTHDAYSTATE[nCount]; memset(pDayState, 0, sizeof(MONTHDAYSTATE) * nCount); int nIndex = (timeFrom.wDay == 1) ? 0 : 1; pDayState[nIndex] |= BIT4; pDayState[nIndex] |= BIT19; pDayState[nIndex] |= BIT25; pCtrl->SetDayState(nCount, pDayState); delete [] pDayState; However when I call pCtrl->SetDayState(), it is there that the problem occurs and it directs me to the line that asserts that i previously mentioned. The ModifyStyle function used in the third line seems to have no effect, as I checked the return value from pCtrl->GetStyle() before and after the call to ModifyStyle and the result was the same. By the code to create the CMonthCalCtrl I meant the code that is prewritten in the source code provided with Visual C++, not the code the user writes. Thanks

                                P Offline
                                P Offline
                                palbano
                                wrote on last edited by
                                #15

                                from MSDN

                                After creating the control, you can change all of the styles except for MCS_DAYSTATE and MCS_MULTISELECT. To change these styles, you will need to destroy the existing control and create a new one that has the desired styles. To retrieve or change any other window styles, use the GetWindowLong and SetWindowLong functions.

                                http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/monthcal/monthcal.asp[^]

                                "No matter where you go, there your are." - Buckaroo Banzai

                                -pete

                                S 2 Replies Last reply
                                0
                                • P palbano

                                  from MSDN

                                  After creating the control, you can change all of the styles except for MCS_DAYSTATE and MCS_MULTISELECT. To change these styles, you will need to destroy the existing control and create a new one that has the desired styles. To retrieve or change any other window styles, use the GetWindowLong and SetWindowLong functions.

                                  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/monthcal/monthcal.asp[^]

                                  "No matter where you go, there your are." - Buckaroo Banzai

                                  -pete

                                  S Offline
                                  S Offline
                                  sschilachi
                                  wrote on last edited by
                                  #16

                                  Thanks, I haven't got time to try that tonight but I will look at it tomorrow

                                  1 Reply Last reply
                                  0
                                  • P palbano

                                    from MSDN

                                    After creating the control, you can change all of the styles except for MCS_DAYSTATE and MCS_MULTISELECT. To change these styles, you will need to destroy the existing control and create a new one that has the desired styles. To retrieve or change any other window styles, use the GetWindowLong and SetWindowLong functions.

                                    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/monthcal/monthcal.asp[^]

                                    "No matter where you go, there your are." - Buckaroo Banzai

                                    -pete

                                    S Offline
                                    S Offline
                                    sschilachi
                                    wrote on last edited by
                                    #17

                                    I have tried to destroy the control using pMonthCalCtrl->DestroyWindow() in response to the user clicking the dropdown button, however, I get an access violation when i run it, how do you destroy the MonthCalCtrl? Thanks

                                    D 1 Reply Last reply
                                    0
                                    • S sschilachi

                                      I have tried to destroy the control using pMonthCalCtrl->DestroyWindow() in response to the user clicking the dropdown button, however, I get an access violation when i run it, how do you destroy the MonthCalCtrl? Thanks

                                      D Offline
                                      D Offline
                                      DRHuff
                                      wrote on last edited by
                                      #18

                                      Did you ever fix this problem? I am having the same problem in getting bold dates up. If you managed to destroy and recreate the window and get the dates bold I would love to know how. Hope your still reading. Thanks Dave

                                      S 1 Reply Last reply
                                      0
                                      • D DRHuff

                                        Did you ever fix this problem? I am having the same problem in getting bold dates up. If you managed to destroy and recreate the window and get the dates bold I would love to know how. Hope your still reading. Thanks Dave

                                        S Offline
                                        S Offline
                                        sschilachi
                                        wrote on last edited by
                                        #19

                                        No, I looked absolutely everywhere and tried just about everything but I eventually gave up as I couldn't find a solution anywhere. If I do have any success I will let you know, and could you do the same if you find a solution. Thanks

                                        D 2 Replies Last reply
                                        0
                                        • S sschilachi

                                          No, I looked absolutely everywhere and tried just about everything but I eventually gave up as I couldn't find a solution anywhere. If I do have any success I will let you know, and could you do the same if you find a solution. Thanks

                                          D Offline
                                          D Offline
                                          DRHuff
                                          wrote on last edited by
                                          #20

                                          Thanks I will let you know if I solve it as well. :~ Dave

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups