Gif89a.h
上传用户:wanyou818
上传日期:2007-01-02
资源大小:30k
文件大小:7k
源码类别:

图片显示

开发平台:

Visual C++

  1. // Gif89a.h : Declaration of the CGif89a
  2. #ifndef __GIF89A_H_
  3. #define __GIF89A_H_
  4. #include "resource.h"       // main symbols
  5. #define DISPOSAL_NO 0
  6. #define DISPOSAL_NOT 4
  7. #define DISPOSAL_RESTBACK 8
  8. #define DISPOSAL_RESTORE 12
  9. typedef struct
  10. {
  11. BYTE bit;
  12. WORD previouscode;
  13. WORD nextcode;
  14. } GIFTABLE;
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CGif89a
  17. class ATL_NO_VTABLE CGif89a : 
  18. public CComObjectRootEx<CComSingleThreadModel>,
  19. public CComCoClass<CGif89a, &CLSID_Gif89a>,
  20. public CComControl<CGif89a>,
  21. public CStockPropImpl<CGif89a, IGif89a, &IID_IGif89a, &LIBID_GIF89Lib>,
  22. public IProvideClassInfo2Impl<&CLSID_Gif89a, NULL, &LIBID_GIF89Lib>,
  23. public IPersistStreamInitImpl<CGif89a>,
  24. public IPersistStorageImpl<CGif89a>,
  25. public IQuickActivateImpl<CGif89a>,
  26. public IOleControlImpl<CGif89a>,
  27. public IOleObjectImpl<CGif89a>,
  28. public IOleInPlaceActiveObjectImpl<CGif89a>,
  29. public IViewObjectExImpl<CGif89a>,
  30. public IOleInPlaceObjectWindowlessImpl<CGif89a>,
  31. public IDataObjectImpl<CGif89a>
  32. // public IConnectionPointContainerImpl<CGif89a>,
  33. // public IPropertyNotifySinkCP<CGif89a>,
  34. // public ISpecifyPropertyPagesImpl<CGif89a>
  35. {
  36. protected:
  37. BOOL m_bAutoStart;
  38. BOOL m_bEmbed;
  39. BYTE m_cCurentByte,m_cPackedField;
  40. UINT m_uBitSize,m_uPrimaryBitSize;
  41. UINT m_uRemain,m_uReadByte,m_uBlockSize;
  42. int m_iWidth,m_iHeight;
  43. int m_iTop,m_iLeft;
  44. int m_iFinishCode,m_iResetCode;
  45. int m_iPass,m_iRow;
  46. int m_iWidth1;
  47. int m_iBackgroundColor;
  48. int m_iGifSize;
  49. int m_x,m_y;
  50. int m_iGlobalColorSize;
  51. int m_iDisposalMethod;
  52. BOOL m_bTransparentIndex;
  53. int m_iTransparentIndex;
  54. int m_iDelayTime;
  55. int m_iTotalReadByte;
  56. int m_iMaxByte;
  57. DWORD m_dwSpeed;
  58. COLORREF m_TransparentColor;
  59. HDC m_hDC;
  60. BYTE* m_pcGlobalColorTable;
  61. BYTE* m_pcBitmap;
  62. BYTE* m_pcGif;
  63. BYTE* m_pcGifTrack; 
  64. BOOL m_bGlass;
  65. volatile int m_EndRun;
  66. HBITMAP m_hRedrawBitmap;
  67. int m_iGifWidth,m_iGifHeight;
  68. volatile BOOL m_bLockBitmap;
  69. TCHAR filename[_MAX_PATH];
  70. int flag;
  71. BOOL m_bRunMode;
  72. BOOL m_bAutoSize1;
  73. LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  74. LRESULT OnErase(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  75. public:
  76. CGif89a();
  77. ~CGif89a();
  78. BOOL Load(LPCTSTR name);
  79. BOOL Play1(void);
  80. HBITMAP FirstImage(void);
  81. HBITMAP NextImage(void);
  82. HBITMAP TakeIt(void);
  83. void Output(BYTE bit)
  84. {
  85. int tmp;
  86. if(m_cPackedField&0x40)
  87. {
  88. if(m_x==m_iWidth)
  89. {
  90. m_x=0;
  91. if(m_iPass==1)m_iRow+=8;
  92. if(m_iPass==2)m_iRow+=8;
  93. if(m_iPass==3)m_iRow+=4;
  94. if(m_iPass==4)m_iRow+=2;
  95. if(m_iRow>=m_iHeight){m_iPass+=1;m_iRow=16>>m_iPass;}
  96. }
  97. tmp=m_iRow*m_iWidth1+m_x;
  98. m_pcBitmap[tmp]=bit;
  99. m_x++;
  100. }
  101. else
  102. {
  103. if(m_x==m_iWidth){m_x=0;m_y++;}
  104. tmp=m_y*m_iWidth1+m_x;
  105. m_x++;
  106. }
  107. if(tmp>m_iMaxByte)return;
  108. m_pcBitmap[tmp]=bit;
  109. }
  110. BYTE GetByte(void)
  111. {
  112. if(m_uReadByte>=m_uBlockSize)
  113. {
  114. m_uBlockSize=*m_pcGifTrack++;
  115. m_uReadByte=0;
  116. m_iTotalReadByte+=m_uBlockSize+1;
  117. if(m_iTotalReadByte>m_iGifSize){m_iTotalReadByte-=m_uBlockSize+1;return 0xFF;}
  118. if(m_uBlockSize==0){m_pcGifTrack--;m_iTotalReadByte--;return 0xFF;}
  119. }
  120. m_uReadByte++;
  121. return *m_pcGifTrack++;
  122. }
  123. WORD GetCode(void)
  124. {
  125. UINT tmp1;
  126. BYTE tmp;
  127. tmp=1;
  128. if(m_uRemain>=m_uBitSize)
  129. {
  130. tmp<<=m_uBitSize;
  131. tmp--;
  132. tmp1=m_cCurentByte&tmp;
  133. m_cCurentByte>>=m_uBitSize;
  134. m_uRemain-=m_uBitSize;
  135. }
  136. else
  137. {
  138. tmp<<=m_uRemain;
  139. tmp--;
  140. tmp1=m_cCurentByte;
  141. m_cCurentByte=GetByte();
  142. tmp=1;
  143. if(8>=(m_uBitSize-m_uRemain))
  144. {
  145. tmp<<=(m_uBitSize-m_uRemain);
  146. tmp--;
  147. tmp1=(((UINT)(m_cCurentByte&tmp))<<m_uRemain)+tmp1;
  148. m_cCurentByte>>=(m_uBitSize-m_uRemain);
  149. m_uRemain=8-(m_uBitSize-m_uRemain);
  150. }
  151. else
  152. {
  153. tmp1=(((UINT)(m_cCurentByte))<<m_uRemain)+tmp1;
  154. m_cCurentByte=GetByte();
  155. tmp<<=m_uBitSize-m_uRemain-8;
  156. tmp--;
  157. tmp1=(((UINT)(m_cCurentByte&tmp))<<(m_uRemain+8))+tmp1;
  158. m_cCurentByte>>=m_uBitSize-m_uRemain-8;
  159. m_uRemain=8-(m_uBitSize-m_uRemain-8);
  160. }
  161. }
  162. return tmp1;
  163. }
  164. DECLARE_REGISTRY_RESOURCEID(IDR_GIF89A)
  165. BEGIN_COM_MAP(CGif89a)
  166. COM_INTERFACE_ENTRY(IGif89a)
  167. COM_INTERFACE_ENTRY(IDispatch)
  168. COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
  169. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
  170. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
  171. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
  172. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  173. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  174. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
  175. COM_INTERFACE_ENTRY_IMPL(IOleControl)
  176. COM_INTERFACE_ENTRY_IMPL(IOleObject)
  177. COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
  178. COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
  179. COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
  180. // COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages)
  181. COM_INTERFACE_ENTRY_IMPL(IDataObject)
  182. COM_INTERFACE_ENTRY(IProvideClassInfo)
  183. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  184. // COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  185. END_COM_MAP()
  186. BEGIN_PROPERTY_MAP(CGif89a)
  187. // Example entries
  188. // PROP_ENTRY("Property Description", dispid, clsid)
  189. PROP_ENTRY("AutoStart",4,CLSID_NULL)
  190. PROP_ENTRY("Speed",5,CLSID_NULL)
  191. PROP_ENTRY("Glass",6,CLSID_NULL)
  192. PROP_ENTRY("AutoSize",7,CLSID_NULL)
  193. PROP_ENTRY("FileName",9,CLSID_NULL)
  194. // PROP_PAGE(CLSID_About)
  195. END_PROPERTY_MAP()
  196. /*BEGIN_CONNECTION_POINT_MAP(CGif89a)
  197. CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
  198. END_CONNECTION_POINT_MAP()
  199. */
  200. BEGIN_MSG_MAP(CGif89a)
  201. MESSAGE_HANDLER(WM_PAINT, OnPaint)
  202. MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
  203. MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
  204. MESSAGE_HANDLER(WM_DESTROY, OnClose)
  205. MESSAGE_HANDLER(WM_ERASEBKGND, OnErase)
  206. END_MSG_MAP()
  207. // IViewObjectEx
  208. STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
  209. {
  210. ATLTRACE(_T("IViewObjectExImpl::GetViewStatusn"));
  211. *pdwStatus = VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE;
  212. return S_OK;
  213. }
  214. // IGif89a
  215. public:
  216. STDMETHOD(get_Embed)(/*[out, retval]*/ VARIANT_BOOL *pVal);
  217. STDMETHOD(put_Embed)(/*[in]*/ VARIANT_BOOL newVal);
  218. STDMETHOD(get_Glass)(/*[out, retval]*/ VARIANT_BOOL *pVal);
  219. STDMETHOD(put_Glass)(/*[in]*/ VARIANT_BOOL newVal);
  220. STDMETHOD(get_Speed)(/*[out, retval]*/ long *pVal);
  221. STDMETHOD(put_Speed)(/*[in]*/ long newVal);
  222. STDMETHOD(put_AutoSize)(/*[in]*/ VARIANT_BOOL newVal);
  223. STDMETHOD(get_AutoSize)(/*[in]*/ VARIANT_BOOL *newVal);
  224. STDMETHOD(get_AutoStart)(/*[out, retval]*/ VARIANT_BOOL *pVal);
  225. STDMETHOD(put_AutoStart)(/*[in]*/ VARIANT_BOOL newVal);
  226. STDMETHOD(get_FileName)(/*[out, retval]*/ BSTR *pVal);
  227. STDMETHOD(put_FileName)(/*[in]*/  BSTR newVal);
  228. STDMETHOD(Stop)();
  229. STDMETHOD(Play)();
  230. STDMETHOD(AboutBox)();
  231. STDMETHOD(SetExtent)(DWORD dwDrawAspect, SIZEL *psizel);
  232. STDMETHOD(GetExtent)(DWORD dwDrawAspect, SIZEL *psizel);
  233. HRESULT OnDraw(ATL_DRAWINFO& di);
  234. HRESULT IPersistStreamInit_Save(LPSTREAM pStm, BOOL /* fClearDirty */, ATL_PROPMAP_ENTRY* pMap);
  235. HRESULT IPersistStreamInit_Load(LPSTREAM pStm, ATL_PROPMAP_ENTRY* pMap);
  236. };
  237. #endif //__GIF89A_H_