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
|
BOOL LoadTextFile(HWND hCtrl, LPCTSTR szFileName){
HANDLE hFile;
BOOL Success=FALSE;
hFile=CreateFile(szFileName,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 FileText;
FileText =(LPSTR)GlobalAlloc(GPTR, dwFileSize+1);
if(FileText != NULL){
DWORD dwRead;
if(ReadFile(hFile, FileText,dwFileSize,&dwRead,NULL)){
FileText[dwFileSize]=0;
if(SetWindowText(hCtrl,FileText))
Success=TRUE;
}
GlobalFree(FileText);
}
}
CloseHandle(hFile);
}
return Success;
}
|