Solved

Problem with COLORREF type

Posted on 1998-07-28
4
365 Views
Last Modified: 2013-11-20
Hello

I am trying to give the user the option to change the background colour of a List Box and store the selected colour in the ini file, so that it will re-appear when they logon on again.  The code I am using is as follows:

void CPatientView::OnTextCol()
{
            // TODO: Add your control notification handler code here
CPatientDoc* pDoc = GetDocument();
CColorDialog dlg;
//dlg.SetCurrentColor(pDoc->GetColor());
if (dlg.DoModal() == IDOK)
{
      COLORREF color = dlg.GetColor();
      
      //CString Temp;
      //Temp.Format("%s", (LPCTSTR)color);
      OUR_APP->WriteProfileString( "Colours", "Background", LPCTSTR(color));
      

}

The main problem is that the entry written in the ini file is always null, whichever colour the user selects.

As far as I am aware the COLORREF type is a RGB value, can I store this in anyway in the INI file.

I very much look forward to a reply

Thanks in advance.
      

}
0
Comment
Question by:AsifMughal
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
snoegler earned 50 total points
ID: 1319862
COLORREF is a 32-bit unsigned integer so simply casting it to a string cannot be done.

In your source code you have already the correct thought:

>>    //CString Temp;                                 // <-- right
>>    //Temp.Format("%s", (LPCTSTR)color);  // <-- wrong(cast from DWORD to string)
>>    OUR_APP->WriteProfileString( "Colours", "Background", LPCTSTR(color)); //<-- wrong

CString temp;
temp.Format("%ld",(DWORD)color);
OUR_APP->WriteProfileString("Colours","Background",temp);

To retrieve it again:
CString temp=OUR_APP->GetProfileString("Colours","Background");
color=(COLORREF)atol(temp); //atol() returns the string to int value

0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319863
Don't give me credit for this, but you're going about it the hard way!!!

How about just...

WriteProfileInt( "Colours", "Background", color );

and

color = GetProfileInt( "Colours", "Background", RGB( default ));

Phillip
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1319864
Sorry you are right. I don't have to do much with these WriteProfile... things, so i didn't see that
there is a function for writing an integer.
I think you should get the points :(
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319865
Well, I feel guilty for answering an answered question!

Phillilp

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 136
Hibernate methods 2 71
only14 challenge 19 75
Sed question 2 84
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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