📄 commdef.h
字号:
#ifndef __COMMON_DEFINE_HEADER__
#define __COMMON_DEFINE_HEADER__
#ifndef NULL
#define NULL 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef Get3Min
#define Get3Min(x1,x2,x3) (((x1)<(x2)?(x1):(x2))<(x3)?((x1)<(x2)?(x1):(x2)):(x3))
#endif
#ifndef Get3Max
#define Get3Max(x1,x2,x3) (((x1)>(x2)?(x1):(x2))>(x3)?((x1)>(x2)?(x1):(x2)):(x3))
#endif
#ifndef between
#define between(x, a, b) ((((x)>=(a))&&((x)<=(b)))||(((x)>=(b))&&((x)<=(a))))
#endif
#ifndef ALIGN4
#define ALIGN4(x) ((((DWORD)x)+3) & (0xFFFFFFFC))
#endif
#ifndef ALIGN8
#define ALIGN8(x) ((((DWORD)x)+7) & (0xFFFFFFF8))
#endif
#ifndef LIMITTOMAX
#define LIMITTOMAX(x, maxvalue) ((x) > (maxvalue) ? (maxvalue) : (x))
#endif
#ifndef LIMITTOBOUND
#define LIMITTOBOUND(x, l, h) \
{ \
if ((x) < (l)) \
{ \
(x)=(l); \
} \
else if ((x) > (h)) \
{ \
(x)=(h); \
} \
}
#endif
#ifndef INTERVAL
#define INTERVAL(a, b) ((a) < (b) ? ((b)-(a)) : ((a)-(b)))
#endif
#ifndef INTERSECT
#define INTERSECT(x1, y1, x2, y2) ((((y2)>(x1))&&((x2)<(y1))) ? (min((y1), (y2))-max((x1), (x2))) : 0)
#endif
#ifndef ENLARGETOTIMES
#define ENLARGETOTIMES(x, y) (((x) % (y) == 0) ? (x) : ((x) + (y) - (x) % (y)))
#endif
#ifndef TRUNCTOTIMES
#define TRUNCTOTIMES(v, x) (((v) / (x)) * (x))
#endif
#ifndef RECTWIDTH
#define RECTWIDTH(rc) (((rc).right)-((rc).left))
#endif
#ifndef RECTHEIGHT
#define RECTHEIGHT(rc) (((rc).bottom)-((rc).top))
#endif
// align to (sizeof(int))
#ifndef _INTSIZEOF
#define _INTSIZEOF(TYPE) ((sizeof(TYPE)+sizeof(int)-1) & ~(sizeof(int)-1))
#endif
#ifndef ROUND_POSITIVE
#define ROUND_POSITIVE(x) ((((double)(x)-(int)(x))>0.5)?((int)((x)+1)):((int)(x)))
#endif
#ifndef ROUND_NEGATIVE
#define ROUND_NEGATIVE(x) ((((int)(x)-(double)(x))>0.5)?((int)((x)-1)):((int)(x)))
#endif
#ifndef ROUND
#define ROUND(x) (((x)>0) ? ROUND_POSITIVE(x) : ROUND_NEGATIVE(x))
#endif
#ifndef offsetof
#define offsetof(s,m) ((size_t)&(((s*)0)->m))
#endif
#ifndef ARRAYSIZE
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
#endif
#ifndef MulDiv
#define MulDiv(a,b,c) (((a)*(b))/(c))
#endif
#ifndef BMP_LINE_WIDTH
#define BMP_LINE_WIDTH(nImageWidth, nBitCount) (2 * 2 * (((nImageWidth) * (nBitCount) + 31) >> 5))
#endif
#ifndef BMP_RGBDATA_SIZE
#define BMP_RGBDATA_SIZE(nImageWidth, nImageHeight, nBitCount) (BMP_LINE_WIDTH(nImageWidth, nBitCount)*(nImageHeight))
#endif
//((x) < (0) ? (0) : ((x) > (255) ? (255) : (x)))
#ifndef LIMITUNCHAR
#define LIMITUNCHAR(x_int, c_char) \
{ \
if ((x_int) < 0) \
{ \
(c_char)=0x00; \
} \
else if ((x_int) > 0xFF) \
{ \
(c_char)=0xFF; \
} \
else \
{ \
(c_char)=(BYTE)(x_int); \
} \
}
#endif
#ifndef MAKEDWORD
#define MAKEDWORD(a, b, c, d) ((DWORD)(\
((BYTE)(a)) | \
(((DWORD)((BYTE)(b))) << 8) | \
(((DWORD)((BYTE)(c))) << 16) | \
(((DWORD)((BYTE)(d))) << 24) \
))
#endif
#ifndef POINTTODWORD
#define POINTTODWORD(pt) (((pt.x) & 0x0000FFFF) | (((pt.y)<<16)&0xFFFF0000))
#endif
#ifdef WIN32
#define SHOWMSG _tprintf
#else
#define SHOWMSG NKDbgPrintfW
#endif
#ifndef PRT_ERR
#define PRT_ERR(hr) \
SHOWMSG(TEXT("Error In File %s, funcname=%s, line=%d, err code=0x%08x\r\n"), \
TEXT(__FILE__), TEXT(__FUNCTION__), __LINE__, hr)
#endif
#ifndef CHECKRESULT
#define CHECKRESULT(x) \
{ \
if (FAILED(hr = x)) \
{ \
PRT_ERR(hr); \
} \
}
#endif
#ifndef FAILEDRETURN
#define FAILEDRETURN(x) \
{ \
if (FAILED(hr = x)) \
{ \
PRT_ERR(hr); \
return hr; \
} \
}
#endif
#ifndef FAILEDBREAK
#define FAILEDBREAK(x) \
{ \
if (FAILED(hr = x)) \
{ \
PRT_ERR(hr); \
break; \
} \
}
#endif
#ifndef FAILEDJUMP
#define FAILEDJUMP(x) \
{ \
if (FAILED(hr = x)) \
{ \
PRT_ERR(hr); \
goto Cleanup; \
} \
}
#endif
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(x) \
{ \
if (x) \
{ \
x->Release(); \
x = NULL; \
} \
}
#endif
#ifndef SAFE_ADDREF
#define SAFE_ADDREF(x) \
{ \
if (x) \
{ \
x->AddRef(); \
} \
}
#endif
#ifndef SAFE_DELETE
#define SAFE_DELETE(x) \
{ \
if (x) \
{ \
delete x; \
x = NULL; \
} \
}
#endif
#ifndef SAFE_DELETEARRAY
#define SAFE_DELETEARRAY(x) \
{ \
if (x) \
{ \
delete[] x; \
x = NULL; \
} \
}
#endif
#ifndef SAFE_SYSFREESTRING
#define SAFE_SYSFREESTRING(x) \
{ \
if (x) \
{ \
SysFreeString(x); \
x = NULL; \
} \
}
#endif
#ifndef SAFE_CLOSEHANDLE
#define SAFE_CLOSEHANDLE(x) \
{ \
if (x && INVALID_HANDLE_VALUE != x) \
{ \
CloseHandle(x); \
x = NULL; \
} \
}
#endif
#ifndef SAFE_DELETEOBJECT
#define SAFE_DELETEOBJECT(x) \
{ \
if (x) \
{ \
DeleteObject(x) ; \
x = NULL ; \
} \
}
#endif
#ifndef SAFE_DELETEDC
#define SAFE_DELETEDC(x) \
{ \
if (x) \
{ \
DeleteDC(x) ; \
x = NULL ; \
} \
}
#endif
#ifndef SAFE_RELEASEDC
#define SAFE_RELEASEDC(a, b) \
{ \
if (b) \
{ \
ReleaseDC(a, b); \
b = NULL; \
} \
}
#endif
#ifndef SAFE_DESTROYICON
#define SAFE_DESTROYICON(x) \
{ \
if (x) \
{ \
DestroyIcon(x) ; \
x = NULL ; \
} \
}
#endif
#ifndef SAFE_DESTROYWINDOW
#define SAFE_DESTROYWINDOW(x) \
{ \
if (x) \
{ \
DestroyWindow(x) ; \
x = NULL ; \
} \
}
#endif
#ifndef SAFE_CLOSESOCKET
#define SAFE_CLOSESOCKET(h) \
{ \
if (h) \
{ \
closesocket(h) ; \
h = NULL ; \
} \
}
#endif
#ifndef SAFE_POINT_SETVALUE
#define SAFE_POINT_SETVALUE(p, v) \
{ \
if (p) \
{ \
*(p) = (v) ; \
} \
}
#endif
#ifndef SAFE_STRNCPY
#define SAFE_STRNCPY(dst, src, len) \
{ \
if (dst && src) \
{ \
if (len > 0) \
{ \
strncpy(dst, src, len) ; \
dst[len-1] = TEXT('\0') ; \
} \
else if (len == 0) \
{ \
dst[0] = TEXT('\0') ; \
} \
} \
}
#endif
#ifndef SAFE_WCSNCPY
#define SAFE_WCSNCPY(dst, src, len) \
{ \
if (dst && src) \
{ \
if (len > 0) \
{ \
wcsncpy(dst, src, len) ; \
dst[len-1] = TEXT('\0') ; \
} \
else if (len == 0) \
{ \
dst[0] = TEXT('\0') ; \
} \
} \
}
#endif
#ifdef _UNICODE
#define SAFE_TCSNCPY SAFE_WCSNCPY
#else
#define SAFE_TCSNCPY SAFE_STRNCPY
#endif
#ifndef EQUAL_POINT
#define EQUAL_POINT(pt1, pt2) ((((pt1)->x) == ((pt2)->x) && ((pt1)->y) == ((pt2)->y)) ? TRUE : FALSE)
#endif
#ifndef MoveWindowRect
#define MoveWindowRect(hwnd, prc, bRepaint) \
MoveWindow(hwnd, (prc)->left, (prc)->top, (prc)->right-(prc)->left, (prc)->bottom-(prc)->top, bRepaint)
#endif
// MB2WC(WCHAR *wc, int nWCLength, char *mb, int nMBLength=-1, UINT uCodePage=CP_ACP)
#ifndef MB2WC
#define MB2WC(wc, nWCLength, mb, nMBLength, uCodePage) \
MultiByteToWideChar(uCodePage, NULL, mb, nMBLength, wc, nWCLength)
#endif
// WC2MB(char *mb, int nMBLength, WCHAR *wc, int nWCLength=-1, UINT uCodePage=CP_ACP)
#ifndef WC2MB
#define WC2MB(mb, nMBLength, wc, nWCLength, uCodePage) \
WideCharToMultiByte(uCodePage, NULL, wc, nWCLength, mb, nMBLength, NULL, NULL)
#endif
#endif //__COMMON_DEFINE_HEADER__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -