⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadtextfile.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
字号:
/*----------------------------------------------------------------------
Copyright (c) 1998,1999 Gipsysoft. All Rights Reserved.
Please see the file "licence.txt" for licencing details.
File:	LoadTextFile.cpp
Owner:	russf@gipsysoft.com
Purpose:	Load a text file.
----------------------------------------------------------------------*/
#include "stdafx.h"

extern bool LoadTextFile( LPCTSTR pcszFilename, LPTSTR &pszBuffer );

bool LoadTextFile( LPCTSTR pcszFilename, LPTSTR &pszBuffer, UINT &uLength )
{
	bool bRetVal = false;
	HANDLE hFile = ::CreateFile( pcszFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile != INVALID_HANDLE_VALUE )
	{
		uLength = ::GetFileSize( hFile, NULL );
		if( uLength )
		{
			LPTSTR pszFile = new char [ uLength + 1 ];
			DWORD dwRead;
			if( ::ReadFile( hFile, pszFile, uLength, &dwRead, NULL ) )
			{
				pszFile[ uLength ] = _T('\000');

#ifdef _UNICODE
				LPTSTR pszFile2 = new char [ uLength * sizeof( TCHAR ) + 1 ];
				MultiByteToWideChar(CP_ACP, 0, pszBuffer, uLength, pszFile2, uLength * sizeof( TCHAR ) );
				pszBuffer = pszFile2;
				delete pszFile;
#else	//	UNICODE
				pszBuffer = pszFile;
#endif	//	_UNICODE
				bRetVal = true;
			}
		}

		::CloseHandle( hFile );
	}
	return bRetVal;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -