Solved

Problem with COLORREF type

Posted on 1998-07-28
4
360 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Well, I feel guilty for answering an answered question!

Phillilp

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
while loop over for loop 7 79
format the code in java 6 72
Doc'in system (example?) BA 7 77
either24  challenge 19 83
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now