home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedZip.Cab / F112559_XceedZipEvents.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-17  |  6.4 KB  |  206 lines

  1. // XceedZipEvents.cpp : implementation file
  2. //
  3. // MFC sample using The Xceed Zip Compression Library 4
  4. // Copyright (c) 1999 Xceed Software Inc.
  5. //
  6. // This sample illustrate how to use the XceedZip control in MFC
  7. // without having to drop the control on a form.
  8. //
  9.  
  10. #include "stdafx.h"
  11. #include "Typelib.h"
  12. #include "XceedZipEvents.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CXceedZipEvents
  22.  
  23. IMPLEMENT_DYNCREATE(CXceedZipEvents, CCmdTarget)
  24.  
  25. CXceedZipEvents::CXceedZipEvents( void )
  26. {
  27.     EnableAutomation();
  28.  
  29.   m_pBar              = NULL;
  30.   m_pResults          = NULL;
  31.   m_pConnectionPoint  = NULL;
  32. }
  33.  
  34. CXceedZipEvents::~CXceedZipEvents( void )
  35. {
  36.   if( m_pConnectionPoint )
  37.   {
  38.     m_pConnectionPoint->Unadvise( m_adviseCookie );
  39.   }
  40. }
  41.  
  42. void CXceedZipEvents::OnFinalRelease()
  43. {
  44.     // When the last reference for an automation object is released
  45.     // OnFinalRelease is called.  The base class will automatically
  46.     // deletes the object.  Add additional cleanup required for your
  47.     // object before calling the base class.
  48.  
  49.     CCmdTarget::OnFinalRelease();
  50. }
  51.  
  52.  
  53. BEGIN_MESSAGE_MAP(CXceedZipEvents, CCmdTarget)
  54.     //{{AFX_MSG_MAP(CXceedZipEvents)
  55.         // NOTE - the ClassWizard will add and remove mapping macros here.
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. // XCEED: For each event we want to handle, we add an entry here.
  60. //        Since we cheated and asked the ClassWizard to create a wrapper
  61. //        around _IXceedZipEvents, we can copy and paste from the
  62. //        xceedzip.h and xceedzip.cpp files the required stuff! 
  63. //        This is much useful for the parameter list and the event ID! q;-)
  64. BEGIN_DISPATCH_MAP(CXceedZipEvents, CCmdTarget)
  65.     //{{AFX_DISPATCH_MAP(CXceedZipEvents)
  66.     DISP_FUNCTION_ID(CXceedZipEvents, "GlobalStatus", 0x17d5, GlobalStatus, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I4 VTS_I2)
  67.   DISP_FUNCTION_ID(CXceedZipEvents, "SkippingFile", 0x17d6, SkippingFile, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_DATE VTS_DATE VTS_DATE VTS_I4 VTS_BOOL VTS_I4)
  68.   DISP_FUNCTION_ID(CXceedZipEvents, "Warning",      0x17d7, Warning,      VT_EMPTY, VTS_BSTR VTS_I4)
  69.   DISP_FUNCTION_ID(CXceedZipEvents, "InsertDisk",   0x1838, InsertDisk,   VT_EMPTY, VTS_I4 VTS_PBOOL)
  70.     //}}AFX_DISPATCH_MAP
  71. END_DISPATCH_MAP()
  72.  
  73. // Note: we add support for IID_IXceedZipEvents to support typesafe binding
  74. //  from VBA.  This IID must match the GUID that is attached to the 
  75. //  dispinterface in the .ODL file.
  76.  
  77. // XCEED: We changed the pregenerated GUID for this class, since we want to
  78. //        implement an existing interface. We tool the OLE view tool, found
  79. //        the _IXceedZipEvents interface, right-clicked on it and selected
  80. //        "Copy GUID to clipboard", which yeilds this:
  81. //        {DB797691-40E0-11D2-9BD5-0060082AE372}
  82.  
  83. //        So we changed the structure below accordingly.
  84. static const IID IID_IXceedZipEvents =
  85. { 0xDB797691, 0x40E0, 0x11D2, { 0x9B, 0xD5, 0x00, 0x60, 0x08, 0x2A, 0xE3, 0x72 } };
  86.  
  87. BEGIN_INTERFACE_MAP(CXceedZipEvents, CCmdTarget)
  88.     INTERFACE_PART(CXceedZipEvents, IID_IXceedZipEvents, Dispatch)
  89. END_INTERFACE_MAP()
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CXceedZipEvents utility methods
  93.  
  94. // XCEED: This code was inspired from article Q183599 is MSDN
  95. bool CXceedZipEvents::Connect( IDispatch* pDispatch )
  96. {
  97.   if( !pDispatch )
  98.   {
  99.     return false;
  100.   }
  101.  
  102.   // Reset stuff in case Connect called more than once
  103.   if( m_pConnectionPoint )
  104.   {
  105.     m_pConnectionPoint->Unadvise( m_adviseCookie );
  106.     m_pConnectionPoint  = NULL;
  107.   }
  108.  
  109.   // Get server's IConnectionPointContainer interface.
  110.   IConnectionPointContainer*  pConnPtContainer;
  111.  
  112.   HRESULT hr  = pDispatch->QueryInterface( IID_IConnectionPointContainer, 
  113.                                            (void **)&pConnPtContainer );
  114.   
  115.   if( FAILED( hr ) )
  116.   {
  117.     return false;
  118.   }
  119.  
  120.   // Find connection point for events we're interested in.
  121.   hr  = pConnPtContainer->FindConnectionPoint( IID_IXceedZipEvents,
  122.                                                &m_pConnectionPoint );
  123.   
  124.   if( FAILED( hr ) )
  125.   {
  126.     pConnPtContainer->Release();
  127.     return false;
  128.   }
  129.  
  130.   // Get the IUnknown interface of our event implementation.
  131.   LPUNKNOWN pUnk  = GetInterface( &IID_IUnknown );
  132.  
  133.   if( !pUnk )
  134.   {
  135.     pConnPtContainer->Release();
  136.     return false;
  137.   }
  138.  
  139.   // Setup advisory connection!
  140.   hr  = m_pConnectionPoint->Advise( pUnk, &m_adviseCookie );
  141.  
  142.   pConnPtContainer->Release();
  143.  
  144.   if( FAILED( hr ) )
  145.   {
  146.     return false;
  147.   }
  148.  
  149.   return true;
  150. }
  151.  
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CXceedZipEvents message handlers
  154.  
  155. void CXceedZipEvents::GlobalStatus(long lFilesTotal, long lFilesProcessed, long lFilesSkipped, short nFilesPercent, long lBytesTotal, long lBytesProcessed, long lBytesSkipped, short nBytesPercent, long lBytesOutput, short nCompressionRatio)
  156. {
  157.   if( m_pBar )
  158.   {
  159.     m_pBar->SetPos( nBytesPercent );
  160.   }
  161. }
  162. void CXceedZipEvents::SkippingFile(LPCTSTR sFilename, LPCTSTR sComment, LPCTSTR sFilenameOnDisk, long lSize, long lCompressedSize, long xAttributes, long lCRC, DATE dtLastModified, DATE dtLastAccessed, DATE dtCreated, long xMethod, BOOL bEncrypted, long xReason)
  163. {
  164.   if( m_pResults )
  165.   {
  166.     CString sMsg;
  167.  
  168.     sMsg.Format( "Skipping file %s for reason %d", sFilename, xReason );
  169.     m_pResults->AddString( sMsg );
  170.   }
  171. }
  172.  
  173. void CXceedZipEvents::Warning(LPCTSTR sFilename, long xWarning)
  174. {
  175.   if( m_pResults )
  176.   {
  177.     CString sMsg;
  178.  
  179.     sMsg.Format( "Warning %d on file %s", xWarning, sFilename );
  180.     m_pResults->AddString( sMsg );
  181.   }
  182. }
  183.  
  184. void CXceedZipEvents::InsertDisk(long lDiskNumber, BOOL* bDiskInserted)
  185. {
  186.   int nAnswer;
  187.  
  188.   if( lDiskNumber == 0 )
  189.   {
  190.     nAnswer = MessageBox( NULL, 
  191.                           "Cannot find the ending portion of the zip file. If this is a "
  192.                           "spanned zip file, please insert the last disk and press OK.", 
  193.                           "Insert disk", 
  194.                           MB_OKCANCEL );
  195.   }
  196.   else
  197.   {
  198.     CString sMsg;
  199.  
  200.     sMsg.Format( "Please insert disk #%d in drive.", lDiskNumber );
  201.     nAnswer = MessageBox( NULL, sMsg, "Insert disk", MB_OKCANCEL );
  202.   }
  203.  
  204.   *bDiskInserted  = ( nAnswer == IDOK );
  205. }
  206.