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

📄 mylog.cpp

📁 SQLBig5BugTool 宽字符操作问题
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	strFolder="";
	
	BOOL bOK=FALSE;
	
	BROWSEINFO   bi={0,};
	
	bi.lpszTitle=pszTitle;
	
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x40
#endif
	
	bi.hwndOwner   =hWnd; 
	bi.pidlRoot   =   NULL;   
	bi.ulFlags   =   BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS|BIF_DONTGOBELOWDOMAIN|BIF_NEWDIALOGSTYLE;   
	bi.lpfn=BrowseCallbackProc;
	
	LPITEMIDLIST     pidlRoot   =   NULL;   
	
	if(pszRootRestrict&&((*pszRootRestrict)!=0))
	{
		IShellFolder*	 pDesktopFolder=0;    
		OLECHAR          olePath[MAX_PATH]={0,};         
		ULONG            chEaten=0;   
		ULONG            dwAttributes=0;   
		
		if   (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))   
		{   
			MultiByteToWideChar(CP_ACP,   MB_PRECOMPOSED,   strFolder.c_str(),   -1,   olePath,   MAX_PATH);   
			pDesktopFolder->ParseDisplayName(NULL,   NULL,   olePath,   &chEaten,   &pidlRoot,   &dwAttributes);   
			pDesktopFolder->Release();   
		}   
	}
	
	bi.lParam=(LPARAM)strInitFolder.c_str();
	
	bi.pidlRoot   =   pidlRoot;   
	
	
	LPITEMIDLIST lpidl= SHBrowseForFolder(&bi); 
	if(lpidl)
	{
		char szPath[1024]={0,};
		
		SHGetPathFromIDList(lpidl, szPath); 
		
		strFolder=szPath;
		
		bOK=TRUE;
	}	
	
	IMalloc * pMalloc = NULL;
	if ( SUCCEEDED ( ::SHGetMalloc( &pMalloc ) ) )  // 取得IMalloc分配器接口
	{
		if(lpidl)
		{
			pMalloc->Free( lpidl );    // 释放内存
			lpidl=0;
		}
		if(pidlRoot)
		{
			pMalloc->Free( pidlRoot );    // 释放内存
			pidlRoot=0;
		}
		
		pMalloc->Release();       // 释放接口
		pMalloc=0;
	}	  
	return bOK;
}

void	ParseStringEx(
					  const std::string	strStr,
					  const std::string	strBeginToken,
					  const std::string	strEndToken,
					  STRING_LIST&		StrList,
					  const bool		bAutoLeftTrim ,
					  const bool		bAutoRightTrim  ,
					  const bool		bSkipEmpty 
					  )
{
	StrList.clear();
	
	if(strlen(strStr.c_str())<=0)
	{
		return ;
	}
	if(strBeginToken.empty())
	{
		assert(false);
		return;
	}
	if(strEndToken.empty())
	{
		assert(false);
		return;
	}
	
	
	int iPosBegin=-1;
	int iPosEnd=-1;
	
	std::string strTxt=strStr;
	
	while(!strTxt.empty())
	{
		iPosBegin=strTxt.find(strBeginToken);
		if(iPosBegin<0)
		{
			return;
		}
		strTxt=strTxt.substr(iPosBegin+strBeginToken.size(),strTxt.size());
		if(strTxt.empty())
		{
			return;
		}
		
		iPosEnd=strTxt.find(strEndToken);
		if(iPosEnd<0)
		{
			return;
		}
		
		std::string strVal=strTxt.substr(0,iPosEnd);
		if(bAutoLeftTrim)
		{
			StringTrimLeft(strVal);
		}		
		if(bAutoRightTrim)
		{
			StringTrimRight(strVal);
		}
		if(bSkipEmpty&&(strVal.empty()))
		{
		}
		else
		{
			StrList.push_back(strVal);
		}
	}
	
}

void StringListToString(
						STRING_LIST&		StrList,
						std::string&		str,
						const char*			pszToken
						)
{
	str="";
	for(STRING_LIST::iterator itr=StrList.begin();itr!=StrList.end();itr++)
	{
		if(!str.empty())
		{
			str+=pszToken;
		}
		str+=(*itr);
	}
}

BOOL	ParseString(
					const std::string	strStr,
					const std::string	strTokenString,
					STRING_LIST&		StrList,
					const bool			bAutoLeftTrim ,
					const bool			bAutoRightTrim  ,
					const bool			bSkipEmpty ,
					const bool			bEliminateMultipleToken,
					const bool			bAutoClearList,
					const bool			bNoDuplicate,
					const bool			bFailedIfDuplicated,
					const PARSE_STRING_CASE_CAST	psccAutoCastCase
					)
{
	if(bAutoClearList)
	{
		StrList.clear();
	}
	
	if(strlen(strStr.c_str())<=0)
	{
		return TRUE;
	}
	
	int iPos=-1;
	
	std::string strTxt=strStr;
	
	switch(psccAutoCastCase)
	{
	case psccAutoCastNone:
		{
		}
		break;
	case psccAutoCastUpper:
		{
			strupr((char*)strTxt.c_str());
		}
		break;
	case psccAutoCastLower:
		{
			strlwr((char*)strTxt.c_str());
		}
		break;
	default:
		{
			assert(false);
			return FALSE;
		}
		break;
	}
	if(strTokenString.empty())
	{
		if(bSkipEmpty)
		{
			if(strTxt.empty())
			{
				return TRUE;
			}
		}
		StrList.push_back(strTxt);
		return TRUE;
	}
	strTxt += strTokenString;
	
	if(bEliminateMultipleToken)
	{
		std::string strDoubleTokenString=strTokenString+strTokenString;		
		
		for(iPos=strTxt.find(strDoubleTokenString);iPos>=0;iPos=strTxt.find(strDoubleTokenString))
		{
			if(iPos>0)
			{
				strTxt=strTxt.substr(0,iPos-1)+strTxt.substr(iPos+strlen(strDoubleTokenString.c_str()),-1);
			}
			else
			{
				strTxt=strTxt.substr(iPos+strlen(strDoubleTokenString.c_str()));
			}			
		};
	}	
	
	int iCurPos=0;
	
	int iLenOfTokenString=strlen(strTokenString.c_str());
	iPos=-1;
	for(iPos=strTxt.find(strTokenString,iCurPos);
	iPos>=0;
	iPos=strTxt.find(strTokenString,iCurPos)
		)
	{
		std::string strTxtTemp=strTxt.substr(iCurPos,iPos-iCurPos);
		
		if(bAutoLeftTrim)
		{
			StringTrimLeft(strTxtTemp);
		}
		
		if(bAutoRightTrim)
		{
			StringTrimRight(strTxtTemp);
		}
		
		if(bNoDuplicate)
		{
			if(StrList.end()!=std::find(StrList.begin(),StrList.end(),strTxtTemp.c_str()))
			{
				if(bFailedIfDuplicated)
				{
					return FALSE;
				}
				else
				{
					iCurPos=iPos+iLenOfTokenString;
					continue;
				}
			}
		}
		
		if(bSkipEmpty&&(strTxtTemp.empty()))
		{
		}
		else
		{
			StrList.push_back(strTxtTemp);
		}
		
		iCurPos=iPos+iLenOfTokenString;
	};
	return TRUE;
}


void StringTrimLeft(std::string& strTxt) 
{
	if(strTxt.size()<=0)
	{
		return ;
	}
	int iFirstNotSpace=0;
	
	while((' ' == strTxt[iFirstNotSpace])
		||('\t' == strTxt[iFirstNotSpace])
		||('\n' == strTxt[iFirstNotSpace])
		||('\r' == strTxt[iFirstNotSpace])
		)
	{
		iFirstNotSpace ++;
		if(iFirstNotSpace>(strTxt.size()-1))
		{
			strTxt="";
			return ;
		}			
	}
	
	if(0==iFirstNotSpace)
	{
		return ;
	}
	
	strTxt=strTxt.substr(iFirstNotSpace,strTxt.size()-iFirstNotSpace);
}

void StringTrimRight(std::string& strTxt) 
{
	if(strTxt.size()<=0)
	{
		return ;
	}
	int iFirstNotSpaceFromLast=strTxt.size()-1;
	
	while((' ' == strTxt[iFirstNotSpaceFromLast])
		||('\t' == strTxt[iFirstNotSpaceFromLast])
		||('\n' == strTxt[iFirstNotSpaceFromLast])
		||('\r' == strTxt[iFirstNotSpaceFromLast])
		)
	{
		iFirstNotSpaceFromLast --;	
		if(iFirstNotSpaceFromLast<0)
		{
			strTxt="";
			return ;
		}		
	}
	
	if((strTxt.size()-1)==iFirstNotSpaceFromLast)
	{
		return ;
	}
	
	strTxt=strTxt.substr(0,iFirstNotSpaceFromLast+1);
}


BOOL GetSubString(
				  const char* pszString,
				  const char* pszStrBeginWith,
				  const char* pszStrEndWith,
				  std::string& strSubString,
				  const BOOL  bEndWithOptional
				  )
{
	if(!pszStrBeginWith)
	{
		return FALSE;
	}
	strSubString="";
	char* pszTokenBegin=strstr(pszString,pszStrBeginWith);
	if(!pszTokenBegin)
	{
		return FALSE;
	}
	if(pszStrEndWith)
	{
		char* pszTokenEnd=strstr(pszTokenBegin+strlen(pszStrBeginWith),pszStrEndWith);
		if(pszTokenEnd)
		{
			strSubString=pszTokenBegin+strlen(pszStrBeginWith);
			
			strSubString=strSubString.substr(0,pszTokenEnd-pszTokenBegin-strlen(pszStrBeginWith));
			return TRUE;
		}
		else
		{
			if(bEndWithOptional)
			{
				strSubString=pszTokenBegin+strlen(pszStrBeginWith);
				return TRUE;
			}
			else
			{
				return FALSE;
			}
		}
	}
	else
	{
		strSubString=pszTokenBegin+strlen(pszStrBeginWith);
		return TRUE;
	}
}

const char*const GetExeDir()
{
	static char szExeDir[1024]={0,};
	if(szExeDir[0]==0)
	{
		::GetModuleFileName(0,szExeDir,sizeof(szExeDir));
		char* pchToken=strrchr(szExeDir,'\\');
		if(pchToken)
		{
			*(pchToken+1)=0;
		}
	}
	return szExeDir;	
}


BOOL CopyTextToClipboardW(
						  const HWND  hWnd,
						  const char *pszTxt
						  )
{
	//put your text in source 
	if(OpenClipboard(hWnd)) 
	{ 
		HGLOBAL clipbuffer=0; 
		WCHAR * buffer=0; 
		::EmptyClipboard(); 
		
		WCHAR    wcsTxt[16*1024] = {0,};
		
		if(0==::MultiByteToWideChar(
			CP_ACP,
			0,
			pszTxt,
			-1,
			wcsTxt,
			sizeof(wcsTxt)
			))
		{			
			TraceOut("failed to MultiByteToWideChar in CopyTextToClipboardW.lasterror:%d",::GetLastError());
		}
		
		long lLen=wcslen(wcsTxt);
		clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, 2*(lLen+1)); 
		buffer = (WCHAR*)::GlobalLock(clipbuffer); 
		
		wcscpy(buffer,wcsTxt);
		
		::GlobalUnlock(clipbuffer); 
		
		SetClipboardData(CF_UNICODETEXT,clipbuffer); 
		
		CloseClipboard(); 
	} 
	else
	{
		return FALSE;
	}
	return TRUE;
}

BOOL CopyTextToClipboardA(
						  const HWND  hWnd,
						  const char *pszTxt
						  )
{
	if(!OpenClipboard(hWnd)) 
	{
		return FALSE;
	}
	HGLOBAL clipbuffer=0; 
	char * buffer=0; 
	::EmptyClipboard(); 
	clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, strlen(pszTxt)+1); 
	buffer = (char*)::GlobalLock(clipbuffer); 
	
	strcpy(buffer, pszTxt); 
	
	::GlobalUnlock(clipbuffer); 
	
	SetClipboardData(CF_TEXT,clipbuffer); 
	
	CloseClipboard(); 
	
	return TRUE;
}

BOOL CopyTextToClipboard(
						 const HWND  hWnd,
						 const char *pszTxt,
						 const BOOL  bUniCode
						 )
{
	if(!OpenClipboard(hWnd)) 
	{
		return FALSE;
	}
	if(bUniCode)
	{
		return CopyTextToClipboardW(hWnd,pszTxt);
	}
	else
	{
		return CopyTextToClipboardA(hWnd,pszTxt);
	}
}


void GetVersionInfo(
					const char*			pszFilePath,
					FILE_VERSION_INFO&	FileVersionInfo
					)
{
	FileVersionInfo.strFileVersion="";
	
	DWORD dwFileVersionInfoSize=GetFileVersionInfoSize(
		(char*)pszFilePath,
		0
		);
	
	char pBlock[16*1024]={0,};
	
	if(dwFileVersionInfoSize>sizeof(pBlock))
	{
		assert(false);
		return;
	}
	if(!GetFileVersionInfo(
		(char*)pszFilePath,
		0,
		sizeof(pBlock),
		(LPVOID)pBlock
		))
	{
		assert(false);
		return ;
	};
	
	VS_FIXEDFILEINFO* pVSFixedFileInfo=0;
	
	// Read the list of languages and code pages.
	UINT uiLen=0;
	
	VerQueryValue(
		pBlock, 
		TEXT("\\"),
		(LPVOID*)&pVSFixedFileInfo,
		&uiLen
		);
	
	FileVersionInfo.strFileVersion=FormatString(
		"%x.%x",
		pVSFixedFileInfo->dwFileVersionMS>>16,
		pVSFixedFileInfo->dwFileVersionLS
		);
}




