| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1449 人关注过本帖
标题:[讨论]初学者求助,关于画线问题
只看楼主 加入收藏
猫猫吃鱼
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-12-10
收藏
 问题点数:0 回复次数:1 
[讨论]初学者求助,关于画线问题

我刚学VC几天,
看的是孙鑫的教程,
可是我照着他的教程写了几行画线代码,
他运行出的程序就可以画线,
而我运行代码,就画不出线呢,
代码如下:
HDC hdc;
hdc=::GetDC(m_hWnd);
MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,NULL);
LineTo(hdc,point.x,point.y);
::ReleaseDC(m_hWnd,hdc);

关于这几行代码,还有很多不明白地方,
1.HDC是要画图就要用到的类吗?是个什么东西
2.m_hWnd是什么啊,它和hdc有啥关系呢

搜索更多相关主题的帖子: 画线 hdc hWnd point 
2006-12-10 15:04
tiancaiak
Rank: 2
等 级:论坛游民
威 望:1
帖 子:111
专家分:43
注 册:2006-9-17
收藏
得分:0 

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()
函数之外进行绘图时用的

我们所有的图形操作都是在设备环境中进行的,你也可以把设备环境理解为一张纸


2006-12-11 17:41
快速回复:[讨论]初学者求助,关于画线问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014589 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved