Windos学习旅程-Error和UNICODE(二)
///////////////////////////////////////////////////////////
//1.Error
///////////////////////////////////////////////////////////
Windows的Error表示结构有三部分组成:
1.ID
2.MessageID
3.MessageText
Windows提供了一个API来显示MessageText
DWORD FormatMessage(
DWORD dwFlags, // source and processing options
LPCVOID lpSource, // pointer to message source
DWORD dwMessageId, // requested message identifier
DWORD dwLanguageId, // language identifier for requested message
LPTSTR lpBuffer, // pointer to message buffer
DWORD nSize, // maximum size of message buffer
va_list *Arguments // pointer to array of message inserts
);
如果想自己定义个Error,可以用SetError()API.
///////////////////////////////////////////////////////////
//2.UNICODE
///////////////////////////////////////////////////////////
当我学了UNICODE这一部分内容才知道为啥Windows要自己定义一些鬼类型,比如说PCHAR,PSTR等等。这些类型都是为了兼容UNICODE用的,因为Windows2000以后的系统底层用的编码是UNICODE的,即使你在程序里面用的是ANSI类型,当Windows也会默认的给你加一个字节去处理按照UNICODE去运行,当运行完成后,在把UNICODE的转化成ANSI类型返回给应用系统。但是为了向后兼容Windows对于以前ANSI/UNICODE编码分别提供了对应的API,如我们最长见的CreateWindow API
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#ifdef UNICODE
#define CreateWindow CreateWindowW
#else
#define CreateWindow CreateWindowA
#endif // !UNICODEWindows除了定义UNICODE这个宏以外还定义了,_TEXT()等宏。。
Windows系统中对于宏的应用可谓是出神入化,在MFC中RTTI等超NB的机制都是用宏来实现的,在这儿也就不详述了。
posted on 2007-11-16 13:29 john.huang 阅读(313) 评论(0) 收藏 举报
浙公网安备 33010602011771号