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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
BOOL LoadTextFileToEdit(HWND hEdit, LPCTSTR pszFileName)
{
fstream file;
//HANDLE hFile;
BOOL bSuccess = FALSE;
file.open ("a.txt");
//hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
//OPEN_EXISTING, 0, NULL);
if (!file.is_open())
return bSuccess;
else
//if(hFile != INVALID_HANDLE_VALUE)
{
int fileSize;
//DWORD dwFileSize;
file.seekg (0, ios::end);
fileSize = file.tellg();
//dwFileSize = GetFileSize(hFile, NULL);
if(fileSize >0)
//if(dwFileSize != 0xFFFFFFFF)
{
char * allocateFile;
//LPSTR pszFileText;
allocateFile = new char [fileSize+1];
//pszFileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
//if(pszFileText != NULL)
if (allocateFile != 0)
{
DWORD dwRead;
if(ReadFile(file, allocateFile, fileSize, &dwRead, NULL))
//if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
{
allocateFile[fileSize] = 0;
//pszFileText[dwFileSize] = 0; // Add null terminator
if(SetWindowText(hEdit, allocateFile));
//if(SetWindowText(hEdit, pszFileText))
bSuccess = TRUE; // It worked!
}
delete [] allocateFile;
//GlobalFree(pszFileText);
}
}
file.close();
//CloseHandle(hFile);
}
return bSuccess;
}
|