// 34.cpp : DLL _xZkqqHx_jHhAiCmMiPiJiKpKiJlLiPiIjHjNiCmMjCoIiLgAiCpAiNhDiCkCiCnMiClHiBeC_xHqqkZx_
//

#include "stdafx.h"
#include "resource.h"		// For IDR_MAINFRAME.
#include "3HeaderInf.h"		// For MC3HeaderInf.
#include "3Document.h"		// For MC3Document.

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

static double myCalcDisplayPPM ();

short			g_nVersion = -1;

// 06.05.12 Fukushiro M. 1_xZkqqHx_iNhDiNoNiPjM_xHqqkZx_ ()
//IMpgMolipMain*	g_pMolipMainI = NULL;

const double	g_dDisplayPPM = myCalcDisplayPPM();

//----- 06.05.12 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
//class FC3File : public CFile
//{
//public:
//	FC3File (MfcFile* pFile = NULL) : m_pMfcFile(pFile) {}
//	virtual ULONGLONG GetPosition() const { return m_pMfcFile->GetPosition(); }
//	virtual CString GetFileName() const { return (LPCTSTR)m_pMfcFile->GetFileName(); }
//	virtual CString GetFileTitle() const { return (LPCTSTR)m_pMfcFile->GetFileTitle(); }
//	virtual CString GetFilePath() const { return (LPCTSTR)m_pMfcFile->GetFilePath(); }
//	virtual void SetFilePath(LPCTSTR lpszNewName) { m_pMfcFile->SetFilePath(lpszNewName); }
//
//// Operations
//	virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL)
//				{ return m_pMfcFile->Open(lpszFileName, nOpenFlags, NULL); }
//
////	virtual CFile* Duplicate() const { return m_pMfcFile->Duplicate(); }
//
//	virtual ULONGLONG Seek(LONGLONG lOff, UINT nFrom) { return m_pMfcFile->Seek((LONG)lOff, nFrom); }
//	virtual void SetLength(ULONGLONG dwNewLen) { m_pMfcFile->SetLength((DWORD)dwNewLen); }
//	virtual ULONGLONG GetLength() const { return m_pMfcFile->GetLength(); }
//
//	virtual UINT Read(void* lpBuf, UINT nCount) { return m_pMfcFile->Read(lpBuf, nCount); }
//	virtual void Write(const void* lpBuf, UINT nCount) { m_pMfcFile->Write(lpBuf, nCount); }
//
//	virtual void LockRange(ULONGLONG dwPos, ULONGLONG dwCount) { m_pMfcFile->LockRange((DWORD)dwPos, (DWORD)dwCount); }
//	virtual void UnlockRange(ULONGLONG dwPos, ULONGLONG dwCount) { m_pMfcFile->UnlockRange((DWORD)dwPos, (DWORD)dwCount); }
//
//	virtual void Abort() { m_pMfcFile->Abort(); }
//	virtual void Flush() { m_pMfcFile->Flush(); }
//	virtual void Close() { m_pMfcFile->Close(); }
//
//// Implementation
//public:
//	virtual ~FC3File() {}
//	virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0, void** ppBufStart = NULL, void** ppBufMax = NULL)
//		{ return m_pMfcFile->GetBufferPtr(nCommand, nCount, ppBufStart, ppBufMax); }
//
//protected:
//	MfcFile*	m_pMfcFile;
//};
//----- 06.05.12 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----

static double myCalcDisplayPPM ()
{
	// _xZkqqHx_iDgGiDeCiDfIiDhGiDiMiDeDiCmM_xHqqkZx_HDC_xZkqqHx_iCpAiNoMjAkMiBeC_xHqqkZx_
	HDC hAttribDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	if (hAttribDC == NULL) return 0.0;
	double dDisplayPPM = (double)GetDeviceCaps(hAttribDC, LOGPIXELSX) / 25.4;
	// HDC_xZkqqHx_iCpAiNoNiPjMiBeC_xHqqkZx_
	::DeleteDC(hAttribDC);
	return dDisplayPPM;
}


