📄 ngmacros.h
字号:
// NGMacros.h : Macro definitions
//
#ifndef __MACRO
#define __MACRO
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
/////////////////////////////////////////////////////////////////////////////
// Definitions
// Reserved for Help Support
// (this code is from the Help95 sample)
#define MAKEHELPID(a, b) ((DWORD)(0x80000000 | ((DWORD)(a) << 16) | ((DWORD)(b)) ))
struct CTRLID_HELPID_PAIR
{
CTRLID_HELPID_PAIR(DWORD x, DWORD y) : dwCtrlID(x), dwHelpID(y) {};
DWORD dwCtrlID;
DWORD dwHelpID;
};
#if 0
// Wrappers for non-UNICODE safe runtime library functions
// (avoids nasty surprises for Unicode rebuilds)
#ifdef _UNICODE
#define IsAlpha(c) iswalpha(c)
#define IsDigit(c) iswdigit(c)
#define IsSpace(c) iswspace(c)
#define IsPunct(c) iswpunct(c)
#define IsAlNum(c) iswalnum(c)
#else
#define IsAlpha(c) isalpha(c)
#define IsDigit(c) isdigit(c)
#define IsSpace(c) isspace(c)
#define IsPunct(c) ispunct(c)
#define IsAlNum(c) isalnum(c)
#endif
#endif
/***********************************************************************
* Use to notify the user that a method or facility is not fully implemented
* When compiled for debug adds an error message to the output trace and
* throws a debug assertion.
* When compiled for release, this macro has no effect.
*
************************************************************************/
#define NOT_IMPLEMENTED_ERROR() \
{ \
TRACE0("**** ERROR: Not yet implemented"); \
ASSERT(FALSE); \
}
/***********************************************************************
* Helper macros to implement safe pointer attachments
*
* When another object obtains a pointer to your class it can then
* call Attach(pointer&) to register it's interest.
*
* When the server object is deleted all attached pointers will be
* safely NULLed.
*
* To use:
* 1. Add DECLARE_PTR_ATTACHMENT(ClassName) to the operations
* section of your header file
*
* 2. Add IMPLEMENT_PTR_ATTACHMENT(ClassName) to your
* implementation file
*
* 3. Add a call to NullAttachedPointers() to the class destructor
*
* These macros are provided to avoid the need for a "mix-in" class
* implementing this capability
*
************************************************************************/
#define DECLARE_PTR_ATTACHMENT(ClassName) \
protected:\
CPtrList m_listReferences; \
\
void NullAttachedPointers(void);\
public:\
BOOL Attach(ClassName*& rpObj); \
BOOL Detach(ClassName*& rpObj);
#define IMPLEMENT_PTR_ATTACHMENT(ClassName) \
\
BOOL ClassName::Attach(ClassName*& rpObj) \
{ \
TRACE_CALL1("Attach(0x%X)\n", &rpObj); \
\
if (NULL == &rpObj) \
return FALSE; \
\
if (NULL != m_listReferences.Find( (LPVOID)&rpObj )) \
{ \
TRACE0("Attempted to re-attach a pointer!\n"); \
ASSERT(0); \
return FALSE; \
} \
rpObj = this; \
m_listReferences.AddHead( (LPVOID)&rpObj ); \
return TRUE; \
} \
\
\
BOOL ClassName::Detach(ClassName*& rpObj) \
{ \
TRACE_CALL1("Detach(0x%X)\n", &rpObj); \
\
POSITION pos = m_listReferences.Find( (LPVOID)&rpObj ); \
if (NULL == pos) \
{ \
TRACE0("Attempted to detach unattached pointer!\n"); \
ASSERT(0); \
return FALSE; \
} \
m_listReferences.RemoveAt(pos); \
if (this == rpObj) \
rpObj = NULL; \
\
return TRUE; \
} \
\
void ClassName::NullAttachedPointers(void) \
{ \
for (POSITION pos = m_listReferences.GetHeadPosition(); pos != NULL; ) \
{ \
ClassName** ppObject = (ClassName**)m_listReferences.GetNext(pos); \
if (this == *ppObject) \
*ppObject = NULL; \
} \
}
/***********************************************************************
* Provide a version of the DECLARE_SERIAL() macro which can be used
* in classes within MFC extension DLLs
*
* Use this instead of DECLARE_SERIAL() in any classes within an
* extension DLL
*
* Refer to MSDN Knowledge Base Article Q152254
* "BUG: LNK2001 on Operator>> with Class from MFC Extension DLL"
* for full details.
*
************************************************************************/
#define DECLARE_SERIAL_EXTDLL(class_name) \
_DECLARE_DYNCREATE(class_name) \
AFX_EXT_API friend CArchive& AFXAPI \
operator>>(CArchive& ar, class_name* &pOb);
#endif // !_MACROS_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -