ConvDwg2Kmg.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:5k
- // ConvDwg2Kmg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "ConvDwg2Kmg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CConvDwg2Kmg
- IMPLEMENT_DYNCREATE(CConvDwg2Kmg, CCmdTarget)
- CConvDwg2Kmg::CConvDwg2Kmg()
- {
- EnableAutomation();
-
- // To keep the application running as long as an OLE automation
- // object is active, the constructor calls AfxOleLockApp.
- AfxOleLockApp();
- }
- CConvDwg2Kmg::~CConvDwg2Kmg()
- {
- // To terminate the application when all objects created with
- // with OLE automation, the destructor calls AfxOleUnlockApp.
- AfxOleUnlockApp();
- }
- void CConvDwg2Kmg::OnFinalRelease()
- {
- // When the last reference for an automation object is released
- // OnFinalRelease is called. The base class will automatically
- // deletes the object. Add additional cleanup required for your
- // object before calling the base class.
- CCmdTarget::OnFinalRelease();
- }
- BEGIN_MESSAGE_MAP(CConvDwg2Kmg, CCmdTarget)
- //{{AFX_MSG_MAP(CConvDwg2Kmg)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BEGIN_DISPATCH_MAP(CConvDwg2Kmg, CCmdTarget)
- //{{AFX_DISPATCH_MAP(CConvDwg2Kmg)
- DISP_FUNCTION(CConvDwg2Kmg, "BeginConverter", BeginConverter, VT_BOOL, VTS_BSTR)
- DISP_FUNCTION(CConvDwg2Kmg, "EndConverter", EndConverter, VT_BOOL, VTS_NONE)
- DISP_FUNCTION(CConvDwg2Kmg, "ConverterDwg2Kmg", ConverterDwg2Kmg, VT_BOOL, VTS_BSTR VTS_BSTR VTS_I4)
- DISP_FUNCTION(CConvDwg2Kmg, "GetProgressInfo", GetProgressInfo, VT_BOOL, VTS_PR8 VTS_PBSTR)
- DISP_FUNCTION(CConvDwg2Kmg, "GetRegInt", GetRegInt, VT_I4, VTS_BSTR VTS_BSTR VTS_I4)
- DISP_FUNCTION(CConvDwg2Kmg, "GetRegStr", GetRegStr, VT_BSTR, VTS_BSTR VTS_BSTR VTS_BSTR)
- DISP_FUNCTION(CConvDwg2Kmg, "SetRegInt", SetRegInt, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_I4)
- DISP_FUNCTION(CConvDwg2Kmg, "SetRegStr", SetRegStr, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_BSTR)
- //}}AFX_DISPATCH_MAP
- END_DISPATCH_MAP()
- // Note: we add support for IID_IConvDwg2Kmg to support typesafe binding
- // from VBA. This IID must match the GUID that is attached to the
- // dispinterface in the .ODL file.
- // {859B1323-1130-4E4D-A3DA-BF73E9265A65}
- static const IID IID_IConvDwg2Kmg =
- { 0x859b1323, 0x1130, 0x4e4d, { 0xa3, 0xda, 0xbf, 0x73, 0xe9, 0x26, 0x5a, 0x65 } };
- BEGIN_INTERFACE_MAP(CConvDwg2Kmg, CCmdTarget)
- INTERFACE_PART(CConvDwg2Kmg, IID_IConvDwg2Kmg, Dispatch)
- END_INTERFACE_MAP()
- // {B4CAB403-44A6-4287-B9A3-3FE032C64134}
- IMPLEMENT_OLECREATE(CConvDwg2Kmg, "FileSwitch.ConvDwg2Kmg", 0xb4cab403, 0x44a6, 0x4287, 0xb9, 0xa3, 0x3f, 0xe0, 0x32, 0xc6, 0x41, 0x34)
- /////////////////////////////////////////////////////////////////////////////
- // CConvDwg2Kmg message handlers
- extern CFileSwitchApp theApp;
- extern CStdioFile g_CensorialFile; //监察转换进度的文件
- extern int g_mode;
- BOOL CConvDwg2Kmg::BeginConverter(LPCTSTR strRegistryKey)
- {
- m_pProgress=new CProgressInfo;
- m_pCommand=new CCommandInfo;
- m_pConverter=new CKmgConverter(m_pCommand);
- m_pReader=new CDwgReader(m_pProgress,m_pCommand,m_pConverter);
- theApp.SetUserRegistryKey(strRegistryKey);
- return m_pReader->BeginConvert();
- }
- BOOL CConvDwg2Kmg::EndConverter()
- {
- BOOL bSuccess=m_pReader->EndConvert();
- delete m_pProgress;
- delete m_pCommand;
- delete m_pReader;
- delete m_pConverter;
- return bSuccess;
- }
- BOOL CConvDwg2Kmg::ConverterDwg2Kmg(LPCTSTR strDwgFilename, LPCTSTR strKmgFilename, long hwnd)
- {
- m_pCommand->m_strSourceName=strDwgFilename;
- m_pCommand->m_strAimName=strKmgFilename;
- m_pCommand->m_hmainfrm=(HWND)hwnd;
- g_mode=0;
- //仅供测试 g_mode=1;
- //theApp.GetProfileInt("PARAMETER","CONVMODE",0);
- //if(g_mode!=1)
- //{
- // g_mode=0;
- //}
- //theApp.WriteProfileInt("PARAMETER","CONVMODE",0);
- _CONV_OPEN;
- BOOL bSucc;
- // try
- // {
- bSucc=m_pReader->Parse();
- // }
- // catch(...)
- // {
- // return FALSE;
- // }
- //_CONV_CLOSE;
- if(g_mode==2)
- {
- if(g_CensorialFile.m_pStream)
- {
- g_CensorialFile.Close();
- }
- g_mode=0;
- }
- return bSucc;
- }
- BOOL CConvDwg2Kmg::GetProgressInfo(double FAR* pdProgress, BSTR FAR* pstrProgressTip)
- {
- // TODO: Add your dispatch handler code here
- double dProgress;
- CString strProgressTip;
- if(m_pProgress==NULL)
- {
- return FALSE;
- }
- m_pProgress->GetProgressInfo(dProgress,strProgressTip);
- *pstrProgressTip=(BSTR FAR)(LPCTSTR)strProgressTip;
- *pdProgress=dProgress;
- return TRUE;
- }
- long CConvDwg2Kmg::GetRegInt(LPCTSTR strName1, LPCTSTR strName2, long iDefault)
- {
- // TODO: Add your dispatch handler code here
- return theApp.GetProfileInt(strName1,strName2,iDefault);
- }
- BSTR CConvDwg2Kmg::GetRegStr(LPCTSTR strName1, LPCTSTR strName2, LPCTSTR strDefault)
- {
- CString strResult;
- strResult=theApp.GetProfileString(strName1,strName2,strDefault);
- return strResult.AllocSysString();
- }
- void CConvDwg2Kmg::SetRegInt(LPCTSTR strName1, LPCTSTR strName2, long iValue)
- {
- theApp.WriteProfileInt(strName1,strName2,iValue);
- }
- void CConvDwg2Kmg::SetRegStr(LPCTSTR strName1, LPCTSTR strName2, LPCTSTR strValue)
- {
- theApp.WriteProfileString(strName1,strName2,strValue);
- }