/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	Convert3To4
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhEiDiJiDgCiDgHiDfCiDeBiCfC_xHqqkZx_ -> _xZkqqHx_iDhEiDiJiDgCiDgHiDfCiDeBiCfD_xHqqkZx_ _xZkqqHx_iCmMjFmPiKlHiCpAiNhDiCkEiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	fileFrom	:_xZkqqHx_jDmHiCnNiPgPiClFiMlDiCmMiDeBiBfLiDeKiDeDiDhFiCpAiOhHjCoIiBeC_xHqqkZx_
 *			fileTo		:_xZkqqHx_iPjBiCkLiNjOiCnNjAoGiCmMiDeBiBfLiDeKiDeDiDhFiCpAiOhHjCoIiBeC_xHqqkZx_
 *			formTo		:_xZkqqHx_iPjBiCkLiNjOiCnNiCmMiDhHiDgCiDfPiCmJiLeMiPhBiClDiCoKiCoJjFlGiPjBiMfOiCpAiOhHjCoIiBeC_xHqqkZx_FD_DTP_NONE _xZkqqHx_iCkK_xHqqkZx_
 *						 _xZkqqHx_iOhHjCoIiClDiCoKiClNiPoKiNiHiCmNjDmHiCnNiPgPiClFiMlDiCmMjFlGiPjBiMfOiCmJiPiHiClIiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.06.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void Convert3To4 (MfcFile* fileFrom, MfcFile* fileTo, FTDocumentFormat formTo)
{
	// _xZkqqHx_iDgPiBfLiDfHiDiHiDjDiCpAiOhHjCoIiBeC_xHqqkZx_
	g_nVersion = 3;

	// _xZkqqHx_jAfGiClFiCkCiDgIiDeMiDiFiDiBiDjDiDgHiCpAiNoMjAkMiBeC_xHqqkZx_
	g_pDoc = (MC3Document*)RUNTIME_CLASS(MC3Document)->CreateObject();
	CSingleDocTemplate docTemplate(	IDR_MAINFRAME,
									RUNTIME_CLASS(MC3Document),
									RUNTIME_CLASS(CFrameWnd),
									RUNTIME_CLASS(CView));
	docTemplate.AddDocument(g_pDoc);
	COleTemplateServer server;
	static const CLSID clsid = DYNAMIC_DRAW_CLSID;
	server.ConnectTemplate(clsid, &docTemplate, TRUE);
	// _xZkqqHx_iDgIiDeMiDiFiDiBiDjDiDgHiCpAiPiJiKpKiJlLiBeC_xHqqkZx_
	g_pDoc->OnNewDocument();

	CFCMfcFile fileFrom3(fileFrom);
	CArchive arFrom(&fileFrom3, CArchive::load);
	arFrom.m_pDocument = g_pDoc;

	// _xZkqqHx_iDfIiDgHiDiKiBfLiDiAiCpAjDmHiCnNiPgPiClHiBeC_xHqqkZx_
	g_pDoc->InStreamCore(arFrom);

	// _xZkqqHx_iDgPiBfLiDfHiDiHiDjDiCpAiOhHjCoIiBeC_xHqqkZx_
	g_nVersion = 4;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiMfOiCpAiOhHjCoIiBeC_xHqqkZx_
	if (formTo != FD_DTP_NONE) g_pDoc->SetFileType(formTo);

	CFCMfcFile fileTo4(fileTo);
	CArchive arTo(&fileTo4, CArchive::store);
	arTo.m_pDocument = g_pDoc;
	// _xZkqqHx_iDfIiDgHiDiKiBfLiDiAiCpAiPjBiCkLiNjOiCnOiBeC_xHqqkZx_
	g_pDoc->OutStreamCore(arTo);

	// _xZkqqHx_iNoMjAkMiClFiClNiDgIiDeMiDiFiDiBiDjDiDgHiCpAiNoNiPjMiBeC_xHqqkZx_
	delete g_pDoc;
	g_pDoc = NULL;

	// _xZkqqHx_iDgPiBfLiDfHiDiHiDjDiCpAiDiKiDfKiDgCiDgHiBeC_xHqqkZx_
	g_nVersion = -1;
} // Convert3To4.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	Convert4To3
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhEiDiJiDgCiDgHiDfCiDeBiCfD_xHqqkZx_ -> _xZkqqHx_iDhEiDiJiDgCiDgHiDfCiDeBiCfC_xHqqkZx_ _xZkqqHx_iCmMjFmPiKlHiCpAiNhDiCkEiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	fileFrom	:_xZkqqHx_jDmHiCnNiPgPiClFiMlDiCmMiDeBiBfLiDeKiDeDiDhFiCpAiOhHjCoIiBeC_xHqqkZx_
 *			fileTo		:_xZkqqHx_iPjBiCkLiNjOiCnNjAoGiCmMiDeBiBfLiDeKiDeDiDhFiCpAiOhHjCoIiBeC_xHqqkZx_
 *			formTo		:_xZkqqHx_iPjBiCkLiNjOiCnNiCmMiDhHiDgCiDfPiCmJiLeMiPhBiClDiCoKiCoJjFlGiPjBiMfOiCpAiOhHjCoIiBeC_xHqqkZx_FD_DTP_NONE _xZkqqHx_iCkK_xHqqkZx_
 *						 _xZkqqHx_iOhHjCoIiClDiCoKiClNiPoKiNiHiCmNjDmHiCnNiPgPiClFiMlDiCmMjFlGiPjBiMfOiCmJiPiHiClIiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.06.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void Convert4To3 (MfcFile* fileFrom, MfcFile* fileTo, FTDocumentFormat formTo)
{
	// _xZkqqHx_iDgPiBfLiDfHiDiHiDjDiCpAiOhHjCoIiBeC_xHqqkZx_
	g_nVersion = 4;

	// _xZkqqHx_jAfGiClFiCkCiDgIiDeMiDiFiDiBiDjDiDgHiCpAiNoMjAkMiBeC_xHqqkZx_
	g_pDoc = (MC3Document*)RUNTIME_CLASS(MC3Document)->CreateObject();
	CSingleDocTemplate docTemplate(	IDR_MAINFRAME,
									RUNTIME_CLASS(MC3Document),
									RUNTIME_CLASS(CFrameWnd),
									RUNTIME_CLASS(CView));
	docTemplate.AddDocument(g_pDoc);
	COleTemplateServer server;
	static const CLSID clsid = DYNAMIC_DRAW_CLSID;
	server.ConnectTemplate(clsid, &docTemplate, TRUE);
	// _xZkqqHx_iDgIiDeMiDiFiDiBiDjDiDgHiCpAiPiJiKpKiJlLiBeC_xHqqkZx_
	g_pDoc->OnNewDocument();

	CFCMfcFile fileFrom4(fileFrom);
	CArchive arFrom(&fileFrom4, CArchive::load);
	arFrom.m_pDocument = g_pDoc;

	// _xZkqqHx_iDfIiDgHiDiKiBfLiDiAiCpAjDmHiCnNiPgPiClHiBeC_xHqqkZx_
	g_pDoc->InStreamCore(arFrom);

	// _xZkqqHx_iDgPiBfLiDfHiDiHiDjDiCpAiOhHjCoIiBeC_xHqqkZx_
	g_nVersion = 3;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiMfOiCpAiOhHjCoIiBeC_xHqqkZx_
	if (formTo != FD_DTP_NONE) g_pDoc->SetFileType(formTo);

	CFCMfcFile fileTo3(fileTo);
	CArchive arTo(&fileTo3, CArchive::store);
	arTo.m_pDocument = g_pDoc;
	// _xZkqqHx_iDfIiDgHiDiKiBfLiDiAiCpAiPjBiCkLiNjOiCnOiBeC_xHqqkZx_
	g_pDoc->OutStreamCore(arTo);

	// _xZkqqHx_iNoMjAkMiClFiClNiDgIiDeMiDiFiDiBiDjDiDgHiCpAiNoNiPjMiBeC_xHqqkZx_
	delete g_pDoc;
	g_pDoc = NULL;

	// _xZkqqHx_iDgPiBfLiDfHiDiHiDjDiCpAiDiKiDfKiDgCiDgHiBeC_xHqqkZx_
	g_nVersion = -1;
} // Convert3To4.

