Add newline to a text field (Win32)
Posted
by user146780
on Stack Overflow
See other posts from Stack Overflow
or by user146780
Published on 2010-04-23T20:41:38Z
Indexed on
2010/04/23
21:03 UTC
Read the original article
Hit count: 440
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
© Stack Overflow or respective owner