1.FALSE/TRUE与false/true的区别:
false/true是标准C++语言里新增的关键字,而FALSE/TRUE是通过#define,这要用途是解决程序在C与C++中环境的差异,以下是FALSE/TRUE在windef.h的定义:
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
也就是说FALSE/TRUE是int类型,而false/true是bool类型;所以两者不一样的,只不过我们在使用中没有这种感觉,因为C++会帮你做隐式转换。
2.bool的大小与BOOL的区别:
bool在C++里是占用1字节,而BOOL是int类型,int类型的大小是视具体环境而定的;所以来说:false/true只占用1个字节,而TRUE/FALSE视具体环境而言,以下是BOOL在windef.h中的定义:typedef int BOOL;
3.NULL与0的区别:
还是让我们看一下windef.h中NULL的定义:
#ifndef NULL
#ifdef __cplusplus//这个是指示是用C++来编译程序
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
所以说:它们没有区别,只不过在C里面会做一个强制类型转换。
4.HINSTANCE与HMODULE的区别:
在windef.h中的定义:
typedef HINSTANCE HMODULE; /* HMODULEs can be used in place of HINSTANCEs */
5.CALLBACK,WINAPI的实质:
在windef.h中的定义:
#undef far
#undef near
#undef pascal
#define far
#define near
#if (!defined(_MAC)) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
#define pascal __stdcall
#else
#define pascal
#endif
#if defined(DOSWIN32) || defined(_MAC)
#define cdecl _cdecl
#ifndef CDECL
#define CDECL _cdecl
#endif
#else
#define cdecl
#ifndef CDECL
#define CDECL
#endif
#endif
#ifdef _MAC
#define CALLBACK PASCAL
#define WINAPI CDECL
#define WINAPIV CDECL
#define APIENTRY WINAPI
#define APIPRIVATE CDECL
#ifdef _68K_
#define PASCAL __pascal
#else
#define PASCAL
#endif
#elif (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
#define CALLBACK __stdcall
#define WINAPI __stdcall
#define WINAPIV __cdecl
#define APIENTRY WINAPI
#define APIPRIVATE __stdcall
#define PASCAL __stdcall
#else
#define CALLBACK
#define WINAPI
#define WINAPIV
#define APIENTRY WINAPI
#define APIPRIVATE
#define PASCAL pascal
#endif
6.一些常见类型的定义:
在windef.h中的定义:
typedef UINT WPARAM;
typedef LONG LPARAM;
typedef LONG LRESULT;
typedef int INT;
typedef unsigned int UINT;
typedef unsigned long DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef float FLOAT;
typedef unsigned long ULONG;
typedef unsigned short USHORT;
typedef unsigned char UCHAR;
typedef char *PSZ;
7.常见Window资源类型的实质:
在windef.h中的定义:
DECLARE_HANDLE(HPEN);
DECLARE_HANDLE(HBITMAP);
DECLARE_HANDLE(HBRUSH);
DECLARE_HANDLE(HDC);
DECLARE_HANDLE(HFONT);
DECLARE_HANDLE(HICON);
DECLARE_HANDLE(HMENU);
DECLARE_HANDLE(HMETAFILE);
DECLARE_HANDLE(HINSTANCE);
DECLARE_HANDLE(HPALETTE);
typedef WORD ATOM;
typedef HANDLE HGLOBAL;
typedef HANDLE HLOCAL;
typedef HANDLE GLOBALHANDLE;
typedef HANDLE LOCALHANDLE;
typedef HICON HCURSOR; /* HICONs & HCURSORs are polymorphic */
typedef DWORD COLORREF;
在windowsx.h中:
#define DECLARE_HANDLE32 DECLARE_HANDLE
penwin.h:
#ifndef DECLARE_HANDLE32
#define DECLARE_HANDLE32(name)\
struct name##__ { int unused; };\
typedef const struct name##__ FAR* name
#endif //!DECLARE_HANDLE32
6.Platform的编译版本的相关预处理宏:
Macro Description
__cplusplus Defined for C++ programs only.
_MFC_VER Defines the MFC version. Defined as 0x0421 for Microsoft Foundation Class Library 4.21. Always defined.
_MSC_VER Defines the compiler version. Defined as 1200 for Microsoft Visual C++ 6.0. Always defined.
_WIN32 Defined for applications for Win32®. Always defined.