|
-
March 31st, 1999, 05:07 PM
#1
!! Putting text file contents into a CEdit !!
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
-
March 31st, 1999, 07:41 PM
#2
My way (right way, who knows?)
-
March 31st, 1999, 11:22 PM
#3
Another way...
This is my way
CString m_file_contents
// Read file contents into m_file_contents
// use DDX
UpdateData(FALSE)
So easy
-
March 31st, 1999, 11:46 PM
#4
Re: Another way...
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
}
-
April 1st, 1999, 02:10 AM
#5
Re: !! Putting text file contents into a CEdit !!
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.
-
April 1st, 1999, 06:25 AM
#6
Re: Another way...
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|