I need help modifying an existing app written in C++. Take info from *.ini file and use it in app to change colors.

Hi Experts, I have no C++ backround.  I write in VB and ASP.  I currently have a project which is very urgent and requires immediate attention.

I curently have an application which has several display controls.  I need to be able to edit the color of these in my ini file.

e.g.

[Display]
BackgroundColor=
BorderColor=
StaticTextColor=
DynamicTextColor=
GraphOutlineColor=
GraphActiveElementColor=
PageHighlightColor=
AlarmColor=

Then when my app starts up it will extract this data  and implent it to my GUI.  I am sure this is relatvely easy (when you know how!!) as the current app uses other info from the ini file.  I want to use this as a learning experience for myself, I seek help due to the urgency of this project.

I can't eeven figure out how to view the form in design view like in vb??

I wish to mail the code over to anyone wishing to help.  I will also give extra points

I need HELP
RickyHannaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

itsmeandnobodyelseCommented:
If using MFC (Microsoft Foundation Classes, a VC class library) you may fetch the items from the inifile like that:

       // if you are using string values for the colors, e. g.  BorderColor=red
       CString BorderColor;
       int nLen = GetPrivateProfileString("Display", "BorderColor", "", BorderColor.GetBuffer(20), 20, "C:\\temp\\myinifile.ini");
       BorderColor.ReleaseBuffer(-1);

or

      // if you are using RGB values, e. g.  BorderColor=255 0 0, you could do that:      

       CString BorderColor;
       int nLen = GetPrivateProfileString("Display", "BorderColor", "", BorderColor.GetBuffer(20), 20, "C:\\temp\\myinifile.ini");
       BorderColor.ReleaseBuffer(-1);

       COLORREF rgbBorderColor;
       int red = atoi(BorderColor);
       int pos = BorderColor.Find(' ');
       if (pos < 0)  return -1;    // error: no space between red and green
       int green = atoi(BorderColor.Mid(pos+1));
       pos = BorderColor.Find(' ', pos+1);
       if (pos < 0)  return -1;    // error: no space between green and blue
       int blue = atoi(BorderColor.Mid(pos+1));
       COLORREF rgbBorderColor = RGB(red, green, blue);

