www.pudn.com > ToolBar_ATL.rar > Picture.h
//////////////////////////////////////////////////////////////// // MSDN Magazine — October 2001 // 如果代码可行,就是Paul DiLascia写的。如若不行,那我就不知道是谁写的了。// 在Windows 98中用Visual C++ 6.0编译通过,大概在Windows 2000中也可以吧// 在你的编辑器中设置tabsize = 3 // #pragma once #include////////////////// // Picture 对象—封装IPicture // class CPicture { public: CPicture(); ~CPicture(); // 从不同的资源中加载 BOOL Load(UINT nIDRes); BOOL Load(LPCTSTR pszPathName); BOOL Load(CFile& file); BOOL Load(CArchive& ar); BOOL Load(IStream* pstm); // 转换设备环境 BOOL Render(CDC* pDC, CRect rc=CRect(0,0,0,0), LPCRECT prcMFBounds=NULL) const; CSize GetImageSize(CDC* pDC=NULL) const; operator IPicture*() { return m_spIPicture; } void GetHIMETRICSize(OLE_XSIZE_HIMETRIC& cx, OLE_YSIZE_HIMETRIC& cy) const { cx = cy = 0; const_cast (this)->m_hr = m_spIPicture->get_Width(&cx); ASSERT(SUCCEEDED(m_hr)); const_cast (this)->m_hr = m_spIPicture->get_Height(&cy); ASSERT(SUCCEEDED(m_hr)); } void Free() { if (m_spIPicture) { m_spIPicture.Release(); } } protected: CComQIPtr m_spIPicture; // 指向IPicture的ATL聪明指针 HRESULT m_hr; // 最近一次的错误代码 };