CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    22

    !! 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

  2. #2
    Join Date
    Apr 1999
    Posts
    191

    My way (right way, who knows?)



    CWnd::SetWindowText()

  3. #3
    Join Date
    Apr 1999
    Posts
    4

    Another way...



    This is my way


    CString m_file_contents


    // Read file contents into m_file_contents

    // use DDX


    UpdateData(FALSE)


    So easy



  4. #4
    Join Date
    Apr 1999
    Posts
    22

    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

    }

  5. #5
    Join Date
    Apr 1999
    Posts
    2

    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.

  6. #6
    Join Date
    Apr 1999
    Posts
    383

    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
  •  





Click Here to Expand Forum to Full Width

Featured