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

📄 toolkit.cpp

📁 上传的是有关mfc的详细介绍
💻 CPP
字号:
// ToolKit.cpp: implementation of the ToolKit class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ToolKit.h"

#include "LogFile.h"

#include "SystemConfig.h"

#include "ItemKey.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

ToolKit::ToolKit()
{

}

ToolKit::~ToolKit()
{

}

// 取得应用程序的路径
void ToolKit::GetAppPath(CString &strAppPath)
{
	GetModuleFileName(NULL, strAppPath.GetBuffer(MAX_PATH), MAX_PATH);
	strAppPath.ReleaseBuffer();
		
	int nLength = 0;	
	char ch = NULL;
	ch = '\\';	
	nLength = strAppPath.GetLength();
	strAppPath = strAppPath.Left(nLength - 1);
	nLength = strAppPath.ReverseFind(ch);
	strAppPath = strAppPath.Left(nLength + 1);
	ch = '\\';	
	nLength = strAppPath.GetLength();
	strAppPath = strAppPath.Left(nLength - 1);
	nLength = strAppPath.ReverseFind(ch);
	strAppPath = strAppPath.Left(nLength + 1);
}

// 取得相对路径的绝对路径
CString ToolKit::GetAbsPath(CString strComPath)
{
	CString strAppPath;
	ToolKit::GetAppPath(strAppPath);

	CString strAbsPath;
	strAbsPath.Format("%s%s", strAppPath, strComPath);
	return strAbsPath;
}

void ToolKit::ShowMessageBox(char *chText)
{
	AfxMessageBox(chText);
}

void ToolKit::TrimForCharArray(char *chResource)
{	
	char *pchSeparator = NULL;
	pchSeparator = strstr(chResource, "");
	int nCharCountName = pchSeparator - chResource;
	if (nCharCountName > 0)
	{
		*(chResource + nCharCountName) = '\0'; 
	}
}

CString ToolKit::ToCString(int nValue)
{
	CString strText;
	strText.Format("%d", nValue);
	return strText;

}


int ToolKit::ToInt(char *chValue)
{
	int nValue;
	sscanf(chValue, ("%d"), &nValue);
	return nValue;
}

int ToolKit::GetCharCount(char *chText, char chart)
{
	int count = 0;
	int length = strlen(chText);
	for (int i = 0; i < length; i++)
	{
		if (chart == chText[i])
		{
			count++;
		}
	}

	return count;
}

void ToolKit::ExitSystem()
{

	delete CLogFile::GetLog();	
	delete SystemConfig::GetConfig();
	exit(0);	
}

void ToolKit::OnShowWnd(HWND hWnd)
{
	ShowWindow(hWnd, SW_SHOW);

	// 如果没有刷新的界面则不用绘制背景
	InvalidateRect(hWnd, NULL, false);
}

CString ToolKit::GetDefaultFileName()
{
	SYSTEMTIME st;
	GetLocalTime(&st);
	CString strFile = "";
	strFile.Format("SN%04d-%02d-%02d_%02d-%02d-%02d.txt",
					st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
	return strFile;
}

CString ToolKit::GetTrackFileName()
{
	CString strName;
	CString strExe ;
	strExe.Format("%s",	ItemKey::EXTEND_TRACK);
	strExe.Remove('*');
		
	//默认以时间作为名称
	SYSTEMTIME st;
	::GetLocalTime(&st);
	strName.Format("Track%04d-%02d-%02d_%02d-%02d-%02d%s",
					st.wYear, st.wMonth, st.wDay, st.wHour, 
					st.wMinute, st.wSecond, strExe);

	// 设置航迹文件路径
	return ToolKit::GetAbsPath(ItemKey::TRACK_FOLDER + strName);
}


//获得的系统时间
//UGString SNWndProc::GetTime( HWND hParent, DWORD dwID )
CString ToolKit::GetTime()
{
	
	CString strTime;
	DWORD dwHour = 0;
	
	SYSTEMTIME SystemTime; 
	GetSystemTime( &SystemTime); 
	dwHour = SystemTime.wHour;
	//00:00:00 -- 07:59:59
	if (dwHour >= 17 )
	{
		dwHour -= 16;
	}
	//08:00:00 -- 23:59:59
	else 
	{
		dwHour += 8;
	}
	
	if ( dwHour )
	{
		strTime.Format( ("%02d:%02d"),dwHour,SystemTime.wMinute);
	}
	else
	{
		strTime = "";
	}
	
	return strTime;
}

⌨️ 快捷键说明

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