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.
  • 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
                        • 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
                          #21

                          Well I worked around it so that I can use it the way I want!:-D:-D:-D Basically I added an invisible Month Calendar control which I then set to the same space as the DateTimePickers rect in the DropDown handler. I also set a flag for bMonthShowing. In the OnPaint method I use the bMonthShowing flag to let me know to reposition the windows m_pMonth->SetWindowPos(&wndNoTopMost, 0, 0, 1, 1, SWP_NOMOVE | SWP_SHOWWINDOW); m_ctlMonth.SetWindowPos(&wndTopMost, 0, 0, 1, 1, SWP_NOMOVE | SWP_SHOWWINDOW); In the CloseUp handler I set the MonthCalendar invisible. For the month calendar I handle the GetDayStates to set which days I want bold. In the OnSelect for the month calendar I do the following: COleDateTime t; SYSTEMTIME tt; BOOL ret = m_ctlMonth.GetCurSel(&tt); t.SetDate(tt.wYear, tt.wMonth, tt.wDay); m_ctlDatePicker.SetTime(t); (If I did the GetCurSel directly into a COleDateTime it comes back with an invalid status :confused: ) And everything works! All right I missed one or two (or more) things. oops What a kludge! If you want I can send you the whole dialog project. Let me know. 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