home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // LTSampleDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "LTSample.h"
- #include "VpWnd.h"
- #include "LTSampleDlg.h"
- #include "DlgProxy.h"
- #include "PropDialog.h"
- #include "SelOptPage.h"
- #include "QueryDialog.h"
- #include "AddSymbolDlg.h"
- #include "SmartObjectInserDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- const CLSID CLSID_Application = {0x6A481001,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
- const CLSID CLSID_XApplication = {0x6A481801,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
- const IID IID_Graphics = {0x6A48110A,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
- const IID IID_IDrawing = {0x6A481107,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- //}}AFX_VIRTUAL
-
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CLTSampleDlg dialog
-
- IMPLEMENT_DYNAMIC(CLTSampleDlg, CDialog);
-
- CLTSampleDlg::CLTSampleDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CLTSampleDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CLTSampleDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_pAutoProxy = NULL;
-
- m_pLocalApp = NULL;
- m_pInprocApp = NULL;
- m_pApp = NULL;
- m_iVersion = 0;
- }
-
- CLTSampleDlg::~CLTSampleDlg()
- {
- // If there is an automation proxy for this dialog, set
- // its back pointer to this dialog to NULL, so it knows
- // the dialog has been deleted.
- if (m_pAutoProxy != NULL)
- m_pAutoProxy->m_pDialog = NULL;
- }
-
- BEGIN_MESSAGE_MAP(CLTSampleDlg, CDialog)
- //{{AFX_MSG_MAP(CLTSampleDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_CLOSE()
- ON_BN_CLICKED(IDC_MERGEDRAWING, OnMergedrawing)
- ON_BN_CLICKED(IDC_OPENDRAWING, OnOpendrawing)
- ON_BN_CLICKED(IDC_PASTE, OnPaste)
- ON_BN_CLICKED(IDC_PROPERTYSYMBOL, OnPropertysymbol)
- ON_BN_CLICKED(IDC_SAVEDRAWING, OnSavedrawing)
- ON_BN_CLICKED(IDC_SELECTSYMBOL, OnSelectsymbol)
- ON_BN_CLICKED(IDC_CREATEAPP, OnCreateapp)
- ON_BN_CLICKED(IDC_SETVIEW, OnSetview)
- ON_BN_CLICKED(IDC_NEWDRAWING, OnNewdrawing)
- ON_BN_CLICKED(IDC_LOCALMODE, OnLocalmode)
- ON_BN_CLICKED(IDC_INPROCMODE, OnInprocmode)
- ON_BN_CLICKED(IDC_DRAWINGPROPERTY, OnDrawingProperty)
- ON_BN_CLICKED(IDC_CLOSEDRAWING, OnClosedrawing)
- ON_BN_CLICKED(IDC_EXPLODESYMBOL, OnExplodesymbol)
- ON_BN_CLICKED(IDC_QUERY, OnQuery)
- ON_BN_CLICKED(IDC_COPYSYMBOL, OnCopysymbol)
- ON_BN_CLICKED(IDC_ADDSYMBOL, OnAddsymbol)
- ON_BN_CLICKED(IDC_REMOVESYMBOL, OnDeletesymbol)
- ON_BN_CLICKED(IDC_APPPROPERTY, OnAppproperty)
- ON_BN_CLICKED(IDC_OPTIONS, OnOptions)
- ON_BN_CLICKED(IDC_GETBLOCK, OnGetblock)
- ON_BN_CLICKED(IDC_ZOOM_IN, OnZoomIn)
- ON_BN_CLICKED(IDC_ZOOM_OUT, OnZoomOut)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- void CLTSampleDlg::SyncToApplication(IApplication *pApp, BOOL bGetSelection)
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iCount = pDwgList->GetCount();
- IDrawing *pIDwg = NULL;
- for (int iItem = 0; iItem < iCount; iItem++)
- {
- pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
- if (pIDwg != NULL)
- pIDwg->Release();
- }
- pDwgList->ResetContent();
- }
-
- if (pApp != NULL)
- {
- BSTR bstrVersion = NULL;
- HRESULT hRes = pApp->get_Version(0, &bstrVersion);
- if (SUCCEEDED(hRes)
- && bstrVersion != NULL)
- {
- CString cstrBuild(bstrVersion);
- int iDot = cstrBuild.Find('.');
- CString cstrVersion = cstrBuild.Left(iDot);
- m_iVersion = atoi(cstrVersion);
- }
- else
- m_iVersion = 4;
-
- // Uncorrect reference counting of the Selection object
- // in SDK v 4.x - I have to correct it in the my sample
- if (bGetSelection
- && m_iVersion > 4)
- bGetSelection = FALSE;
-
- // Get the handle to the drawings collection
- Drawings* pDwgs = NULL;
- hRes = pApp->get_Drawings(&pDwgs);
- if (SUCCEEDED(hRes))
- {
- COleVariant varIndex;
- varIndex.vt = VT_I4;
-
- Selection *pSelection = NULL;
-
- for (varIndex.lVal = 0L; ; ++varIndex.lVal)
- {
- IDrawing* pIDwg = NULL;
- hRes = pDwgs->get_Item(&varIndex, &pIDwg);
- if (FAILED(hRes))
- break;
- AddDrawingToList(pDwgList, pIDwg);
-
- if (bGetSelection)
- {
- // correct reference count for the Selection object
- pIDwg->get_Selection(&pSelection);
- if (pSelection != NULL)
- {
- pSelection->AddRef();
- pSelection = NULL;
- }
- }
-
- pIDwg->Release();
- }
- pDwgs->Release();
- }
- }
- else
- m_iVersion = 0;
- CButton *pCreateAppBt = (CButton *)GetDlgItem(IDC_CREATEAPP);
- if (pCreateAppBt != NULL)
- pCreateAppBt->EnableWindow(pApp == NULL);
- }
-
- void CLTSampleDlg::AddDrawingToList(CComboBox *pDwgList, IDrawing *pIDwg)
- {
- if (pDwgList == NULL)
- return;
- if (pIDwg != NULL)
- {
- BSTR bstrName = NULL;
- HRESULT hRes = pIDwg->get_Name(&bstrName);
- if (SUCCEEDED(hRes))
- {
- ASSERT(bstrName != NULL);
- CString strName = bstrName;
- ::SysFreeString(bstrName);
- int iString = pDwgList->AddString(strName);
- pDwgList->SetCurSel(iString);
-
- pDwgList->SetItemDataPtr(iString, pIDwg);
- pIDwg->AddRef();
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CLTSampleDlg message handlers
-
- BOOL CLTSampleDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- m_wndView.SubclassDlgItem(IDC_TCVIEW, this);
-
- // Add "About..." menu item to system menu.
-
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
-
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- CButton *pButton = (CButton *)GetDlgItem(IDC_LOCALMODE);
- if (pButton != NULL
- && ::IsWindow(pButton->GetSafeHwnd()))
- pButton->SetCheck(1);
-
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CLTSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void CLTSampleDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CLTSampleDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- // Automation servers should not exit when a user closes the UI
- // if a controller still holds on to one of its objects. These
- // message handlers make sure that if the proxy is still in use,
- // then the UI is hidden but the dialog remains around if it
- // is dismissed.
-
- void CLTSampleDlg::OnClose()
- {
- if (CanExit())
- {
- CDialog::OnClose();
-
- m_wndView.SetView(NULL);
-
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iCount = pDwgList->GetCount();
- for (int iItem = 0; iItem < iCount; iItem++)
- {
- IDrawing *pIDwg = NULL;
- pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
- if (pIDwg != NULL)
- pIDwg->Release();
- }
- }
- if (m_pLocalApp != NULL)
- m_pLocalApp->Release();
- if (m_pInprocApp != NULL)
- m_pInprocApp->Release();
- }
- }
-
- void CLTSampleDlg::OnOK()
- {
- if (CanExit())
- CDialog::OnOK();
- }
-
- void CLTSampleDlg::OnCancel()
- {
- if (CanExit())
- CDialog::OnCancel();
- }
-
- BOOL CLTSampleDlg::CanExit()
- {
- // If the proxy object is still around, then the automation
- // controller is still holding on to this application. Leave
- // the dialog around, but hide its UI.
- if (m_pAutoProxy != NULL)
- {
- ShowWindow(SW_HIDE);
- return FALSE;
- }
-
- return TRUE;
- }
-
- static char BASED_CODE szFilter[] = "TurboCAD Drawing Files (*.tcw)|*.tcw|All Files (*.*)|*.*||";
-
- void CLTSampleDlg::OnMergedrawing()
- {
- if (m_pApp == NULL)
- {
- AfxMessageBox(IDS_CREATEAPPFIRST);
- return;
- }
-
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
-
- // Pointer to Drawings collection
- Drawings* pDwgs = NULL;
-
- // Pointer to drawing intrface
- IDrawing* pIDwgOpen = NULL;
-
- Properties *pProps = NULL;
- Property *pProp = NULL;
- Graphics *pGrs = NULL;
-
- Properties *pPropsOpen = NULL;
- Property *pPropOpen = NULL;
- Graphics *pGrsOpen = NULL;
-
- IGraphic *pIGr = NULL;
- BSTR bstrPath = NULL;
-
- // Make a "missing" optional parameter
- VARIANT varMissing;
- varMissing.vt = VT_ERROR;
- varMissing.scode = DISP_E_PARAMNOTFOUND;
-
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
- if (dlg.DoModal() != IDOK)
- return;
-
- // Get the handle to the drawings collection
- TRY
- {
-
- IDrawing *pIDwg = NULL;
- HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
- CHECK_HRESULT(hRes)
-
- // Get the file name into a BSTR
- CString strPath = dlg.GetPathName();
- bstrPath = strPath.AllocSysString();
-
- // Add the drawing to the drawings collection
- hRes = pDwgs->Open(bstrPath, &varMissing, &varMissing, &pIDwgOpen);
- CHECK_HRESULT(hRes)
-
- pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- COleVariant varPropName("TileMode");
- COleVariant varMode;
- COleVariant varOldMode;
-
- hRes = pIDwgOpen->get_Properties(&pPropsOpen);
- CHECK_HRESULT(hRes)
-
- hRes = pPropsOpen->get_Item(&varPropName, &pPropOpen);
- CHECK_HRESULT(hRes)
-
- hRes = pIDwg->get_Properties(&pProps);
- CHECK_HRESULT(hRes)
-
- hRes = pProps->get_Item(&varPropName, &pProp);
- CHECK_HRESULT(hRes)
-
- hRes = pProp->get_Value(0, &varMode);
- CHECK_HRESULT(hRes)
-
- varOldMode = varMode;
-
- hRes = pPropOpen->put_Value(0, &varMode);
- CHECK_HRESULT(hRes)
-
- hRes = pIDwgOpen->get_Graphics(&pGrsOpen);
- CHECK_HRESULT(hRes)
-
- long lCount = 0;
- hRes = pGrsOpen->get_Count(&lCount);
- CHECK_HRESULT(hRes)
-
- hRes = pIDwg->get_Graphics(&pGrs);
- CHECK_HRESULT(hRes)
-
- COleVariant varIndex((const long&)0);
-
- long lItem = 0;
- for (lItem = 0; lItem < lCount; lItem++)
- {
- hRes = pGrsOpen->Remove(&varIndex, &pIGr);
- CHECK_HRESULT(hRes)
-
- hRes = pGrs->AddGraphic(pIGr, &varMissing, &varMissing);
- CHECK_HRESULT(hRes)
- pIGr->Release();
- pIGr = NULL;
- }
-
- pGrsOpen->Release();
- pGrsOpen = NULL;
-
- pGrs->Release();
- pGrs = NULL;
-
- // merge next space
- if (varMode.iVal == 0)
- varMode.iVal = 1;
- else
- varMode.iVal = 0;
-
- hRes = pProp->put_Value(0, &varMode);
- CHECK_HRESULT(hRes)
-
- hRes = pPropOpen->put_Value(0, &varMode);
- CHECK_HRESULT(hRes)
-
- hRes = pIDwgOpen->get_Graphics(&pGrsOpen);
- CHECK_HRESULT(hRes)
-
- hRes = pGrsOpen->get_Count(&lCount);
- CHECK_HRESULT(hRes)
-
- hRes = pIDwg->get_Graphics(&pGrs);
- CHECK_HRESULT(hRes)
-
- for (lItem = 0; lItem < lCount; lItem++)
- {
- hRes = pGrsOpen->Remove(&varIndex,&pIGr);
- CHECK_HRESULT(hRes)
-
- hRes = pGrs->AddGraphic(pIGr, &varMissing, &varMissing);
- CHECK_HRESULT(hRes)
- pIGr->Release();
- pIGr = NULL;
- }
-
- }
- }
- CATCH_ALL(e)
- {
- }
- END_CATCH_ALL
- }
- else
- OnOpendrawing();
-
- if (bstrPath != NULL)
- ::SysFreeString(bstrPath);
-
- if (pIGr != NULL)
- pIGr->Release();
-
- if (pGrsOpen != NULL)
- pGrsOpen->Release();
-
- if (pPropOpen != NULL)
- pPropOpen->Release();
-
- if (pPropsOpen != NULL)
- pPropsOpen->Release();
-
- if (pGrs != NULL)
- pGrs->Release();
-
- if (pProp != NULL)
- pProp->Release();
-
- if (pProps != NULL)
- pProps->Release();
-
- if (pIDwgOpen != NULL)
- {
- pIDwgOpen->Close(&varMissing, &varMissing, &varMissing);
- pIDwgOpen->Release();
- }
-
- if (pDwgs != NULL)
- pDwgs->Release();;
-
- }
-
- void CLTSampleDlg::OnOpendrawing()
- {
- if (m_pApp == NULL)
- {
- AfxMessageBox(IDS_CREATEAPPFIRST);
- return;
- }
- CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
- if (dlg.DoModal() != IDOK)
- return;
-
- // Pointer to Drawings collection
- Drawings* pDwgs = NULL;
-
- // Get the handle to the drawings collection
- HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
- if (FAILED(hRes))
- {
- return;
- }
-
- // Pointer to drawing object
- IDrawing* pIDwg = NULL;
-
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Get the file name into a BSTR
- CString strPath = dlg.GetPathName();
- BSTR bstrPath = strPath.AllocSysString();
-
- // Add the drawing to the drawings collection
- hRes = pDwgs->Open(bstrPath, &var, &var, &pIDwg);
-
- // Free the system memory for the BSTR
- ::SysFreeString(bstrPath);
-
- if (SUCCEEDED(hRes))
- {
- CComboBox* pDwgsList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- AddDrawingToList(pDwgsList, pIDwg);
- pIDwg->Release();
- }
- else
- {
- // File was not opened. Maybe the filter gave us a reason.
- CString strDesc("Unknown");
-
- // Try to get thread-wide error object
- IErrorInfo* pErrorInfo = NULL;
- if (SUCCEEDED(::GetErrorInfo(0, &pErrorInfo)))
- {
- // Try to get description string
- BSTR bstrDesc = NULL;
- if (SUCCEEDED(pErrorInfo->GetDescription(&bstrDesc)))
- {
- strDesc = bstrDesc;
- ::SysFreeString(bstrDesc);
- }
- pErrorInfo->Release();
- }
-
- // Display failure message
- CString msg = "Could not open '" + strPath + "': " + strDesc;
- MessageBox(msg);
- }
-
- // Finished with drawings collection, decrement reference count
- pDwgs->Release();
-
- }
-
- void CLTSampleDlg::OnPaste()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- CButton *pPropBt = (CButton *)GetDlgItem(IDC_PASTE);
- pPropBt->EnableWindow(FALSE);
-
- HRESULT hRes = pIDwg->Paste();
- if (FAILED(hRes))
- AfxMessageBox(IDS_PASTEFAILED);
- pPropBt->EnableWindow(TRUE);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
- }
-
- void CLTSampleDlg::OnPropertysymbol()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
- pPropBt->EnableWindow(FALSE);
- Selection *pSelection = NULL;
- HRESULT hRes = pIDwg->get_Selection(&pSelection);
- if (SUCCEEDED(hRes))
- {
- long lCount;
- hRes = pSelection->get_Count(&lCount);
- if (SUCCEEDED(hRes))
- {
- if (lCount = 1)
- {
- IGraphic *pIGr = NULL;
- COleVariant varIndex((const long&)0);
-
- hRes = pSelection->get_Item(varIndex, &pIGr);
- if (SUCCEEDED(hRes))
- {
- Properties *pProps = NULL;
- hRes = pIGr->get_Properties(&pProps);
- if (SUCCEEDED(hRes))
- {
- CPropDialog dlgProp(pProps, this);
- if (dlgProp.DoModal() == IDOK)
- {
- }
- pProps->Release();
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- pIGr->Release();
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- pSelection->Release();
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- pPropBt->EnableWindow(TRUE);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
- }
-
- void CLTSampleDlg::OnSavedrawing()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- HRESULT hRes = S_OK;
- if (pDwgList != NULL)
- {
- CButton *pSaveBt = (CButton *)GetDlgItem(IDC_SAVEDRAWING);
- pSaveBt->EnableWindow(FALSE);
-
- int iItem = pDwgList->GetCurSel();
- if (iItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
- if (pIDwg != NULL)
- {
- CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
- if (dlg.DoModal() == IDOK)
- {
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Get the file name into a BSTR
- CString strPath = dlg.GetPathName();
- BSTR bstrPath = strPath.AllocSysString();
-
- HRESULT hRes = pIDwg->SaveAs(bstrPath, &var);
-
- // Free the system memory for the BSTR
- ::SysFreeString(bstrPath);
- }
- }
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- pSaveBt->EnableWindow(TRUE);
- }
- }
-
- void CLTSampleDlg::OnSelectsymbol()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- HRESULT hRes = S_OK;
- if (pDwgList != NULL)
- {
- CButton *pSelectBt = (CButton *)GetDlgItem(IDC_SELECTSYMBOL);
- if (pSelectBt->IsWindowEnabled())
- {
- int iItem = pDwgList->GetCurSel();
- if (iItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
- if (pIDwg != NULL)
- {
- Selection *pSel = NULL;
- hRes = pIDwg->get_Selection(&pSel);
- if (SUCCEEDED(hRes))
- {
- pSel->Unselect();
- pSel->Release();
- }
- }
- m_wndView.SetSelectMode();
- pSelectBt->EnableWindow(FALSE);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- else
- {
- pSelectBt->EnableWindow(TRUE);
- m_wndView.SetSelectMode();
- }
- }
- }
-
- void CLTSampleDlg::OnCreateapp()
- {
- CButton *pBtCreate = (CButton *)GetDlgItem(IDC_CREATEAPP);
- if (pBtCreate != NULL
- && ::IsWindow(pBtCreate->GetSafeHwnd()))
- pBtCreate->EnableWindow(FALSE);
-
- int iLocal = 0;
- CButton *pBtLocal = (CButton *)GetDlgItem(IDC_LOCALMODE);
- if (pBtLocal != NULL
- && ::IsWindow(pBtLocal->GetSafeHwnd()))
- iLocal = pBtLocal->GetCheck();
-
- int iInproc = 0;
- CButton *pBtInproc = (CButton *)GetDlgItem(IDC_INPROCMODE);
- if (pBtInproc != NULL
- && ::IsWindow(pBtInproc->GetSafeHwnd()))
- iInproc = pBtInproc->GetCheck();
-
- HRESULT hRes = S_OK;
- if (iLocal == 1)
- {
- ASSERT(iInproc != 1);
- if (m_pLocalApp == NULL)
- {
- IUnknown* pIUnk = NULL;
- hRes = ::GetActiveObject(CLSID_Application, NULL, &pIUnk);
- if (FAILED(hRes))
- {
- hRes = CoCreateInstance(CLSID_Application, //Class identifier (CLSID) of the object
- NULL, //Object is or isn't part of an aggregate
- CLSCTX_LOCAL_SERVER, //Context for running executable code
- IID_IUnknown, //Interface identifier
- (void**)&pIUnk //Points to requested interface pointer
- );
-
- if (FAILED(hRes))
- {
- AfxMessageBox(IDS_COULDNOTCREATELOCALSERVER);
- return;
- }
- }
-
- hRes = pIUnk->QueryInterface(IID_IApplication, (void**)&m_pLocalApp);
- pIUnk->Release();
- if (FAILED(hRes))
- {
- AfxMessageBox(IDS_OBJECTISNOTTURBOCADAPPLICATION);
- }
- }
- else
- AfxMessageBox(IDS_LOCALSERVERALREADYRUNNING);
- m_pApp = m_pLocalApp;
- }
- else if (iInproc == 1)
- {
- if (m_pInprocApp == NULL)
- {
- hRes = CoCreateInstance(CLSID_XApplication, //Class identifier (CLSID) of the object
- NULL, //Object is or isn't part of an aggregate
- CLSCTX_INPROC_SERVER, //Context for running executable code
- IID_IApplication, //Interface identifier
- (void**)&m_pInprocApp //Points to requested interface pointer
- );
-
- if (FAILED(hRes))
- AfxMessageBox(IDS_COULDNOTCREATEINPROCSERVER);
-
- }
- else
- AfxMessageBox(IDS_INPROCSERVERALREADYCREATED);
- m_pApp = m_pInprocApp;
- }
- else
- ASSERT(FALSE);
-
- // uncorrect reference counting of the Selection object
- // in SDK v 4.x - I have to correct it in the my sample
- // when create Application object
- SyncToApplication(m_pApp, TRUE);
- if (m_pApp != NULL)
- AfxMessageBox(IDS_APPCOMPLETE);
- }
-
-
- void CLTSampleDlg::OnSetview()
- {
-
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iItem = pDwgList->GetCurSel();
- if (iItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
- Views *pViews = NULL;
- HRESULT hRes = pIDwg->get_Views(&pViews);
- if (SUCCEEDED(hRes))
- {
- // Pointer to view object
- View* pView = NULL;
-
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Add the view to the collection
- hRes = pViews->Add(&var, &var, &pView);
-
- if (SUCCEEDED(hRes))
- {
- // Set up view to be the active view
- m_wndView.SetView(pView);
-
- // Finished with view, decrement reference count
- pView->Release();
- }
-
- // Finished with views, decrement reference count
- pViews->Release();
- }
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
-
- void CLTSampleDlg::OnNewdrawing()
- {
- if (m_pApp == NULL)
- {
- AfxMessageBox(IDS_CREATEAPPFIRST);
- return;
- }
-
- Drawings* pDwgs = NULL;
-
- // Get the handle to the drawings collection
- HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
- if (FAILED(hRes))
- {
- return;
- }
-
- // Pointer to drawing object
- IDrawing* pIDwg = NULL;
-
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Add the drawing to the drawings collection
- hRes = pDwgs->Add(&var, &pIDwg);
- if (SUCCEEDED(hRes))
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- AddDrawingToList(pDwgList, pIDwg);
- pIDwg->Release();
- }
-
- // Finished with drawings collection, decrement reference count
- pDwgs->Release();
- }
-
- void CLTSampleDlg::OnLocalmode()
- {
- m_pApp = m_pLocalApp;
- SyncToApplication(m_pApp);
- }
-
- void CLTSampleDlg::OnInprocmode()
- {
- m_pApp = m_pInprocApp;
- SyncToApplication(m_pApp);
- }
-
- void CLTSampleDlg::OnDrawingProperty()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- CButton *pPropBt = (CButton *)GetDlgItem(IDC_DRAWINGPROPERTY);
- pPropBt->EnableWindow(FALSE);
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- Properties *pProps = NULL;
- HRESULT hRes = pIDwg->get_Properties(&pProps);
- if (SUCCEEDED(hRes))
- {
- CPropDialog dlgProp(pProps, this);
- if (dlgProp.DoModal() == IDOK)
- {
- }
- pProps->Release();
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- }
- pPropBt->EnableWindow(TRUE);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
-
- void CLTSampleDlg::OnClosedrawing()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- CButton *pPropBt = (CButton *)GetDlgItem(IDC_DRAWINGPROPERTY);
- pPropBt->EnableWindow(FALSE);
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- IDrawing *pIDwgView = m_wndView.GetDrawing();
- if (pIDwgView == pIDwg)
- {
- m_wndView.SetView(NULL);
- m_wndView.Invalidate();
- m_wndView.UpdateWindow();
- pIDwgView->Release();
- }
-
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
- pIDwg->Close(&var, &var, &var);
- pIDwg->Release();
-
- pDwgList->DeleteString(iSelItem);
- pDwgList->SetCurSel(iSelItem - 1);
- }
- pPropBt->EnableWindow(TRUE);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
-
- void CLTSampleDlg::OnExplodesymbol()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- CButton *pExplBt = (CButton *)GetDlgItem(IDC_EXPLODESYMBOL);
- pExplBt->EnableWindow(FALSE);
- Selection *pSelection = NULL;
- HRESULT hRes = pIDwg->get_Selection(&pSelection);
- if (SUCCEEDED(hRes))
- {
- long lCount;
- hRes = pSelection->get_Count(&lCount);
- if (SUCCEEDED(hRes))
- {
- if (lCount = 1)
- {
- IGraphic *pIGr = NULL;
- COleVariant varIndex((const long&)0);
-
- hRes = pSelection->get_Item(varIndex, &pIGr);
- if (SUCCEEDED(hRes))
- {
- GraphicSet *pSet = NULL;
- hRes = pIGr->Explode(&pSet);
- if (SUCCEEDED(hRes))
- {
- pSet->Release();
- }
- else
- AfxMessageBox(IDS_CANNOTEXPLODEGRAPHIC);
- pIGr->Release();
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- pSelection->Release();
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- pExplBt->EnableWindow(TRUE);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
- }
-
- void CLTSampleDlg::OnQuery()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- CButton *pQueryBt = (CButton *)GetDlgItem(IDC_QUERY);
- pQueryBt->EnableWindow(FALSE);
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- Graphics *pGrs = NULL;
- HRESULT hRes = pIDwg->get_Graphics(&pGrs);
- if (SUCCEEDED(hRes))
- {
- CQueryDialog dlgQuery(this);
- if (dlgQuery.DoModal() == IDOK)
- {
- GraphicSet *pGrSet = NULL;
- BSTR bstrQuery = dlgQuery.m_cstrQueryString.AllocSysString();
- hRes = pGrs->QuerySet(bstrQuery, &pGrSet);
- if (SUCCEEDED(hRes))
- {
- if (pGrSet != NULL)
- {
- hRes = pGrSet->Select();
- if (SUCCEEDED(hRes))
- AfxMessageBox(IDS_QUERYSET_SUCCEEDED);
- else
- AfxMessageBox(IDS_CANNOTSELECTGRAPHIC);
- pGrSet->Release();
- }
- m_wndView.Invalidate();
- m_wndView.UpdateWindow();
- }
- else
- AfxMessageBox(IDS_QUERYSET_FAILED);
- ::SysFreeString(bstrQuery);
- }
- pGrs->Release();
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- }
- pQueryBt->EnableWindow(TRUE);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
-
- void CLTSampleDlg::OnCopysymbol()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- void CLTSampleDlg::OnAddsymbol()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- CAddSymbolDlg dlgAdd(this);
- if (dlgAdd.DoModal() == IDOK)
- {
- HRESULT hRes = S_OK;
- switch (dlgAdd.m_iInsert)
- {
- case 0:
- {
- RegenMethods *pRegens = NULL;
- hRes = m_pApp->get_RegenMethods(&pRegens);
- if (SUCCEEDED(hRes))
- {
- CSmartObjectInserDlg dlgInsert(pRegens, this);
- if (dlgInsert.DoModal())
- {
- VARIANT varMissing;
- ::VariantInit(&varMissing);
- varMissing.vt = VT_ERROR;
- varMissing.scode = DISP_E_PARAMNOTFOUND;
-
- VARIANT varType;
- ::VariantInit(&varType);
- varType.vt = VT_I4;
- varType.lVal = imsiPolyline;
-
- VARIANT varRegenType;
- ::VariantInit(&varRegenType);
- varRegenType.vt = VT_I4;
- varRegenType.lVal = dlgInsert.m_dwID;
-
- IGraphic *pIGr = NULL;
- Graphics *pGrs = NULL;
- hRes = pIDwg->get_Graphics(&pGrs);
- if (SUCCEEDED(hRes))
- {
-
- switch (dlgInsert.m_rmType)
- {
- case imsiAutomation:
- {
- hRes = pGrs->Add(&varType,
- &varRegenType,
- &varMissing,
- &varMissing,
- &varMissing,
- &varMissing,
- &pIGr);
- }
- break;
- case imsiVTbl:
- AfxMessageBox(IDS_NOTIMPLEMENTED);
- break;
- case imsiScript:
- AfxMessageBox(IDS_NOTIMPLEMENTED);
- break;
- }
- if (pIGr != NULL)
- pIGr->Release();
- pGrs->Release();
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- }
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- }
- break;
- case 1:
- default:
- AfxMessageBox(IDS_NOTIMPLEMENTED);
- break;
- }
- }
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
-
- void CLTSampleDlg::OnDeletesymbol()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
- pPropBt->EnableWindow(FALSE);
- Selection *pSelection = NULL;
- HRESULT hRes = pIDwg->get_Selection(&pSelection);
- if (SUCCEEDED(hRes))
- {
- long lCount;
- hRes = pSelection->get_Count(&lCount);
- if (SUCCEEDED(hRes))
- {
- IGraphic *pIGr = NULL;
- COleVariant varIndex((const long&)0);
-
- hRes = pSelection->get_Item(varIndex, &pIGr);
- if (SUCCEEDED(hRes))
- {
- long index;
- hRes = pIGr->get_Index(&index);
- if (SUCCEEDED(hRes))
- {
- IDispatch *pIDisp = NULL;
- hRes = pIGr->get_Parent(&pIDisp);
- if (SUCCEEDED(hRes))
- {
- Graphics *pGrs = NULL;
- IDrawing *pIDwg = NULL;
- hRes = pIDisp->QueryInterface(IID_IDrawing, (void **)&pIDwg);
- if (SUCCEEDED(hRes))
- hRes = pIDwg->get_Graphics(&pGrs);
- else
- hRes = pIDisp->QueryInterface(IID_Graphics, (void **)&pGrs);
- pIDisp->Release();
- if (SUCCEEDED(hRes))
- {
- varIndex = index;
- IGraphic *pIGrRemoved = NULL;
- hRes = pGrs->Remove(&varIndex, &pIGrRemoved);
- if (SUCCEEDED(hRes))
- {
- AfxMessageBox(IDS_SYMBOLREMOVEDFROMDRAWING);
- pIGrRemoved->Release();
- }
- pGrs->Release();
- }
- }
- }
- pIGr->Release();
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- pSelection->Release();
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- pPropBt->EnableWindow(TRUE);
- }
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
-
- void CLTSampleDlg::OnAppproperty()
- {
- if (m_pApp != NULL)
- {
- CButton *pAppPropsBt = (CButton *)GetDlgItem(IDC_APPPROPERTY);
- if (pAppPropsBt != NULL)
- pAppPropsBt->EnableWindow(FALSE);
- Properties *pProps = NULL;
- HRESULT hRes = m_pApp->get_Properties(&pProps);
- if (SUCCEEDED(hRes))
- {
- CPropDialog dlgProp(pProps, this);
- if (dlgProp.DoModal() == IDOK)
- {
- }
- pProps->Release();
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- if (pAppPropsBt != NULL)
- pAppPropsBt->EnableWindow(TRUE);
- }
- else
- AfxMessageBox(IDS_CREATEAPPFIRST);
-
- }
-
- void CLTSampleDlg::OnOptions()
- {
- CPropertySheet sheet("Options", this);
- CSelOptPage select;
-
- select.m_iVersion = m_iVersion;
- select.m_bTopLevel = m_wndView.m_varTopLevel.boolVal;
- select.m_bInvisible = m_wndView.m_varInvisible.boolVal;
- select.m_bSegments = m_wndView.m_varSegments.boolVal;
- select.m_bArcs = m_wndView.m_varArcs.boolVal;
- select.m_bTexts = m_wndView.m_varTexts.boolVal;
- select.m_bBlocks = m_wndView.m_varBlocks.boolVal;
-
- sheet.AddPage(&select);
- if (sheet.DoModal() == IDOK)
- {
- m_wndView.m_varTopLevel.boolVal = select.m_bTopLevel;
- m_wndView.m_varInvisible.boolVal = select.m_bInvisible;
- m_wndView.m_varSegments.boolVal = select.m_bSegments;
- m_wndView.m_varArcs.boolVal = select.m_bArcs;
- m_wndView.m_varTexts.boolVal = select.m_bTexts;
- m_wndView.m_varBlocks.boolVal = select.m_bBlocks;
- }
- }
-
- void CLTSampleDlg::OnGetblock()
- {
- CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
- if (pDwgList != NULL)
- {
- int iSelItem = pDwgList->GetCurSel();
- if (iSelItem >= 0)
- {
- IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
- if (pIDwg != NULL)
- {
- CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
- pPropBt->EnableWindow(FALSE);
- Selection *pSelection = NULL;
- HRESULT hRes = pIDwg->get_Selection(&pSelection);
- if (SUCCEEDED(hRes))
- {
- long lCount;
- hRes = pSelection->get_Count(&lCount);
- if (SUCCEEDED(hRes))
- {
- if (lCount = 1)
- {
- IGraphic *pIGr = NULL;
- COleVariant varIndex((const long&)0);
-
- hRes = pSelection->get_Item(varIndex, &pIGr);
- if (SUCCEEDED(hRes))
- {
- Block *pBlock = NULL;
- hRes = pIGr->get_Block(&pBlock);
- if (SUCCEEDED(hRes) && pBlock)
- {
- pBlock->Release();
- }
- else
- AfxMessageBox(IDS_CANNOTGETBLOCK);
- pIGr->Release();
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- }
- else
- AfxMessageBox(IDS_CANNOTGETCOLLECTION);
- pSelection->Release();
- }
- else
- AfxMessageBox(IDS_SELECTONESYMBOLONLY);
- pPropBt->EnableWindow(TRUE);
- }
- else
- AfxMessageBox(IDS_SELECTDRAWINGFIRST);
- }
- }
- }
-
- void CLTSampleDlg::OnZoomIn()
- {
- CString strStr;
- strStr.LoadString(IDS_ADDYOUR_CODE_HERE);
- AfxMessageBox(strStr);
- // TODO: Add your control notification handler code here
- }
-
- void CLTSampleDlg::OnZoomOut()
- {
- CString strStr;
- strStr.LoadString(IDS_ADDYOUR_CODE_HERE);
- AfxMessageBox(strStr);
- // TODO: Add your control notification handler code here
-
- }
-