If not using MFC you can do the same by that:

   #include <iostream>
   #include <string>
   using namespace std;

   struct Colors
   {
      string BackgroundColor;
      string BorderColor;
      string StaticTextColor;
      string DynamicTextColor;
      string GraphOutlineColor;
      string GraphActiveElementColor;
      string PageHighlightColor;
      string AlarmColor;
   };  

   bool getColorsFromInifile(Colors& cols, const string& inifile)
   {
         ifstream ifs(inifile);
         string line;
         bool display_found = false;
         while(getline(ifs, line))
         {
                 if (!display_found)
                 {
                     if (line.find("[Display]" != string::npos)
                          display_found = true;
                 }
                 else if (line.find('[') == 0)
                        break;          // we are thru if there is the next inifile section
                 else
                 {
                       int pos = line.find('=');
                       if (pos != string::npos && pos > 0)
                       {
                               string key = line.substr(0, pos);
                               if ( key == "BackgoundColor")
                                   cols.BackgroundColor = line.substr(pos+1);
                               else if ( key == "BorderColor")
                                   cols.BorderColor = line.substr(pos+1);
                               else if ....
                       }
                 }    
         }
         ifs.close();
         return display_found;
   }    

Regards, Alex
0
RickyHannaAuthor Commented:
Can I mail you what I have?

I'm kinda lost.

Thanks so far

Ricky
0
itsmeandnobodyelseCommented:
You could mail to

     info ad sbsweb dot info

but you would get more answers if you simply post your code (or the relevant parts) here in EE.

Regards, Alex
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

RickyHannaAuthor Commented:
I have mailed it.  I also don't understand how to view the visual part to see the controls at design time, like in vb

I really appreciate your help!!

Ricky
0
itsmeandnobodyelseCommented:
I got it.  But need some time to analyze it. Have to take some hours sleep before.

Regards, Alex
0
RickyHannaAuthor Commented:
I hear you there.

Ha ha

Thanks so much for your help.  

Ricky
0
itsmeandnobodyelseCommented:
Add that source to your project. It should do the job. Call function

    getColorsFromInifile(inifilefullpath);

from Winhcd.cpp in

   int config_system_vars(void)

function after call

   init_def();

Good luck, Alex



#include "winhpd.h"


enum ColorIndex {
    IDX_REFERENCE_BLACK,          
    IDX_REFERENCE_RED,
    IDX_REFERENCE_GREEN,          
    IDX_REFERENCE_BLUE,          
    IDX_REFERENCE_WHITE,          
    IDX_REFERENCE_GREY,          
    IDX_REFERENCE_YELLOW,    
    IDX_REFERENCE_PINK,          
    IDX_REFERENCE_TURQUOISE,
    IDX_REFERENCE_LIGHTBLUE,      
    IDX_REFERENCE_LIGHTGREEN,
    IDX_REFERENCE_LIGHTRED,      
    IDX_REFERENCE_LIGHTYELLOW,    
    IDX_REFERENCE_LIGHTPINK,      
    IDX_REFERENCE_LIGHTTURQUOISE,
    IDX_REFERENCE_PURPLE,
    IDX_PINK,
    IDX_BACKGROUND_LIGHT_BLUE,
    IDX_BACKGROUND_DEEP_BLUE,  
    IDX_BACKGROUND_LIGHT_GREEN,
    IDX_BACKGROUND_DARK_GREEN,  
    IDX_ORANGE_RED,            
    IDX_DARK_GREY,              
    IDX_BORDER_GREY,
    MAX_IDX_COLOR
};

COLORREF rgbColors[MAX_IDX_COLOR] =
{
    REFERENCE_BLACK,            
    REFERENCE_RED,  
    REFERENCE_GREEN,            
    REFERENCE_BLUE,            
    REFERENCE_WHITE,            
    REFERENCE_GREY,            
    REFERENCE_YELLOW,      
    REFERENCE_PINK,            
    REFERENCE_TURQUOISE,  
    REFERENCE_LIGHTBLUE,        
    REFERENCE_LIGHTGREEN,  
    REFERENCE_LIGHTRED,        
    REFERENCE_LIGHTYELLOW,      
    REFERENCE_LIGHTPINK,        
    REFERENCE_LIGHTTURQUOISE,  
    REFERENCE_PURPLE,  
    PINK,  
    BACKGROUND_LIGHT_BLUE,  
    BACKGROUND_DEEP_BLUE,    
    BACKGROUND_LIGHT_GREEN,  
    BACKGROUND_DARK_GREEN,  
    ORANGE_RED,              
    DARK_GREY,              
    BORDER_GREY,  
};

char* szColors[MAX_IDX_COLOR] = {
    "REFERENCE_BLACK",          
    "REFERENCE_RED",
    "REFERENCE_GREEN",          
    "REFERENCE_BLUE",          
    "REFERENCE_WHITE",          
    "REFERENCE_GREY",          
    "REFERENCE_YELLOW",    
    "REFERENCE_PINK",          
    "REFERENCE_TURQUOISE",
    "REFERENCE_LIGHTBLUE",      
    "REFERENCE_LIGHTGREEN",
    "REFERENCE_LIGHTRED",      
    "REFERENCE_LIGHTYELLOW",    
    "REFERENCE_LIGHTPINK",      
    "REFERENCE_LIGHTTURQUOISE",
    "REFERENCE_PURPLE",
    "PINK",
    "BACKGROUND_LIGHT_BLUE",
    "BACKGROUND_DEEP_BLUE",  
    "BACKGROUND_LIGHT_GREEN",
    "BACKGROUND_DARK_GREEN",  
    "ORANGE_RED",            
    "DARK_GREY",              
    "BORDER_GREY",
};

enum GUIColor {
      BACKGROUNDCOLOR,
      BORDERCOLOR,
      DISABLECOLOR,        
      STATICTEXTCOLOR,
      DYNAMICTEXTCOLOR,
      GRAPHOUTLINECOLOR,
      GRAPHACTIVEELEMENTCOLOR,
      BARGRAPHCOLOR,
      PAGEHIGHLIGHTCOLOR,
      ALARMCOLOR,
      MAX_GUI_COLOR
};


char* szGUIColors[MAX_GUI_COLOR] = {
    "BackgroundColor",
    "BorderColor",
    "DisableColor",        
    "StaticTextColor",
    "DynamicTextColor",
    "GraphOutlineColor",
    "GraphActiveElementColor",
    "BarGraphColor",
    "PageHighlightColor",
    "AlarmColor",
};

COLORREF* pGUIColors[MAX_GUI_COLOR] = {
    &backgroundcolor,      
    &bordercolor,          
    &disablecolor,          
    &statictextcolor,      
    &dynamictextcolor,      
    &graphoutlinecolor,    
    &graphactiveelementcolor,
    &bargraphcolor,        
    &pagehighlightcolor,        
    &alarmcolor,                
};

const int EQUAL = 0;

void getColorsFromInifile(LPCSTR pszInifile)
{
    //  e.g.  BorderColor=RED
    char szBuffer[128] = { '\0' };

    for (int i = 0; i < MAX_GUI_COLOR; ++i)
    {
        int nLen = GetPrivateProfileString("Display", szGUIColors[i], "", szBuffer, sizeof(szBuffer), pszInifile);
        if (nLen > 0)
        {
            for (int n = 0; n < MAX_IDX_COLOR; ++n)
            {
                if (stricmp(szColors[n], szBuffer) == EQUAL)
                {
                    *pGUIColors[n] = rgbColors[n];
                    break;
                }
            }
        }
    }
}


0
itsmeandnobodyelseCommented:
You'll need a forward declaration in winhpd.cpp:

...
#include "winHPD.h"
#include "ntport.h"

// forward declaration
void getColorsFromInifile(LPCSTR pszInifile);

...


Define colors in winhpd.ini like that (you may use any value defined in szColors above)

[Display]
BackgroundColor=REFERENCE_PINK
BorderColor=ORANGE_RED
StaticTextColor=
DynamicTextColor=
GraphOutlineColor=
GraphActiveElementColor=
PageHighlightColor=
AlarmColor=


>> I can't eeven figure out how to view the form in design view like in vb??

Normally, you could view a form using the resource editor. That is one of the tabs of your project tree window. However, there is no form to edit in your prog as all controls were dynamically painted not using a dialog form. In fact, most of your GUI is C and native Windows API and not C++ and MFC. The displaying stuff is done in display.c (note, all sources having a ".c" extension were compiled using the ANSI C compiler and *not* C++. That doesn't harm beside of there is GUI program where you could easily modify the design of the application.

Regards, Alex




0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RickyHannaAuthor Commented:
Well I have added your code, none of YOUR code is giving me errors. though it is giving me this back????


LINK : fatal error LNK1207: incompatible PDB format in "C:\Documents and Settings\rhhanna\Desktop\c Project\Debug\winHPD.pdb"; delete and rebuild
Error executing link.exe.

winHPD.exe - 1 error(s), 0 warning(s)

Any ideas?  I will award extra points by the way!

Thanks so much for your time and effort so far
0
itsmeandnobodyelseCommented:
>> Any ideas?

Where did you add the code above? I used a source called colors.cpp. You also could add it to winhpd.cpp. But not to a .c source as it is C++ code. Try to close your project (leave Visual Studio), delete Debug directory using the Explorer and make a rebuild.  That should solve the problem.

>> I will award extra points by the way!

500 points and grade A is the maximum for one question in EE. And that's ok. The only way to honour an extraordinary help - or give the maximum points to more than one expert - is to open a new question named 'points for xyz' and accept xyz's answer.

Regards, Alex
0
RickyHannaAuthor Commented:
Hi I have zipped up the code with all the changes made.  All the code has been added to the winHPD.cpp file.

Can you look to see if you can identify the problem?

I have created another thread called '500 Points For  itsmeandnobodyelse'
Thanks
Ricky
0
RickyHannaAuthor Commented:
I have the color solution .

Thanks for the code, see you at the other thread

Ricky
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.