?? publicfunction.h
字號:
// PublicFunction.h: interface for the CPublicFunction class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_PUBLICFUNCTION_H__654F176C_F11F_4843_AEA0_F53676D52341__INCLUDED_)
#define AFX_PUBLICFUNCTION_H__654F176C_F11F_4843_AEA0_F53676D52341__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// 日志級別
#define L_VERBOSE 0x00000000 // 詳細,一般是調試信息
#define L_NORMAL 0x00000001 // 正常,程序運行時顯示的一般信息,紀錄運行過程
#define L_WARNING 0x00000002 // 警告,程序運行有錯誤,但不是致命錯誤,程序仍然可以繼續運行下去
#define L_ERROR 0x00000003 // 錯誤,程序運行出現了嚴重錯誤,程序必須立即終止執行
#define L_DEBUG 0x00000004 // 調試,程序在調試版里輸出的日志,在Publish版里就沒有了
#define L_LOGNUM 5 // 日志級別的數量
// 輸出位置
#define L_OUT_CONSOLE 0x00000100 // 輸出到控制臺
#define L_OUT_DLG 0x00000200 // 輸出到對話框
#define L_ONLY_LOGFILE 0x00000400 // 只保存到日志文件,不提示任何信息
#define L_NOTCLOSEPREV 0x00000800 // 當開啟對話框的時候不關閉原來的對話框
#define SLEEP_RETURN(x)\
{\
if ( ::WaitForSingleObject ( m_hEvtEndModule, x ) == WAIT_OBJECT_0 )\
return FALSE;\
}
#define SLEEP_BREAK(x)\
{\
if ( ::WaitForSingleObject ( m_hEvtEndModule, x ) == WAIT_OBJECT_0 )\
break;\
}
// 進入臨間區
#define EnterCRIT(pCRIT,CRITName,FileName,Line) \
{\
(pCRIT)->Lock ();\
TRACE ( "--------> %s , EnterCriticalSection ,%s ( %d )\n", CRITName, FileName, Line );\
}
// 離開臨間區
#define LeaveCRIT(pCRIT,CRITName,FileName,Line) \
{\
TRACE ( "<-------- %s , LeaveCriticalSection ,%s ( %d )\n", CRITName, FileName, Line );\
(pCRIT)->Unlock();\
}
class CHwDir
{
public:
CHwDir(
LPCTSTR lpszBasePathOrFile,
BOOL bSerachSubDir = TRUE, // 搜索子目錄
BOOL bAbsolutePath =TRUE, // 是絕對路徑
CHwDir **ppHwDir=NULL // 將這個類的指針傳出去給調用者
);
virtual ~CHwDir();
public:
ULONGLONG GetAmountBytes();
CStringArray *m_pStrAryResFile, *m_pStrArySubDirectory;
char m_szBasePathFile[MAX_PATH];
void Cancel();
private:
DWORD FindAllFileUnderOneDir(LPCTSTR lpszFileName,LPCTSTR lpszDirectory,BOOL bFindDir);
DWORD Dir();
int HandleOneFile(LPCTSTR lpszDirectory, WIN32_FIND_DATA* pFindData,BOOL bFindDir);
DWORD FindDirAndFile(LPCTSTR lpszDirectory);
private:
BOOL m_bCancel;
CStringArray *m_pStrArySubDirectory_Private;
DWORD m_dwDirNum;
ULONGLONG m_AmountBytes;
BOOL m_bSerachSubDir;
BOOL m_bAbsolutePath; //是否要保存絕對路徑
DWORD m_dwRelativePathStartPos; //相對路徑的起始位置
char m_strFilter[MAX_PATH/2];
};
class CHwDirEx
{
public:
CHwDirEx(
LPCTSTR lpszMultiFindPath, // 要搜索的路徑,如“E:\\winnt\\;d:\temp\\;”
LPCTSTR lpszMultiFindFilter, // 要搜索的過濾條件,如“*.bmp;*.exe;”
LPCTSTR lpszMultiExcludeFilter=NULL, // 要排除的過濾條件,如“*.bmp;*.exe;”
BOOL bSerachSubDir = TRUE, // 搜索子目錄
BOOL bAbsolutePath =TRUE, // 是絕對路徑
CHwDirEx **ppHwDirEx=NULL // 將這個類的指針傳出去給調用者
);
ULONGLONG GetAmountBytes();
virtual ~CHwDirEx();
void Cancel();
CStringArray *m_pStrAryResFile, *m_pStrArySubDirectory;
private:
CHwDir* m_pHwDir;
BOOL m_bCancel;
void DirAll(
LPCTSTR lpszFindPath, // 要搜索的路徑,如“E:\\winnt\\”
LPCTSTR lpszMultiFindFilter, // 要搜索的過濾條件,如“*.bmp;*.exe;”
LPCTSTR lpszMultiExcludeFilter=NULL, // 要排除的過濾條件,如“*.bmp;*.exe;”
BOOL bSerachSubDir = TRUE, // 搜索子目錄
BOOL bAbsolutePath =TRUE // 是絕對路徑
);
void Dir(
LPCTSTR lpszFindPath, // 要搜索的路徑,如“E:\\winnt\\”
LPCTSTR lpszMultiFindFilter, // 要搜索的過濾條件,如“*.bmp;*.exe;”
CStringArray &StrAryResFile, // 搜索的文件保存到此
CStringArray &StrArySubDirectory, // 搜索的子目錄保存到此
DWORD &dwAmountBytes, // 總字節數保存到此
BOOL bSerachSubDir = TRUE, // 搜索子目錄
BOOL bAbsolutePath =TRUE // 是絕對路徑
);
DWORD m_dwDirNum;
ULONGLONG m_AmountBytes;
};
//==========================================================================
// 常用操作宏
//==========================================================================
#define GET_VALID_STRING_FROM_TOW(cs1,cs2) ( (cs1.GetLength()>0)?cs1:cs2 )
#define GET_SAFE_STRING(str) ( (str)?(str):"" )
#define NULL_STRING_FOR_DB ""
#define GET_VALID_CSTRING(cs) ( (cs).GetLength()>0?(cs):((cs),(cs)=NULL_STRING_FOR_DB) )
#define GET_VALID_CSTRING_P(csp) ( (csp)?(*(csp)):"" )
#define STRNCPY_CS(sz,cs) strncpy((char*)(sz),(cs).GetBuffer(0),sizeof(sz))
#define STRNCPY_SZ(sz1,sz2) strncpy(((char*)(sz1)),(sz2)?((char*)(sz2)):"",sizeof(sz1))
#define STRNCPY(sz1,sz2,size) \
{\
strncpy(((char*)(sz1)),(sz2)?((char*)(sz2)):"",(size));\
((char*)(sz1))[(size)-1] = '\0';\
}
// 時間類型的數據長度
#define DATETIME_TYPE_LENGTH 20
#define STRCPY(sz1,sz2) strcpy ( (char*)(sz1), (char*)((sz2)?(sz2):"") )
#define STRLEN_SZ(sz) ((sz)?strlen((char*)(sz)):0)
#define COPMNC_CS_SZ(cs,sz) ( (sz) && ((cs).CompareNoCase(sz)==0) )
#define STRCMP_SAFE(sz1,sz2) (strcmp((char*)GET_SAFE_STRING(sz1),(char*)GET_SAFE_STRING(sz2)))
#define STRLEN_SAFE(sz) ((sz)?strlen((char*)(sz)):0)
#define ATOI_SAFE(sz) (atoi((const char*)(GET_SAFE_STRING((char*)(sz)))))
#define ASSERT_ADDRESS(p,size) ASSERT((p)!=NULL && AfxIsValidAddress((p),(size),TRUE))
#define VALID_IP_PORT(ip,port) ((STRLEN_SAFE(ip)>0) && (port)>1000)
#define LENGTH(x) sizeof(x)/sizeof(x[0])
#define MIN(x,y) (((DWORD)(x)<(DWORD)(y))?(x):(y))
#define MAX(x,y) (((DWORD)(x)>(DWORD)(y))?(x):(y))
// 有效的句柄
#define HANDLE_IS_VALID(h) ((HANDLE)(h) && ((HANDLE)(h)!=INVALID_HANDLE_VALUE))
// 關閉句柄
#define CLOSE_HANDLE(h)\
{\
if ( HANDLE_IS_VALID(h) )\
{\
::CloseHandle ( h );\
(h) = NULL;\
}\
}
int ConvertStrToCTime(char *chtime, CTime &cTime );
CString GetOneLine ( CString &str );
void Log ( UINT nLevel, LPCTSTR lpszFormat, ... );
int GetMouthByShortStr ( LPCTSTR lpszShortMonth );
CString hwFormatMessage ( DWORD dwErrorCode );
int WriteDataToFile(LPCTSTR filename,char* data,long size,LPCTSTR mode, int nStartPos=-1 );
CString Data2HexString ( int nOffset, char *data, int size );
void DbgLog ( LPCTSTR lpszFormat, ... );
int ReadDataFromFile(LPCTSTR filename,char* data,long size, int nStartPos=-1);
char* MakeSureDirectory(LPCTSTR lpszDirName);
int hwSnprintf ( char *buffer, int count, const char *format, ... );
BOOL PartPathAndFileAndExtensionName (
IN LPCTSTR lpszFilePath, // 全路徑名(包含文件名)
OUT CString *pcsOnlyPath, // 輸出光路徑(沒有文件名)
OUT CString *pcsOnlyFileName, // 輸出光文件名(沒有路徑)
OUT CString *pcsExtensionName // 輸出擴展名
);
BOOL PartFileAndPathByFullPath (
LPCTSTR lpszFilePath,
char *szOnlyFileName,
int nFileNameSize,
char *szOnlyPath =NULL,
int nPathSize=0
);
template<class T1, class T2>
int FindFromArray ( IN T1 &Ary, IN T2 Find )
{
int nCount = Ary.GetSize();
for ( int i=0; i<nCount; i++ )
{
if ( Ary.GetAt(i) == Find )
return i;
}
return -1;
}
template<class T1, class T2, class T3, class T4>
int FindFromArray ( IN T1 &Ary, IN T2 Find, IN T3 &AppAry, IN T4 AppFind )
{
int nCount = Ary.GetSize();
for ( int i=0; i<nCount; i++ )
{
if ( Ary.GetAt(i) == Find &&
AppAry.GetAt(i) == AppFind )
{
return i;
}
}
return -1;
}
void StandardizationPathBuffer ( char *szPath, int nSize, char cFlagChar='\\' );
CString StandardizationFileForPathName ( LPCTSTR lpszFileOrPathName, BOOL bIsFileName, char cReplaceChar='_' );
char *hwStrrChr ( const char *string, int c );
char *hwStrChr ( const char *string, int c );
BOOL PartFileAndExtensionName (
IN LPCTSTR lpszFileName,
OUT char *szFileName,
IN int nFileNameSize,
OUT char *szExtensionName=NULL,
IN int nExtensionNameSize=0 );
BOOL hwDeleteFolder ( LPCTSTR lpszFolder );
BOOL CopyFileAppend ( LPCTSTR lpszFileName_Src, LPCTSTR lpszFileName_Dst, int nOffset );
BOOL CreateNullFile ( LPCTSTR lpszFileName, int nFileSize );
BOOL WaitForThreadEnd ( HANDLE hThread, DWORD dwWaitTime=5000 );
DWORD SelectPathByCommonDlg(LPSTR lpszPathName,HWND hwndOwner=NULL);
BOOL SelectPathByCommonDlg ( CWnd *pDlg, UINT nEditID );
#endif // !defined(AFX_PUBLICFUNCTION_H__654F176C_F11F_4843_AEA0_F53676D52341__INCLUDED_)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -