//定位文件
void Jump2File(string strPath)
{
string cmd = "/e,/select,"+strPath;
ShellExecute(NULL,NULL,"explorer",cmd.c_str(),NULL,SW_SHOW);
}
4.BeginWaitCursor和EndWaitCursor无效
答:SetCapture();BeginWaitCursor();....EndWaitCursor();ReleaseCapture();
5.打印源码中文件名和行号常用的宏名是什么?
答:文件名:__FILE__ 行号:__LINE__
6.如何具体判断一个字符串中哪个是英文字母
答:函数isalpha
//一些帮助函数
//返回当前程序的路径
//例如c:\abc\abc.exe则返回c:\abc
BOOL GetPath(TCHAR * strPath)
{
TCHAR sDrive[_MAX_DRIVE];
TCHAR sDir[_MAX_DIR];
TCHAR sFilename[_MAX_FNAME],Filename[_MAX_FNAME];
TCHAR sExt[_MAX_EXT];
GetModuleFileName(NULL, Filename, _MAX_PATH);
_tsplitpath(Filename, sDrive, sDir, sFilename, sExt);
_tcscpy(strPath,sDrive);
_tcscat(strPath,sDir);
strPath[_tcslen(strPath)-1] = _T('\0');
return TRUE;
}
//获得父进程ID,失败则返回0
DWORD GetPPid()
{
HANDLE hProcessSnap = NULL;
PROCESSENTRY32 pe32 = {0};
DWORD dwPID = GetCurrentProcessId();
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hProcessSnap==(HANDLE)-1)
return (FALSE);
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &pe32))
{
while(pe32.th32ProcessID!=dwPID)
Process32Next(hProcessSnap, &pe32);
}
CloseHandle(hProcessSnap);
return(pe32.th32ParentProcessID);
}
//判断程序是否以服务运行
BOOL isRuninServices()
{
DWORD dwPPID = GetPPid();
HANDLE hProcessSnap = NULL;
PROCESSENTRY32 pe32 = {0};
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == (HANDLE)-1)
return (FALSE);
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &pe32))
{
while(pe32.th32ProcessID!=dwPPID)
Process32Next(hProcessSnap, &pe32);
}
CloseHandle(hProcessSnap);
if(_tcsncicmp(pe32.szExeFile,_T("services.exe"),20)==0)
return TRUE;
else return FALSE;
}
//用于在release下输出调试信息
void KDbgPrint(LPCTSTR lpszFormat, ...)
{
#define _countof(array) (sizeof(array)/sizeof(array[0]))
#ifdef KOUT_DEBUG_STRING
va_list args;
va_start(args, lpszFormat);
int nBuf;
TCHAR szBuffer[512];
nBuf = _vsntprintf(szBuffer, _countof(szBuffer), lpszFormat, args);
OutputDebugString(szBuffer);
va_end(args);
#endif
}
//从地址去获得模块基址
HMODULE WINAPI ModuleFromAddress(PVOID pv)
{
MEMORY_BASIC_INFORMATION mbi;
if(::VirtualQuery(pv, &mbi, sizeof(mbi)) != 0)
{
return (HMODULE)mbi.AllocationBase;
}
else
{
return NULL;
}
}
//获得DLL自身
BOOL GetDllPath(TCHAR * path)
{
HMODULE hDll = ModuleFromAddress(GetDllPath);
if(hDll==NULL)
return FALSE;
else
{
GetModuleFileName(hDll, path, _MAX_PATH);
return TRUE;
}
}
//格式化string
void format_string(string & str,LPCTSTR lpszFormat, ...)
{
#define _countof(array) (sizeof(array)/sizeof(array[0]))
va_list args;
va_start(args, lpszFormat);
int nBuf;
TCHAR szBuffer[1024];
nBuf = _vsntprintf(szBuffer, _countof(szBuffer), lpszFormat, args);
str = szBuffer;
va_end(args);
}
5.
isdigit:判断字符是否是数字(0 – 9)
isalpha:判断字符是否是字母(A – Z or a – z)
isxdigit:判断是否是十六进制字符(A – F, a – f, or 0 – 9)
isalnum:判断是否是数字和字母(A – Z, a – z, or 0 – 9)
6.sprintf,CString.Format中使用变量
CString str;
int i = 3;
str.Format("%0*d", i, ret);//效果一样
str.Format("%03d", ret);//效果一样