📄 usefulfun.h
字号:
//----------------------------------------------------------------------------------------------------------
//本头文件作为各种VC工程所用,实现了GV最常用的函数
//-----------------------------------------------------------------------------------------------------------
#include <windows.h>
#include <atlbase.h>
#include <sstream>
#include <string>
using namespace std;
//=====================================================================
// 语法格式: CString GetAppDir()
// 实现功能: 取得本程序的文件夹路径
// 参数: 无
// 返回值: CString 类型
//=====================================================================
CString GetAppDir()
{
CString appDir;
GetModuleFileName(NULL, appDir.GetBuffer(MAX_PATH), MAX_PATH);
//注:使用该API函数得到的是程序文件完整路径文件名,去掉文件名后才是路径。
appDir.ReleaseBuffer();
int n = appDir.ReverseFind('\\');
appDir = appDir.Left(n);
TCHAR c = appDir.GetAt(n-1);
if(c != '\\') appDir+= "\\";
return appDir;
}
//---------------------------------------------------------------------------------------------------
string Int2Str(int i)
{
ostringstream os;
os << i;
return os.str();
};
int Str2Int(string str)
{
return atoi(str.c_str());
}
//=====================================================================
// 语法格式: string ws2s(wstring& inputws)
// 实现功能: wstring 转为 string
// 参数: wstring& inputws
// 返回值: string 类型
//=====================================================================
string ws2s(wstring& inputws)
{
LPCWSTR pwszSrc=inputws.c_str();
int nLen = WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, NULL, 0, NULL, NULL);
if (nLen<= 0) return std::string("");
char* pszDst = new char[nLen];
if (NULL == pszDst) return std::string("");
WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszDst, nLen, NULL, NULL);
pszDst[nLen -1] = 0;
std::string strTemp(pszDst);
delete [] pszDst;
return strTemp;
}
//=====================================================================
// 语法格式: wstring s2ws(const string& s)
// 实现功能: string 转 wstring
// 参数: string& s
// 返回值: wstring
//=====================================================================
std::wstring s2ws(const string& s)
{
LPCSTR pszSrc=s.c_str();
int nLen=s.size();
int nSize = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszSrc, nLen, 0, 0);
if(nSize <= 0) return NULL;
WCHAR *pwszDst = new WCHAR[nSize+1];
if( NULL == pwszDst) return NULL;
MultiByteToWideChar(CP_ACP, 0,(LPCSTR)pszSrc, nLen, pwszDst, nSize);
pwszDst[nSize] = 0;
if( pwszDst[0] == 0xFEFF) // skip Oxfeff
for(int i = 0; i < nSize; i ++)
pwszDst[i] = pwszDst[i+1];
wstring wcharString(pwszDst);
delete pwszDst;
return wcharString;
};
void replace(string & strBig, const string & strsrc, const string &strdst) {
string::size_type pos=0;
string::size_type srclen=strsrc.size();
string::size_type dstlen=strdst.size();
while( (pos=strBig.find(strsrc, pos)) != string::npos){
strBig.erase(pos, srclen);
strBig.insert(pos, strdst);
pos += dstlen;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -