// ------------------------------------------------------------------------------------------------------------------------
//	Zip Studio 3.0 - Developer Edition
//	VC4Demo sample for Microsoft Visual C++ 4.0
//
//	Copyright Hexanet 1993-1996, All rights reserved
// ------------------------------------------------------------------------------------------------------------------------
//	Note:
//	To run VC4Demo.EXE you need ZS30W32.OCX and the Microsoft
//	DLLs: MSVCRT40.DLL, MFC40.DLL and OLEPRO32.DLL. (The
//	DLLs must be on the same directory or in WINDOWS/SYSTEM)
// ------------------------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include "VC4Demo.h"
#include "MainFrm.h"
#include "ZDoc.h"
#include "ZView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CZDoc

IMPLEMENT_DYNCREATE(CZDoc, CDocument)

BEGIN_MESSAGE_MAP(CZDoc, CDocument)
	//{{AFX_MSG_MAP(CZDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZDoc construction/destruction

CZDoc::CZDoc()
{
	// TODO: add one-time construction code here

}

CZDoc::~CZDoc()
{
}


// This feature is not supported
BOOL CZDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CZDoc serialization

void CZDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CZDoc diagnostics

#ifdef _DEBUG
void CZDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CZDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CZDoc commands


//	This function actually load a ZIP file using a ListView control
//	instead of a simple ListBox control. The ListView control has
//	the style LVS_SHAREIMAGELISTS because we will destroy the
//	HIMAGELIST thanks to the Zip Studio OCX <DestroyZIPITEMImageList>
//	method.
//	Notice that we don' t need to call <DestroyZIPITEMLParam> before
//	we build a new List but we need to do this when we destroy the ListView
//	(that is when we destroy our main View when we close this application).
//	Finally we need to provide a 'private' temporary directory which will
//	be used by <BuildZIPITEMList> to retrieve the Windows95 icons.

BOOL CZDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	/*TCHAR szOurTempDir[_MAX_PATH];
	GetTempPath( _MAX_PATH, szOurTempDir );
	if ( szOurTempDir[ lstrlen(szOurTempDir)-1 ] != '\\' )
		lstrcat( szOurTempDir, _T("\\") );
	lstrcat( szOurTempDir, _T("ZS30OCX") );
	CreateDirectory( szOurTempDir, NULL );
	AnsiToOem( szOurTempDir, szOurTempDir );
	*/
	
	if ( AfxGetMainWnd() )
		if ( ((CMainFrame*)AfxGetMainWnd())->GetActiveView() )
			if ( ((CZView*)( ((CMainFrame*)AfxGetMainWnd())->GetActiveView()))->m_zsctrl )
		{
		int i = ((CZView*)( ((CMainFrame*)AfxGetMainWnd())->GetActiveView()))->m_zsctrl.BuildZIPITEMList(
			lpszPathName, (long)GetListCtrlHwnd(), TRUE, _T(""), TRUE, 0, TRUE);
		if ( i < 0 )
			MessageBox(NULL, "Error while loading the ZIP files list", "", MB_OK);
		}
						   
	
	return TRUE;
}
