tags:

views:

84

answers:

1

I'm making a Notepad clone. Right now my text loads fine but where their are newline characters, they do not make newlines in the text field.

I load it like this:

void LoadText(HWND ctrl,HWND parent)
{

    int leng;
    char buf[330000];

    char FileBuffer[500];
    memset(FileBuffer,0,500);

    FileBuffer[0] = '*';
    FileBuffer[1] = '.';
    FileBuffer[2] = 't';
    FileBuffer[3] = 'x';
    FileBuffer[4] = 't';

    OPENFILENAMEA ofn;
    memset(&ofn, 0, sizeof(OPENFILENAMEA));
    ofn.lStructSize = sizeof(OPENFILENAMEA);
    ofn.hwndOwner = parent;
    ofn.lpstrFile = FileBuffer;
    ofn.nMaxFile = 500;
    ofn.lpstrFilter = "Filetype (*.txt)\0\0";
    ofn.lpstrDefExt = "txt";
    ofn.Flags = OFN_EXPLORER;

    if(!GetOpenFileNameA(&ofn))
    {
        return;
    }
    ifstream *file;
    file = new ifstream(FileBuffer,ios::in);

    int lenn;
    lenn = 0;

    while (!file->eof())
    {

        buf[lenn] = file->get();
        lenn += 1;

    }
    buf[lenn - 1] = 0;

    file->read(buf,lenn);
    SetWindowTextA(ctrl,buf);
    file->close();
}

How can I make it do the new line characters?

Thanks

(Fixed it, turns out the stream was not giving me CR's so I had to insert them.

+3  A: 

Ensure that you have ES_MULTILINE|ES_WANTRETURN set.

Multiline edit controls use "soft line break characters" to force it to wrap. To indicate a "soft line break", use CRCRLF (source). So I guess you need to replace all your CRLF's (or whatever eol character your file uses) with CRCRLF. You're already reading your file in character by character, so you can just insert an extra CR into the buffer.

As a side note, you'll eventually want to do the file IO on a separate thread (i.e. not the UI thread) so that you don't hang the UI while you're reading the file. It'd be nice if the UI showed some sort of loading animation, or progress bar.

jeffamaphone
Yes I have both of these but still no luck. It makes newline if I press enter, but my load does not seem to load them.... *edit ill try what you said about crcrlf
Milo
@user146780: see my updated edits.
jeffamaphone