global.h
来自「◆◆◆ 《投掷飞镖记分工具》◆◆◆ 操作系统 : Windows Mobil」· C头文件 代码 · 共 233 行
H
233 行
/* Filename : global.h */
#pragma once
#ifndef DLL_INTERNAL
#ifdef WINCE
#define DLL_INTERNAL
#else
#define DLL_INTERNAL __declspec( dllexport )
#endif
#endif
#pragma warning(once:4996) // 4996编译时的警告信息仅显示一个
//==========================================================================
// 常用操作宏
//==========================================================================
#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 ASSERT_ADDRESS(p,size) ASSERT((p)!=NULL && AfxIsValidAddress((p),(size),TRUE))
#define GET_SAFE_STRING(str) ( (str)?(str):_T("") )
#define GETFILESIZE(fad) (( (fad).nFileSizeHigh << sizeof(DWORD) ) | (fad).nFileSizeLow)
// strncat 函数
#ifdef UNICODE
#define strncat_hw wcsncat
#else
#define strncat_hw strncat
#endif
// strrchr 函数
#ifdef UNICODE
#define strrchr_hw wcsrchr
#else
#define strrchr_hw strrchr
#endif
// strchr 函数
#ifdef UNICODE
#define strchr_hw wcschr
#else
#define strchr_hw strchr
#endif
// strstr 函数
#ifdef UNICODE
#define strstr_hw wcsstr
#else
#define strstr_hw strstr
#endif
// sscanf 函数
#ifdef UNICODE
#define sscanf_hw swscanf
#else
#define sscanf_hw sscanf
#endif
// _vsnprintf 函数
#ifdef UNICODE
#define _vsnprintf_hw _vsnwprintf
#else
#define _vsnprintf_hw _vsnprintf
#endif
// sprintf 函数
#ifdef UNICODE
#define sprintf_hw swprintf
#else
#define sprintf_hw sprintf
#endif
// _snprintf 函数
#ifdef UNICODE
#define _snprintf_hw _snwprintf
#else
#define _snprintf_hw _snprintf
#endif
// strtok 函数
#ifdef UNICODE
#define strtok_hw wcstok
#else
#define strtok_hw strtok
#endif
// 句柄是否有效
#define HANDLE_IS_VALID(h) ( (HANDLE)(h!=NULL) && (HANDLE)(h) != INVALID_HANDLE_VALUE )
// 关闭句柄
#define SAFE_CLOSE_HANDLE(h)\
{\
if ( HANDLE_IS_VALID ( h ) )\
{\
CloseHandle ( h );\
h = NULL;\
}\
}
// 等待事件的 Sleep() 函数
#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 DELETE_ARRAY(pp)\
{\
if ( (pp) && (*(pp)) )\
{\
(*(pp))->RemoveAll();\
(*(pp))->FreeExtra();\
delete (*(pp));\
(*(pp)) = NULL;\
}\
}
// 删除所有由 new 申请的内存空间,可以是对象,也可以是普通的数据类型,如int、char等
#define DELETE_HEAP(pp)\
{\
if ( (pp) && (*(pp)) )\
{\
delete (*(pp));\
(*(pp)) = NULL;\
}\
}
//
// 全局消息
//
enum
{
WM_SCAN_BLUETOOTH_DEVICE_FINISHED = WM_USER+0x1000,
WM_SHOWLOG,
WM_REG_SEARCH,
WM_EXIT_MYSELF,
WM_SHOW_MAIN_WINDOW,
};
// RDTP 协议的版本号
#define RDTPVERSION _T("RDTP/1.0")
// 回应客户端的代码
#define RESPONSE_CODE_OK 200 // OK
#define RESPONSE_CODE_AUTHENTICATION_FAIL 101 // 身份验证失败
#define RESPONSE_CODE_SUBMITDATA_FAIL 102 // 提交数据给WebService失败
#define RESPONSE_CODE_GETDIAGNOSEINFO_ERROR 103 // 获取诊断信息发生错误
#define RESPONSE_CODE_UNKNOWNVERB 104 // 无法识别的动词
#define RESPONSE_CODE_PROTOCOLERROR 105 // 通信协议错误
#define RESPONSE_CODE_INNERERROR 106 // 程序内部发生错误
template<class T>
int FindFromStaticArray ( IN T *pAry, IN int nArySize, IN T Find )
{
if ( !pAry ) return -1;
for ( int i=0; i<nArySize; i++ )
{
if ( pAry[i] == Find )
return i;
}
return -1;
}
//
// 注意:如果是从 CString 中查找时 Find 千万不要用 LPCTSTR 或者 char* 变量,一定是要用 CString 变量
//
template<class T1, class T2>
int FindFromArray ( IN T1 &Ary, IN T2 Find )
{
int nCount = (int)Ary.GetSize();
for ( int i=0; i<nCount; i++ )
{
T2 tGetValue = Ary.GetAt(i);
if ( tGetValue == Find )
return i;
}
return -1;
}
//
// 从数组 Ary_Org 中查找,只要 Ary_Find 中任何一个元素在 Ary_Org 中出现过
// 就返回该元素在 Ary_Org 中的位置
//
template<class T1, class T2>
int FindFromArray ( IN T1 &Ary_Org, IN T1 &Ary_Find, OUT T2 &Element )
{
int nCount = Ary_Find.GetSize();
for ( int i=0; i<nCount; i++ )
{
T2 tGetValue = Ary_Find.GetAt(i);
int nFindPos = FindFromArray ( Ary_Org, tGetValue );
if ( nFindPos >= 0 )
{
Element = Ary_Org.GetAt ( nFindPos );
return nFindPos;
}
}
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;
}
template<class T1>
int FindFromArray ( IN T1 &Ary_Src, IN T1 &Ary_Find )
{
int nCount = Ary_Src.GetSize();
for ( int i=0; i<nCount; i++ )
{
if ( FindFromArray ( Ary_Find, Ary_Src.GetAt(i) ) >= 0 )
return i;
}
return -1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?