global.cpp

来自「中国电信文字短信收发程序。采用电信提供的接口动态库。」· C++ 代码 · 共 72 行

CPP
72
字号
#include "stdafx.h"
#include "DataStruct.h"

TGlobalVar GlobalVar;
/////////////////////////////////////////////////
//Below is Global function
bool IsFileExists(CString FileName)
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;
	hFind = FindFirstFile(FileName, &FindFileData);
	if (hFind == INVALID_HANDLE_VALUE) return false;
	FindClose(hFind);
	return true;	
}
void WriteLogFile(CString str)
{
	FILE *stream;
	char *strLog ;
	char Segmentation[] = "====================================================================" ;
	char c = '\n';
	int strLen = str.GetLength();
	strLog = str.GetBuffer(0) ;
	if ( (stream = fopen(GlobalVar.FilePath.AppLogFile,"a" )) != NULL )
	{
		COleDateTime CurrentTime;
		CurrentTime = COleDateTime::GetCurrentTime();
		CString strFormat = _T("");
		strFormat = CurrentTime.Format(_T("%H,%M,%S,%A, %B %d, %Y"));
		fprintf( stream,"%s%c",Segmentation,c);
		fprintf( stream,"%s%c" ,strFormat,c);
		fprintf( stream, "%s%c", strLog, c );
		fclose( stream );
	}
}
CString ReadIni(CString SectionName, CString VarName)
{
	CString strReturn = _T("");
	GetPrivateProfileString(SectionName,VarName,"",strReturn.GetBuffer(255),255,GlobalVar.FilePath.IniFile);
	return strReturn ;
}
bool IsIniLogExists()
{
	char Temp[255];
	CString strPath = _T("");
	CString File = _T("");

	VERIFY(::GetModuleFileName(AfxGetInstanceHandle(),Temp, _MAX_PATH));
	strPath.Format("%s",Temp);
	strPath = strPath.Left(strPath.ReverseFind('\\')+1);

	//给全局变量赋值
	GlobalVar.FilePath.AppPath=strPath;

	File=strPath+"SysIni.ini";
	GlobalVar.FilePath.IniFile=File;//保存全局的配置文件名字
	if (!IsFileExists(File))
	{
		AfxMessageBox("配置文件不存在,请仔细检查!");
		return false;
	}
	
	File = strPath+"App.log";
	GlobalVar.FilePath.AppLogFile=File;//保存全局的日志文件名字
	if (!IsFileExists(File))
	{
		AfxMessageBox("日志文件不存在,请仔细检查!");
		return false;
	}
	return true;
}

⌨️ 快捷键说明

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