ConvKmg2Dwg.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:4k
源码类别:

CAD

开发平台:

Visual C++

  1. // ConvKmg2Dwg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "FileSwitch.h"
  5. #include "ConvKmg2Dwg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CConvKmg2Dwg
  13. IMPLEMENT_DYNCREATE(CConvKmg2Dwg, CCmdTarget)
  14. CConvKmg2Dwg::CConvKmg2Dwg()
  15. {
  16. EnableAutomation();
  17. // To keep the application running as long as an OLE automation 
  18. // object is active, the constructor calls AfxOleLockApp.
  19. AfxOleLockApp();
  20. }
  21. CConvKmg2Dwg::~CConvKmg2Dwg()
  22. {
  23. // To terminate the application when all objects created with
  24. //  with OLE automation, the destructor calls AfxOleUnlockApp.
  25. AfxOleUnlockApp();
  26. }
  27. void CConvKmg2Dwg::OnFinalRelease()
  28. {
  29. // When the last reference for an automation object is released
  30. // OnFinalRelease is called.  The base class will automatically
  31. // deletes the object.  Add additional cleanup required for your
  32. // object before calling the base class.
  33. CCmdTarget::OnFinalRelease();
  34. }
  35. BEGIN_MESSAGE_MAP(CConvKmg2Dwg, CCmdTarget)
  36. //{{AFX_MSG_MAP(CConvKmg2Dwg)
  37. // NOTE - the ClassWizard will add and remove mapping macros here.
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. BEGIN_DISPATCH_MAP(CConvKmg2Dwg, CCmdTarget)
  41. //{{AFX_DISPATCH_MAP(CConvKmg2Dwg)
  42. DISP_FUNCTION(CConvKmg2Dwg, "BeginConverter", BeginConverter, VT_BOOL, VTS_BSTR)
  43. DISP_FUNCTION(CConvKmg2Dwg, "EndConverter", EndConverter, VT_BOOL, VTS_NONE)
  44. DISP_FUNCTION(CConvKmg2Dwg, "ConverterKmg2Dwg", ConverterKmg2Dwg, VT_BOOL, VTS_BSTR VTS_BSTR)
  45. DISP_FUNCTION(CConvKmg2Dwg, "GetProgressInfo", GetProgressInfo, VT_BOOL, VTS_PR8 VTS_PBSTR)
  46. //}}AFX_DISPATCH_MAP
  47. END_DISPATCH_MAP()
  48. // Note: we add support for IID_IConvKmg2Dwg to support typesafe binding
  49. //  from VBA.  This IID must match the GUID that is attached to the 
  50. //  dispinterface in the .ODL file.
  51. // {F2AAD484-E483-4C96-A865-CD4776307858}
  52. static const IID IID_IConvKmg2Dwg =
  53. { 0xf2aad484, 0xe483, 0x4c96, { 0xa8, 0x65, 0xcd, 0x47, 0x76, 0x30, 0x78, 0x58 } };
  54. BEGIN_INTERFACE_MAP(CConvKmg2Dwg, CCmdTarget)
  55. INTERFACE_PART(CConvKmg2Dwg, IID_IConvKmg2Dwg, Dispatch)
  56. END_INTERFACE_MAP()
  57. // {2848550E-02EB-448C-901D-CA7870DBA6CC}
  58. IMPLEMENT_OLECREATE(CConvKmg2Dwg, "FileSwitch.ConvKmg2Dwg", 0x2848550e, 0x2eb, 0x448c, 0x90, 0x1d, 0xca, 0x78, 0x70, 0xdb, 0xa6, 0xcc)
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CConvKmg2Dwg message handlers
  61. extern CFileSwitchApp theApp;
  62. extern CStdioFile g_CensorialFile; //监察转换进度的文件
  63. extern int g_mode;
  64. BOOL CConvKmg2Dwg::BeginConverter(LPCTSTR strRegistryKey) 
  65. {
  66. m_pProgress=new CProgressInfo; 
  67. m_pCommand=new CCommandInfo;  
  68. m_pConverter=new CDwgConverter(m_pCommand); 
  69. m_pReader=new CKmgReader(m_pProgress,m_pCommand,m_pConverter);       
  70. theApp.SetUserRegistryKey(strRegistryKey);
  71. return m_pReader->BeginConvert();
  72. }
  73. BOOL CConvKmg2Dwg::EndConverter() 
  74. {
  75. BOOL bSuccess=m_pReader->EndConvert();
  76. delete m_pProgress; 
  77. delete m_pCommand;  
  78. delete m_pReader;       
  79. delete m_pConverter;    
  80. return bSuccess;
  81. }
  82. BOOL CConvKmg2Dwg::ConverterKmg2Dwg(LPCTSTR strKmgFilename, LPCTSTR strDwgFilename) 
  83. {
  84. m_pCommand->m_strSourceName=strKmgFilename;
  85. m_pCommand->m_strAimName=strDwgFilename;
  86. // m_pCommand->m_hmainfrm=(HWND)hwnd;
  87. g_mode=0;
  88. //theApp.GetProfileInt("PARAMETER","CONVMODE",0);
  89. //if(g_mode!=1)
  90. //{
  91. // g_mode=0;
  92. //}
  93. //theApp.WriteProfileInt("PARAMETER","CONVMODE",0);
  94. _CONV_OPEN;
  95. BOOL bSucc=m_pReader->Parse();
  96. _CONV_CLOSE;
  97. return bSucc;
  98. }
  99. BOOL CConvKmg2Dwg::GetProgressInfo(double FAR* pdProgress, BSTR FAR* pstrProgressTip) 
  100. {
  101. double dProgress;
  102. CString strProgressTip;
  103. if(m_pProgress==NULL)
  104. {
  105. return FALSE;
  106. }
  107. m_pProgress->GetProgressInfo(dProgress,strProgressTip);
  108. *pstrProgressTip=(BSTR FAR)(LPCTSTR)strProgressTip;
  109. *pdProgress=dProgress;
  110. return TRUE;
  111. }