I am following the Forger Win API tutorial to load text files into an edit control. Sometimes the whole file loads correctly, and sometimes the last part is missing, where the "part" is in one case 2 and half lines and another 10 lines o_O. Here's what the files look like:
(I am a new user, therefore I do not allow me to post more than one hyperlink, therefore there is a gallery where there are screenshots: http://nancy.imgur.com/all/ and I mean the order in which they appear in the gallery)
2.5 lines left: second (reading stops at the cursor after "F")
10 lines left: fourth (also stops at the cursor after f)
Read more: first and third
I tried using fstreams instead, and the same stuff was left behind (I also could not get new line characters to be displayed in the edit = () control. Any idea what might be wrong?
I could not reference the Forger tutorial, so here's the function:
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 = GlobalAlloc(GPTR, dwFileSize + 1);
if(pszFileText != NULL)
{
DWORD dwRead;
if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
{
pszFileText[dwFileSize] = 0;
if(SetWindowText(hEdit, pszFileText))
bSuccess = TRUE;
}
GlobalFree(pszFileText);
}
}
CloseHandle(hFile);
}
return bSuccess; }
Nancy source
share