Click to See Complete Forum and Search --> : !! Putting text file contents into a CEdit !!


Chris Meyer
March 31st, 1999, 04:07 PM
Hi everyone,


I'd like to put a text file into my application as a resource and then print the contents of it into a CEdit control in my about box. lots of apps do this (Winamp, for example) but I'm not sure how. Can anyone shed some light on The Right Way?


Thanks as always,

Chris

Bore
March 31st, 1999, 06:41 PM
CWnd::SetWindowText()

Hopless
March 31st, 1999, 10:22 PM
This is my way


CString m_file_contents


// Read file contents into m_file_contents

// use DDX


UpdateData(FALSE)


So easy

Chris Meyer
March 31st, 1999, 10:46 PM
Yeah I know this, but it doesn't seem to want to read the data. Right now I have a custom resource type "TEXT" that

just stores the test byte for byte. I've tried setting the control text and DDX but neither work. The control is just

blank. The reason I used the TEXT thing is because I opened winamp.exe to see how Justing Frankel did it and he had

his text in a custom resource. Would you recommend reading directly from the file? If so, how do I get the whole

thing into a CString? Here's what I have at the moment...

Thanks a bunch for your help.

BOOL CHelpDlg::OnInitDialog()

{

CDialog::OnInitDialog();

m_instructions.LoadString( _T(IDR_INSTRUCTIONS) );

UpdateData(false);

return TRUE; // return TRUE unless you set the focus to a control

// EXCEPTION: OCX Property Pages should return FALSE

}

poulin jean Michel
April 1st, 1999, 01:10 AM
if you use MFC a simple syntaxe is GetDlgItemText or SetDlgItemText.

use GetGlgItemText(HWND hwnd,LPSTR lpTitre, int nMax) to read a value;

ie:

char buf[10];

memset(&buf,0,sizeof(buf));

sprintf(buf,"coucou");

GetDlgItemText(IDC_EDIT1, buf,sizeof(buf));

use the same syntax with SetDlgItemText to put a value in the CEDIT.


best regards.

Dave Lorde
April 1st, 1999, 05:25 AM
What about something like this:

BOOL CHelpDlg::OnInitDialog()

{

CStdioFile textFile;

if (!textFile.Open("C:\\instructions.txt", CFile::modeRead))

{

#ifdef _DEBUG

afxDump << "File could not be opened\n";

#endif

return 1;

}

CString textLine;

while (textFile.ReadString( textLine ))

m_Instructions += (textLine + '\n');

UpdateData(false);

return TRUE; // return TRUE unless you set the focus to a control

}


Dave