long ActivateWnd(
				 const HWND hWnd
				 )
{
	DWORD dwCurrentThreadID = GetCurrentThreadId(); 
	DWORD dwWndThreadID = ::GetWindowThreadProcessId(hWnd, NULL); 
	if(dwCurrentThreadID!=dwWndThreadID)
	{
		AttachThreadInput(dwWndThreadID, dwCurrentThreadID, true);
	}
	
	::BringWindowToTop(hWnd);
	
	::SetForegroundWindow(hWnd);
	
	::SetActiveWindow(hWnd);
	
	::SetFocus(hWnd);
	
	if(dwCurrentThreadID!=dwWndThreadID)
	{
		AttachThreadInput(dwWndThreadID, dwCurrentThreadID, false);
	}
	::Sleep(1000);
	
	return 0;
}

BOOL MyDeleteFile(const char *pszFilePath,const BOOL bEnableUndo)
{
	SetFileAttributes(pszFilePath,FILE_ATTRIBUTE_NORMAL);
	
	if(bEnableUndo)
	{
		SHFILEOPSTRUCT   fo={0,};     
		fo.wFunc   =   FO_DELETE   ;   
		fo.pFrom   =   pszFilePath;   
		fo.fFlags   =   FOF_ALLOWUNDO  ;
		int iRet=SHFileOperation(&fo); 
		
		return 0==iRet;
	}
	else
	{
		return DeleteFile(pszFilePath);
	}
} 


void GetLastErrorMsg(
					 std::string& strLastErrorMsg,
					 const DWORD dwLastError
					 )
{
	strLastErrorMsg="";

	LPVOID lpMsgBuf=0;
	
	FormatMessage( 
		FORMAT_MESSAGE_ALLOCATE_BUFFER | 
		FORMAT_MESSAGE_FROM_SYSTEM | 
		FORMAT_MESSAGE_IGNORE_INSERTS,
		NULL,
		dwLastError,
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
		(LPTSTR) &lpMsgBuf,
		0,
		NULL 
		);

	if(lpMsgBuf)
	{
		strLastErrorMsg=(char*)lpMsgBuf;

		LocalFree( lpMsgBuf );
	}
}

BOOL IsNumber(const char *psz)
{	
	if(!psz)
	{
		return FALSE;
	}
	std::string strTxt=psz;
	StringTrimLeft(strTxt);
	StringTrimRight(strTxt);
	
	long lLen=strlen(" ");
	
	//去掉中文的空格
	while(strTxt.size()>lLen)
	{
		if(strTxt.substr(strTxt.size()-lLen)==" ")
		{
			strTxt=strTxt.substr(0,strTxt.size()-lLen);
		}
		else
		{
			break;
		}
	}
	if(strTxt.empty())
	{
		return FALSE;
	}
	if(strTxt[0]=='-')
	{
		strTxt=strTxt.substr(1,strTxt.size());
		//strTxt=strTxt.Mid(1);
		
		StringTrimLeft(strTxt);
		StringTrimRight(strTxt);
	}
	if(strTxt.empty())
	{
		return FALSE;
	}	

	lLen=strTxt.size();
	for(long l=0;l<lLen;l++)
	{
		if(!isdigit(strTxt[l]))
		{
			return FALSE;
		}
	}
	return TRUE;
}


BOOL GetSubFolderList(
					  const char*	pszFolderBase,
					  const char*	pszFolder,
					  STRING_LIST&	SubFolderList,
					  const LONG	lLevel
					  )
{
	if(lLevel<1)
	{
		return FALSE;
	}
	WIN32_FIND_DATA FindFileData={0,};
	
	HANDLE hFind=0;
	
	std::string strFolder=FormatString("%s\\*.*",pszFolder);

	hFind = FindFirstFile(strFolder.c_str(), &FindFileData);
	
	if (hFind == INVALID_HANDLE_VALUE)
	{
		return FALSE;
	} 
	else 
	{
		const ULONG ulLengthFolderBase=strlen(pszFolderBase);
		
		while(::FindNextFile(hFind, &FindFileData))
		{
			if(FILE_ATTRIBUTE_DIRECTORY&FindFileData.dwFileAttributes)
			{
				if (FindFileData.cFileName[0] == '.')
				{
					if (FindFileData.cFileName[1] == '\0' ||
						(FindFileData.cFileName[1] == '.' &&
						FindFileData.cFileName[2] == '\0'))
					{
						continue;
					}
				}

				std::string strSubFolder=FormatString("%s\\%s",pszFolder,FindFileData.cFileName);

				SubFolderList.push_back(strSubFolder.substr(ulLengthFolderBase+1,strSubFolder.size()));
				
				if(lLevel>1)
				{
					if(!GetSubFolderList(
						pszFolderBase,
						strSubFolder.c_str(),
						SubFolderList,
						lLevel-1
						))
					{
						return FALSE;
					};
				}
			}
		}
		FindClose(hFind);
	}

	return TRUE;
}

⌨️ 快捷键说明

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