[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Store CTime object in registry

Posted on 2004-05-02
4
Medium Priority
?
357 Views
Last Modified: 2013-11-20
Hello !

I am writing an app that uses "Reminders"; i.e. the user can enter a subject, details and due time as a reminder for them to do something.  The subject and details of the reminder are stored in CStrings (obtained from CEdit controls) and the data/time are stored in CTime objects (obtained from CDateTimeCtrl controls).  When that time arrives, a dialogue box pops up telling the user so.  In essence, it is very similar to Outlook's "tasks".  

All of this information is to be stored in the registry, but I cannot see how to store a CTime object in a manner so it can re-read back.  I need to read it back to re-initialise the CDateTimeCtrl controls when re-displaying all of the reminders the next time the app is started and the user chooses to view them.

Any ideas ?

TIA !
0
Comment
Question by:mrwad99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 1400 total points
ID: 10971339
You can keep CTime as 6 different int values in the Registry:

CTime time;
// fill time

WriteProfileInt("Time", "year", time.GetYear());
...
WriteProfileInt("Time", "second", time.GetSecond());

To read CTime from Registry read all these values and use CTime constructor:

CTime( int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST = -1 );

You can keep all these values as one string formatting it using String.Format and extracting values from it using sscanf. For example, time in Registry may look as:

"2004 5 2 12 25 55"
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 400 total points
ID: 10971502
Hi ,

You can even read/write CTime object binary from/to the Registry, i.e.:

...
      HKEY hKey;
      LONG lRes = RegOpenKeyEx( HKEY_CURRENT_USER, "test", 0, KEY_ALL_ACCESS, &hKey );

      if ( ERROR_SUCCESS != lRes )
      {
            // does not exist ... create
            lRes = RegCreateKey( HKEY_CURRENT_USER, "test", &hKey );

            if ( ERROR_SUCCESS != lRes )
            {
                  AfxMessageBox( "Error: cannot create \"HK_CU/Test\"" );
                  return -1;
            }

            CTime time( 1975, 5, 21, 22, 15, 0 ); // just a sample date

            // write to registry
            RegSetValueEx( hKey, "test_time", 0, REG_BINARY, (BYTE*)&time, sizeof( CTime ) );
      }
      else
      {
            // read from Registry
            DWORD dwType, dwSize = 0;
            lRes = RegQueryValueEx( hKey, "test_time", 0, &dwType, NULL, &dwSize );

            if ( ERROR_SUCCESS == lRes && REG_BINARY == dwType && sizeof( CTime ) == dwSize )
            {
                  // ok, it's a CTime
                  CTime time;
                  RegQueryValueEx( hKey, "test_time", 0, NULL, (BYTE*)&time, &dwSize );
                  AfxMessageBox( time.Format( "%A, %B %d, %Y" ) );
            }
      }
...

hope that helps,

ZOPPO
0
 
LVL 19

Author Comment

by:mrwad99
ID: 10971522
Thanks both; am just trying all suggestions - will be back ASAP :)
0
 
LVL 19

Author Comment

by:mrwad99
ID: 10971589
Right, both answers were perfectly acceptable so I split the 200 points between you both.  AlexFM I have given you another 250 points as you effectively answered another of my questions - http:Q_20963387.html - although you did so at http:Q_20963870.html - and never accepted credit for it.

Thanks all.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question