Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem with COLORREF type

Posted on 1998-07-28
4
Medium Priority
?
384 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Loops Section Overview

972 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