CXX与HXX的强制类型转换(cast)

在阅读msdn中关于“Graphic Objects”的一篇文章时,发现了这样几句话:

“Each graphic-object class in the class library has a cast operator that will cast an MFC object to the associated Windows handle. The resulting handle is valid until the associated object detaches it. Use the object’s Detach member function to detach the handle.

The following code casts a CPen object to a Windows handle:

CPen myPen;
myPen.CreateSolidPen( PS_COSMETIC, 1, RGB(255,255,0) );
HPEN hMyPen = (HPEN) myPen; ”
其中的cast使我产生了联想,于是,我打开VC,并找到了CPen的类定义,在其中发现了这样一个函数的声明:
"operator HPEN() const;" ,
啊,难道这就是实现上面语句“HPEN hMyPen = (HPEN) myPen”的依据吗?
于是,我又找到了CBrush的类定义,并找到了一个类似的函数声明:
"operator HBRUSH() const;"
呵,答案已经在我心中了:)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值