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 in Windows 10

CDateTimeCtrl in Windows 10

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionannouncement
19 Posts 8 Posters 0 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.
  • U Offline
    U Offline
    User 13100121
    wrote on last edited by
    #1

    I have a project that has a CDateTimeCtrl in it. The program worked fine for years. I ran a long Windows 10 update and now the date time ctrl displays as // instead of the initial date. Has anyone else come across this problem and do you have a solution?

    L D L J 5 Replies Last reply
    0
    • U User 13100121

      I have a project that has a CDateTimeCtrl in it. The program worked fine for years. I ran a long Windows 10 update and now the date time ctrl displays as // instead of the initial date. Has anyone else come across this problem and do you have a solution?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to provide more information. The chances of anyone else having a similar problem AND just happening to read your message, are not likely to be very high. Also I have deleted your two reposts of this question.

      1 Reply Last reply
      0
      • U User 13100121

        I have a project that has a CDateTimeCtrl in it. The program worked fine for years. I ran a long Windows 10 update and now the date time ctrl displays as // instead of the initial date. Has anyone else come across this problem and do you have a solution?

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

        What does your code look like that populates that control?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        1 Reply Last reply
        0
        • U User 13100121

          I have a project that has a CDateTimeCtrl in it. The program worked fine for years. I ran a long Windows 10 update and now the date time ctrl displays as // instead of the initial date. Has anyone else come across this problem and do you have a solution?

          L Offline
          L Offline
          leon de boer
          wrote on last edited by
          #4

          Windows 10 update has a new garbage collector. You used to get away with stuff you can't anymore. For a font to be set, it must remain in memory, it can not be a variable font (like on the local stack) that is destroyed directly after setting it. Old code used to work because the old garbage collector was terrible, try it now and your font will be gone bye bye. The telltale giveaway you did it all wrong is I bet you never deleted the CFONT you made even though you are supposed to and it's your responsibility. The reason you won't have is because when you close the class/dialog or window you no longer have access to the CFONT because it was just some local variable on the stack. Such code is not only bugged it bleeds font handles but "it did used to work". So lets ask that question does your code delete the Cfont you made? :-) To make sure your Cfont is valid for the life of it's use, you have 3 options 1.) Place it up in the class, dialog or window data that the font is being used for 2.) Make it a global variable or do a globalalloc 3.) Use SelectObject to put it on a DC that persists for the time you need it Finally it is your responsibility to clean up and dispose the font when your class/dialog or windows or use of it ends ... you know something like font.DeleteObject(); Basically if this is the problem your old code was always bugged you were just lucky the bug didn't shake out before because the old windows GC was horrible.

          In vino veritas

          M 1 Reply Last reply
          0
          • L leon de boer

            Windows 10 update has a new garbage collector. You used to get away with stuff you can't anymore. For a font to be set, it must remain in memory, it can not be a variable font (like on the local stack) that is destroyed directly after setting it. Old code used to work because the old garbage collector was terrible, try it now and your font will be gone bye bye. The telltale giveaway you did it all wrong is I bet you never deleted the CFONT you made even though you are supposed to and it's your responsibility. The reason you won't have is because when you close the class/dialog or window you no longer have access to the CFONT because it was just some local variable on the stack. Such code is not only bugged it bleeds font handles but "it did used to work". So lets ask that question does your code delete the Cfont you made? :-) To make sure your Cfont is valid for the life of it's use, you have 3 options 1.) Place it up in the class, dialog or window data that the font is being used for 2.) Make it a global variable or do a globalalloc 3.) Use SelectObject to put it on a DC that persists for the time you need it Finally it is your responsibility to clean up and dispose the font when your class/dialog or windows or use of it ends ... you know something like font.DeleteObject(); Basically if this is the problem your old code was always bugged you were just lucky the bug didn't shake out before because the old windows GC was horrible.

            In vino veritas

            M Offline
            M Offline
            Member 1501249
            wrote on last edited by
            #5

            Leon, Sorry, but I don't think this is the problem. Create a new dialog based MFC application. MBCS character set. Put a datetimepicker control on the dialog. Even this tiny sample application will demonstrate the problem. Customers did report this problem, but until now we couldn't reproduce it at our office. Related is: - If the application is started from "Run as administrator", there is no problem. - It might be the chosen character set is related. I have only seen it in a MBCS sample, not in a Unicode sample. I am not quite sure about this.

            L M U 3 Replies Last reply
            0
            • M Member 1501249

              Leon, Sorry, but I don't think this is the problem. Create a new dialog based MFC application. MBCS character set. Put a datetimepicker control on the dialog. Even this tiny sample application will demonstrate the problem. Customers did report this problem, but until now we couldn't reproduce it at our office. Related is: - If the application is started from "Run as administrator", there is no problem. - It might be the chosen character set is related. I have only seen it in a MBCS sample, not in a Unicode sample. I am not quite sure about this.

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              Yeah I take it back MFC is bugged now you can't set any font not just that one ..... just go around the stupidity of MFC and use the Windows API direct

              LOGFONT lf;
              // clear out structure
              memset(&lf, 0, sizeof(LOGFONT));
              // request a 12-pixel-height font
              lf.lfHeight = 12;
              // request a face name "MS Shell Dlg"
              _tcsncpy_s(lf.lfFaceName, LF_FACESIZE, _T("MS Shell Dlg"), _tcslen(_T("MS Shell Dlg")));
              // create the font
              HFONT hfont = ::CreateFontIndirect(&lf);

              // Send the WM_SETFONT message to the date time control
              m_dateTimeCtrl.SendMessage(WM_SETFONT, (WPARAM)hfont, 1);

              That works fine and they can't break that or everything would break because it is how you change fonts on any window.

              In vino veritas

              M 1 Reply Last reply
              0
              • M Member 1501249

                Leon, Sorry, but I don't think this is the problem. Create a new dialog based MFC application. MBCS character set. Put a datetimepicker control on the dialog. Even this tiny sample application will demonstrate the problem. Customers did report this problem, but until now we couldn't reproduce it at our office. Related is: - If the application is started from "Run as administrator", there is no problem. - It might be the chosen character set is related. I have only seen it in a MBCS sample, not in a Unicode sample. I am not quite sure about this.

                M Offline
                M Offline
                Michael E Jones
                wrote on last edited by
                #7

                Hi, I can confirm the problem. Seem to be the Windows Creators Update... Two days ago one of our applications was displaying the date correctly and now it is only displaying a few random pixels. The same application run on a system that has not been updated works as expected. Using the, byte-for-byte, same executable - nothing to do with MFC or changes in the RTL. EDIT: Adding a manifest with "Microsoft.Windows.Common-Controls" does improve things (apart from the fact that all controls look different, which might be a problem for the odd application) - Microsoft has definitely changed some visual behaviour...

                ABC 
                

                cu, Michael

                L J 2 Replies Last reply
                0
                • M Michael E Jones

                  Hi, I can confirm the problem. Seem to be the Windows Creators Update... Two days ago one of our applications was displaying the date correctly and now it is only displaying a few random pixels. The same application run on a system that has not been updated works as expected. Using the, byte-for-byte, same executable - nothing to do with MFC or changes in the RTL. EDIT: Adding a manifest with "Microsoft.Windows.Common-Controls" does improve things (apart from the fact that all controls look different, which might be a problem for the odd application) - Microsoft has definitely changed some visual behaviour...

                  ABC 
                  

                  cu, Michael

                  L Offline
                  L Offline
                  leon de boer
                  wrote on last edited by
                  #8

                  Yes but the API itself behaves correctly it's just frameworks that are breaking and that is fine it is just a framework support issue. The problem now is MFC is no longer a direct Microsoft support framework they have released the sourcecode as it reached end of it's commercial life. It will be interesting to see if they fix it or just tell us we have the sourcecode and we need to go and fix it ... really it isn't their problem anymore and they can wipe there hands of it. Wonder if it's broken on .NET or WPF I will have to go and have a look later today, their response may differ depending on that.

                  In vino veritas

                  L 1 Reply Last reply
                  0
                  • L leon de boer

                    Yeah I take it back MFC is bugged now you can't set any font not just that one ..... just go around the stupidity of MFC and use the Windows API direct

                    LOGFONT lf;
                    // clear out structure
                    memset(&lf, 0, sizeof(LOGFONT));
                    // request a 12-pixel-height font
                    lf.lfHeight = 12;
                    // request a face name "MS Shell Dlg"
                    _tcsncpy_s(lf.lfFaceName, LF_FACESIZE, _T("MS Shell Dlg"), _tcslen(_T("MS Shell Dlg")));
                    // create the font
                    HFONT hfont = ::CreateFontIndirect(&lf);

                    // Send the WM_SETFONT message to the date time control
                    m_dateTimeCtrl.SendMessage(WM_SETFONT, (WPARAM)hfont, 1);

                    That works fine and they can't break that or everything would break because it is how you change fonts on any window.

                    In vino veritas

                    M Offline
                    M Offline
                    Member 1501249
                    wrote on last edited by
                    #9

                    Leon, Thanks, you are right, this is related. And, indeed, it improves the result, but it is still not how it was before the installation of the Windows 10 creator update. We tried the following: - Your code, with CreateFont it will show the date as "21- 4 - ". The year is not visible - m_dateTimeCtrl.SetFont(GetFont()); it will show the date as "21- 4 - 2017". The string is right aligned in the control - m_dateTimeCtrl.SetFormat( _T("dd'-'MM'-'yyyy")); This gives the best result, but is not really an option, because it overrides the system settings for the shortdate presentation

                    M 1 Reply Last reply
                    0
                    • M Member 1501249

                      Leon, Thanks, you are right, this is related. And, indeed, it improves the result, but it is still not how it was before the installation of the Windows 10 creator update. We tried the following: - Your code, with CreateFont it will show the date as "21- 4 - ". The year is not visible - m_dateTimeCtrl.SetFont(GetFont()); it will show the date as "21- 4 - 2017". The string is right aligned in the control - m_dateTimeCtrl.SetFormat( _T("dd'-'MM'-'yyyy")); This gives the best result, but is not really an option, because it overrides the system settings for the shortdate presentation

                      M Offline
                      M Offline
                      Member 1501249
                      wrote on last edited by
                      #10

                      It is even more complicated: if I put the above mentioned tests into one project, it behaves different in comparison to three separated test projects! This behaviour let me think of some kind of memory corruption (stack?), but I can't pinpoint until now how this can occur in a trivial test application.

                      L 1 Reply Last reply
                      0
                      • L leon de boer

                        Yes but the API itself behaves correctly it's just frameworks that are breaking and that is fine it is just a framework support issue. The problem now is MFC is no longer a direct Microsoft support framework they have released the sourcecode as it reached end of it's commercial life. It will be interesting to see if they fix it or just tell us we have the sourcecode and we need to go and fix it ... really it isn't their problem anymore and they can wipe there hands of it. Wonder if it's broken on .NET or WPF I will have to go and have a look later today, their response may differ depending on that.

                        In vino veritas

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        leon de boer wrote:

                        Wonder if it's broken on .NET

                        See My (previously working) DateTimePickers have gone nuts! - .NET Framework Discussion Boards[^].

                        1 Reply Last reply
                        0
                        • M Member 1501249

                          It is even more complicated: if I put the above mentioned tests into one project, it behaves different in comparison to three separated test projects! This behaviour let me think of some kind of memory corruption (stack?), but I can't pinpoint until now how this can occur in a trivial test application.

                          L Offline
                          L Offline
                          leon de boer
                          wrote on last edited by
                          #12

                          I would say the WM_SETFONT call is working the reason the last digits are not displaying is because it doesn't have enough room in the box. That is the default behaviour to drop the last word that doesn't fit in the area. Try making the box just a fraction wider or reduce the font size. It's highlighting another issue that the font is coming out slightly different size to before but that is probably not surprising. You could try the height in pixels as a minus sign that tells windows not to round the value to best value but make the value absolute. I don't know what details the original MFC used to select the font but you could look up the code section. LOGFONT structure (Windows)[^] < 0 = The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts.

                          In vino veritas

                          M 1 Reply Last reply
                          0
                          • M Michael E Jones

                            Hi, I can confirm the problem. Seem to be the Windows Creators Update... Two days ago one of our applications was displaying the date correctly and now it is only displaying a few random pixels. The same application run on a system that has not been updated works as expected. Using the, byte-for-byte, same executable - nothing to do with MFC or changes in the RTL. EDIT: Adding a manifest with "Microsoft.Windows.Common-Controls" does improve things (apart from the fact that all controls look different, which might be a problem for the odd application) - Microsoft has definitely changed some visual behaviour...

                            ABC 
                            

                            cu, Michael

                            J Offline
                            J Offline
                            JamesA_Dev
                            wrote on last edited by
                            #13

                            I think there's a typo and the 2nd one should be "*" rather than "'*'" ? Thanks, it's not feasible to replace old software on all customer sites. Adding the manifest file and setting the reg key below to make it be used gives us an option in case Microsoft decide not to fix it. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide PreferExternalManifest 1

                            1 Reply Last reply
                            0
                            • U User 13100121

                              I have a project that has a CDateTimeCtrl in it. The program worked fine for years. I ran a long Windows 10 update and now the date time ctrl displays as // instead of the initial date. Has anyone else come across this problem and do you have a solution?

                              J Offline
                              J Offline
                              JamesA_Dev
                              wrote on last edited by
                              #14

                              Can anyone else getting this problem please go to Microsoft Connect number 3129203 and vote it up.

                              1 Reply Last reply
                              0
                              • L leon de boer

                                I would say the WM_SETFONT call is working the reason the last digits are not displaying is because it doesn't have enough room in the box. That is the default behaviour to drop the last word that doesn't fit in the area. Try making the box just a fraction wider or reduce the font size. It's highlighting another issue that the font is coming out slightly different size to before but that is probably not surprising. You could try the height in pixels as a minus sign that tells windows not to round the value to best value but make the value absolute. I don't know what details the original MFC used to select the font but you could look up the code section. LOGFONT structure (Windows)[^] < 0 = The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts.

                                In vino veritas

                                M Offline
                                M Offline
                                Member 1501249
                                wrote on last edited by
                                #15

                                Sorry, this doesn't solve the problem. On different Windows 10 creator update PC's, we get different results, all of them are incorrect.

                                L 1 Reply Last reply
                                0
                                • M Member 1501249

                                  Sorry, this doesn't solve the problem. On different Windows 10 creator update PC's, we get different results, all of them are incorrect.

                                  L Offline
                                  L Offline
                                  leon de boer
                                  wrote on last edited by
                                  #16

                                  If that doesn't work MS have a problem because that is a documented API call nothing to do with frameworks etc .. just log it with them as a bug and they will have to fix. It should get a reasonably high priority especially since it is easy to replicate.

                                  In vino veritas

                                  M 1 Reply Last reply
                                  0
                                  • M Member 1501249

                                    Leon, Sorry, but I don't think this is the problem. Create a new dialog based MFC application. MBCS character set. Put a datetimepicker control on the dialog. Even this tiny sample application will demonstrate the problem. Customers did report this problem, but until now we couldn't reproduce it at our office. Related is: - If the application is started from "Run as administrator", there is no problem. - It might be the chosen character set is related. I have only seen it in a MBCS sample, not in a Unicode sample. I am not quite sure about this.

                                    U Offline
                                    U Offline
                                    UrbanBlues
                                    wrote on last edited by
                                    #17

                                    Hello I faced the same problem .. I decided to go to 64 bits Unicode (with a lot of work to migrate to Unicode) and add the following lines to stdafx.h

                                    #ifdef _UNICODE
                                    #if defined _M_IX86
                                    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
                                    #elif defined _M_X64
                                    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
                                    #else
                                    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
                                    #endif
                                    #endif

                                    It works perfectly. The 'new' is smarter and with a cleaner look ... It was finally worth the work Thierry www.tgmdev.be

                                    1 Reply Last reply
                                    0
                                    • U User 13100121

                                      I have a project that has a CDateTimeCtrl in it. The program worked fine for years. I ran a long Windows 10 update and now the date time ctrl displays as // instead of the initial date. Has anyone else come across this problem and do you have a solution?

                                      J Offline
                                      J Offline
                                      JamesA_Dev
                                      wrote on last edited by
                                      #18

                                      Fixed :) June 13th Cumulative Update - kb4022725

                                      1 Reply Last reply
                                      0
                                      • L leon de boer

                                        If that doesn't work MS have a problem because that is a documented API call nothing to do with frameworks etc .. just log it with them as a bug and they will have to fix. It should get a reasonably high priority especially since it is easy to replicate.

                                        In vino veritas

                                        M Offline
                                        M Offline
                                        Member 1501249
                                        wrote on last edited by
                                        #19

                                        The problem is solved in Microsoft's update of June.

                                        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