Edit control displaying a txt file

I am using a edit control to display a text file using c++ file functions. The text does not use the new line characters and i don't think it is using the tab characters. However, if i use windows functions to display the text it does use the characters. The window version looks just like the text file looks in notepad. What do i need to do to get the c++ version to keep the format looking like it does in the windows version?

Here is the c++ version:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void ReadOneLine(HWND hEdit, LPCSTR FileName) {
	char *lineIn;
	int length;

	std::ifstream theFile(FileName);

	if (theFile.good()) {
	// get length of file:
	theFile.seekg (0, std::ios::end);
	length = theFile.tellg();
	theFile.seekg (0, std::ios::beg);

	// allocate memory:
	lineIn = new char [length];
		theFile.read(lineIn,length);
		SetWindowText(hEdit,(LPCSTR)lineIn);
		theFile.close();
	}
	else MessageBox(NULL,"Can't read the file","",MB_OK);
} //end ReadOneLine 


Here is the Window version:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
BOOL LoadTextFileToEdit(HWND hEdit, LPCTSTR pszFileName)
{
	HANDLE hFile;
	BOOL bSuccess = FALSE;

	hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
		OPEN_EXISTING, 0, NULL);
	if(hFile != INVALID_HANDLE_VALUE)
	{
		DWORD dwFileSize;

		dwFileSize = GetFileSize(hFile, NULL);
		if(dwFileSize != 0xFFFFFFFF)
		{
			LPSTR pszFileText;

			pszFileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
			if(pszFileText != NULL)
			{
				DWORD dwRead;

				if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
				{
					pszFileText[dwFileSize] = 0; // Add null terminator
					if(SetWindowText(hEdit, pszFileText))
						bSuccess = TRUE; // It worked!
				}
				GlobalFree(pszFileText);
			}
		}
		CloseHandle(hFile);
	}
	return bSuccess;
}

Topic archived. No new replies allowed.