posts - 274,  comments - 1258,  trackbacks - 0

1)数据类型、变量和常量的定义
在Windows API中,定义了若干数据类型和基本常量(windef.h):
typedef int             BOOL;
typedef unsigned char     BYTE;
typedef unsigned short    WORD;
typedef int          INT;
typedef unsigned int      UINT;
typedef unsigned long    DWORD;
LONGLONG 64位整数

typedef char      CHAR;
typedef __nullterminated CONST CHAR * LPCSTR;
typedef unsigned short      wchar_t;
typedef wchar_t      WCHAR;
typedef CONST WCHAR *    LPCWSTR;
#ifdef UNICODE
 typedef LPCWSTR      LPCTSTR;
#else
 typedef LPCSTR      LPCTSTR;
#endif

typedef UINT  WPARAM;
typedef LONG LPARAM;
typedef LONG  LRESULT;

typedef DWORD    COLORREF; // 0x00bbggrr
typedef short  HFILE;

#define NULL     0 // C++
#define NULL     ((void *)0) // C
#define FALSE         0
#define TRUE           1

在Windows API中,还定义了若干作为对象索引的句柄(handle):
HANDLE // Handle to an object.(DWORD)
HBITMAP // Handle to a bitmap.
HBRUSH // Handle to a brush.
HCURSOR // Handle to a cursor.
HDC // Handle to a device context (DC).
HFILE // Handle to a file opened by OpenFile, not CreateFile.
HFONT // Handle to a font.
HGLOBAL // Handle to a global memory block.
HICON // Handle to an icon.
HINSTANCE // Handle to an instance.
HLOCAL // Handle to a local memory block.
HMENU // Handle to a menu.

在Windows API编程中,常在变量中使用前缀来代表其数据类型:
b BOOL
by BYTE
c char
dw DWORD
fn function(函数)
h handle(句柄)
i int
l LONG
lp long pointer(长指针)
n short
np near pointer(近指针)
p pointer(指针)
s string(字符串)
sz string end with zero(以’\0’结尾的字符串)
w WORD

在Windows API编程中,在常量中使用前缀来代表其所属范围:
CS  Class Style([窗口]类风格)
CW  Create Window(创建窗口)
DT  Drawing Text(绘制文本)
IDC  IDentity of Cursor(光标标识)
IDI  IDentity of Icon(图标标识)
WM  Window Message(窗口消息)
WS  Window Style(窗口风格)

l 几点有关字符(串)类型的说明:
n char为C/C++语言的单字节字符类型
n wchar_t为ISO C++的(双字节)宽字符类型,也是ISO C99的(双字节)宽字符typedef类型(typedef unsigned short wchar_t;)
n WCHAR和_TCHAR都是微软公司为Win32定义的与wchar_t等价的双字节宽字符typedef类型(typedef wchar_t WCHAR;  typedef wchar_t _TCHAR;)
n LPSTR为单字节字符串的长指针
n LPCWSTR为双字节字符串的长指针
n LPCTSTR为(双或单字节)字符串的长指针(按是否定义UNICODE确定)
n string为ISO C++标准新加的单字节字符串类
n CString为微软公司的MFC定义的字符串类(兼容单双字节字符)
n 在要求宽字符串的地方,字符串常量前需要添加L运算符
例如:
int x, y;
LPCWSTR szAppName = L"WHello";
wchar_t buf[20];
……
swprintf(buf, 20, L"Hello! (%d, %d)", x, y);

posted on 2006-06-12 11:42 踏雪赤兔 阅读(635) 评论(0)  编辑 收藏 引用 所属分类: 速查手册
只有注册用户登录后才能发表评论。

百度空间| 见闻日记| 编程感悟
我的twitter


LOGO

自我介绍:百度厂基础平台车间的一名挨踢民工。擅长C++、算法、语言设计、分布式计算,也用过Java,Python, PHP,JS/AS等语言开发。请关注我的twitter (免翻墙版) 发QQ消息


添加到收藏夹 Locations of visitors to this page

常用链接

随笔分类(300)

随笔档案(274)

文章分类(38)

相册

收藏夹(54)

与博主互动

博客手拉手

搜索

  •  

积分与排名

  • 积分 - 392994
  • 排名 - 10

最新评论

阅读排行榜

评论排行榜