1.
HDC 设备环境句柄 实际上那些windows中奇怪的类型都是我们常见的类型变化而得来的
HWND m_hWnd; HWND 是窗口句柄类型,m_hWnd中的m_h是一个叫做"匈牙利命名法"规定的命名变量的规范
在Windows数据类型中有以下描述(来自CSDN):
Windows Data Types
LPCSTR : Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.
LPCTSTR : An LPCWSTR if UNICODE is defined, an LPCSTR otherwise.
LPCWSTR : Pointer to a constant null-terminated string of 16-bit Unicode characters.
LPTSTR : An LPWSTR if UNICODE is defined, an LPSTR otherwise.
LPSTR : Pointer to a null-terminated string of 8-bit Windows (ANSI) characters.
LPWSTR : Pointer to a null-terminated string of 16-bit Unicode characters.
这些数据类型在多个头文件中定义,以下是mapidefs.h中的定义:
typedef WORD WCHAR;
#ifdef UNICODE
typedef WCHAR TCHAR;
#else
typedef char TCHAR;
#endif
typedef WCHAR FAR * LPWSTR;
typedef const WCHAR FAR * LPCWSTR;
typedef TCHAR FAR * LPTSTR;
typedef const TCHAR FAR * LPCTSTR;
typedef BYTE FAR * LPBYTE;
实际上,它们都是char 或 wchar_t类型或该类型的指针:
WORD : typedef unsigned short WORD; 2 bytes
LPCTSTR : typedef const TCHAR *LPCTSTR;
TCHAR : typedef wchar_t TCHAR; 2 bytes
LPTSTR : typedef TCHAR *LPTSTR;
LPCSTR : typedef const CHAR *LPCSTR;
CHAR : typedef char CHAR; 1 byte
说到底,就是1个字节和两个字节的问题~也就是ANSI和Unicode:
char (1 byte) : Type char is an integral type that usually contains members of the execution character set — in Microsoft C++, this is ASCII. (8-bit Windows (ANSI) characters)
__wchar_t ( 2 bytes) : A variable of __wchar_t designates a wide-character or multibyte character type. By default, wchar_t is a typedef for unsigned short. (16-bit Unicode characters)
2.
GetDC(HWND hWindow) 是获取与设备相关的设备环境
它通常与ReleaseDC(HWND hWindow,HDC hDC)是成对出现的
我们一般会使用BeginPaint(HWND hWindow,PAINTSTRUCT* ps)和EndPaint(HWND hWindow,PAINTSTRUCT* ps)
来获得设备环境,而GetDC(HWND hWindow)和ReleaseDC(HWND hWindow,HDC hDC)是在BeginPaint()和EndPaint()
函数之外进行绘图时用的
我们所有的图形操作都是在设备环境中进行的,你也可以把设备环境理解为一张纸