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

x
?
Solved

multi lines in .ini file how to save and load/read ?

Posted on 2004-08-29
14
Medium Priority
?
500 Views
Last Modified: 2013-11-20
I am working on this little clock program and I added notepad to it.
I wanted it to save notepad text to its one ini file only.

Dont tell me to save it to anothet txt file.  
I already know basics of saving and reading to .ini files in MFC pragramming.    

I want to do same thing as the script editor in mIRC.
the script editor in mIRC saves multi lines to .ini like this
n1=text34234
n2=i love you
n3=this is funny  


Here is my .ini  

[BOX1]
Title=test1 remeber me
Hour=10
Minutes=1
AM_PM=PM
[BOX2]
Title=test2
Hour=3
Minutes=4
AM_PM=PM
[BOX3]
Title=test3
Hour=5
Minutes=6
AM_PM=PM
[BOX4]
Title=test4
Hour=0
Minutes=0
AM_PM=AM
[BOX5]
Title=test5
Hour=0
Minutes=0
AM_PM=AM
[BOX6]
Title=test6
Hour=0
Minutes=0
AM_PM=AM
[NOTEPAD]


note=dfsdfasdjf
fksjflasd;f
df;alsdf;ladsf

MY COOL NOTE PAD !!!!!!



when you open it again after you close it

you only see dfsdfasdjf


I know I need to add

note1=
note2=
note3=
note4=


here is my screenshot

http://dasher.psychz.net/~area51/notepadclock.jpg


0
Comment
Question by:Alien3
  • 7
  • 7
14 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11926399
I am not sure I have understood your question, I think you want to save a multiline string in many .ini entries. Could be something like this:

CString text = GetDlgItemText(YOUR_CONTROL_ID);   // Some method to retrieve your text
CString line, label;
int count=0;

while (!text.IsEmpty()) {
    line = text.SpanExcluding("\n\r");
    if (!line.IsEmpty()) {
        label.Format("note%i", ++count);
        // Put here your write to .ini function (may WriteProfileString?) using label and line
    }
    text.Delete(0, line.GetLenght());
    line = text.SpanIncluding("\n\r");
    text.Delete(0, line.GetLenght());
}
0
 
LVL 1

Author Comment

by:Alien3
ID: 11926521
your code bring errors  

here is my function.  

void CMyDigClockDlg::OnSavenote()
{

char sIniFile[MAX_PATH];
GetModuleFileName( NULL, sIniFile, MAX_PATH );
strcpy( strrchr( sIniFile, '\\' ) + 1, "reminderclock.ini" );


WritePrivateProfileString("NOTEPAD", NULL, NULL, sIniFile);
CString KeyName;


CString text = GetDlgItemText(IDC_NOTEPAD);   // Some method to retrieve your text
CString line, label;
int count=0;

while (!text.IsEmpty()) {
    line = text.SpanExcluding("\n\r");
    if (!line.IsEmpty()) {
        label.Format("note%i", ++count);
        // Put here your write to .ini function (may WriteProfileString?) using label and line

WritePrivateProfileString("NOTEPAD", label, m_notepad, sIniFile);

    }
    text.Delete(0, line.GetLenght());
    line = text.SpanIncluding("\n\r");
    text.Delete(0, line.GetLenght());
}



/*

char notepad[MAX_PATH];
int loop;
CString temp_key;


///WritePrivateProfileString ("NOTEPAD", "note", m_notepad, sIniFile);
WritePrivateProfileStruct("NOTEPAD", "note", (LPVOID)&m_notepad, sizeof(m_notepad), sIniFile);

      for (loop = 0; loop < m_notepad.Get; ++loop)
      {
            temp_key.Format ("note%2.2d", loop);




            WritePrivateProfileStruct ("NOTEPAD", temp_key, (void *)&m_notepad, sizeof(notes), sIniFile);
            
      }
*/
      
}


ERRORS:


Compiling...
MyDigClockDlg.cpp
C:\-= My Stuff =-\-= programs =-\-= MY CLOCKS =-\MyDigClockTest\MyDigClockDlg.cpp(854) : error C2661: 'GetDlgItemTextA' : no overloaded function takes 1 parameters
C:\-= My Stuff =-\-= programs =-\-= MY CLOCKS =-\MyDigClockTest\MyDigClockDlg.cpp(867) : error C2039: 'GetLenght' : is not a member of 'CString'
        c:\-= my software =-\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'
C:\-= My Stuff =-\-= programs =-\-= MY CLOCKS =-\MyDigClockTest\MyDigClockDlg.cpp(869) : error C2039: 'GetLenght' : is not a member of 'CString'
        c:\-= my software =-\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'
Error executing cl.exe.

MyDigClock.exe - 3 error(s), 0 warning(s)






0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11926540
It's a typo replace GetLenght with GetLength
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11926617
GetDlgItemText line must be:

CString text;
GetDlgItemText(IDC_NOTEPAD, text);

0
 
LVL 1

Author Comment

by:Alien3
ID: 11926627
it does work but

I get this in .ini

[NOTEPAD]
note1=fgdfgsdfg
note2=fgdfgsdfg
note3=fgdfgsdfg
note4=fgdfgsdfg
dfsgsdfgsfdg
333333333

eeeeeeeeeeee
dfsgsdfgsfdg
333333333

eeeeeeeeeeee
dfsgsdfgsfdg
333333333

eeeeeeeeeeee
dfsgsdfgsfdg
333333333

eeeeeeeeeeee




not right !!!!


0
 
LVL 1

Author Comment

by:Alien3
ID: 11926657
anyway  I fixed this by replacing m_notepad with line.  

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11926676
Yes, there was the bug
0
 
LVL 1

Author Comment

by:Alien3
ID: 11926681
ok I have another question for you.

can you help with how can i read it ?  

      char sIniFile[MAX_PATH];
      GetModuleFileName( NULL, sIniFile, MAX_PATH );
      strcpy( strrchr( sIniFile, '\\' ) + 1, "reminderclock.ini" );

        char   getnote[MAX_PATH];

        GetPrivateProfileString("NOTEPAD", "note", "", getnote, sizeof(getnote), sIniFile);

        m_notepad = _T(getnote);

this is old code.  

this is in OnInitDialog()  


it need to read from [NOTEPAD] section with
note1=
note2=  

it should not include notexx= into textbox.    


0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11926698
CString label;
CString text;
char   getnote[MAX_PATH];

for (int i=1; ;i++) {
    label.Format("note%i",i);
    GetPrivateProfileString("NOTEPAD", label, "", getnote, sizeof(getnote), sIniFile);
    if (*getnote) {
         text += getnote;
         text += "\n\r";
    } else
         break;
}
0
 
LVL 1

Author Comment

by:Alien3
ID: 11926725
the code compiles fine but

I dont get anything in the textbox :/  


0
 
LVL 1

Author Comment

by:Alien3
ID: 11926742
nevermind

here is my code


CString label;
CString text;
char   getnote[MAX_PATH];

for (int i=1; ;i++) {
    label.Format("note%i",i);
    GetPrivateProfileString("NOTEPAD", label, "", getnote, sizeof(getnote), sIniFile);
    if (*getnote) {
         text += getnote;
         text += "\n\r";
      m_notepad = _T(text);
    } else

      break;
}




I get some blocks between the returns now.  

0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 11926750
The problem is here, try with:
         text += "\r\n";
0
 
LVL 1

Author Comment

by:Alien3
ID: 11926783
the code helps :)  

Thanks very much  
elite MFC programmer :D  



0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11926804
Thanks to you too, see you in next question.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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: 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. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

885 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