//----- 06.05.12 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
//void operator << (CArchive& ar, const DBLPoint& mmpt)
//{
//	ar.Write(&mmpt, sizeof(mmpt));
//}
//
//void operator << (CArchive& ar, const DBLRect& mmrt)
//{
//	ar.Write(&mmrt, sizeof(mmrt));
//}
//
//void operator << (CArchive& ar, const CLSID& clsid)
//{
//	ar.Write(&clsid, sizeof(clsid));
//}
//
//void operator >> (CArchive& ar, DBLPoint& mmpt)
//{
//	ar.Read(&mmpt, sizeof(mmpt));
//}
//
//void operator >> (CArchive& ar, DBLRect& mmrt)
//{
//	ar.Read(&mmrt, sizeof(mmrt));
//}
//
//void operator >> (CArchive& ar, CLSID& clsid)
//{
//	ar.Read(&clsid, sizeof(clsid));
//}
//
//void FFReadString (CArchive& ar, WString& wstr)
//{
//	WORD wLen;
//	ar >> wLen;
//	vector<wchar_t> wvBuff(wLen);
//	ar.Read(&wvBuff.front(), wLen * sizeof(wchar_t));
//	wvBuff.push_back(L'\0');
//	wstr = &wvBuff.front();
//}
//
//void FFWriteString (CArchive& ar, const WString& wstr)
//{
//	ar << WORD(wstr.length());
//	ar.Write(wstr.c_str(), UINT(wstr.length() * sizeof(wchar_t)));
//}
//
//----- 06.05.12 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----
