在阅读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;"呵,答案已经在我心中了:)
博客讲述在阅读msdn关于“Graphic Objects”文章时,提到类库中每个图形对象类有将MFC对象转换为关联Windows句柄的转换运算符,得到的句柄在关联对象分离前有效,还给出将CPen对象转换为Windows句柄的代码示例。
1万+

被折叠的 条评论
为什么被折叠?



