?
Solved

Problem with COLORREF type

Posted on 1998-07-28
4
Medium Priority
?
382 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
[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
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
snoegler earned 100 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

719 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