home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F36938_LTSampleDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-16  |  36.3 KB  |  1,478 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // LTSampleDlg.cpp : implementation file
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "LTSample.h"
  16. #include "VpWnd.h"
  17. #include "LTSampleDlg.h"
  18. #include "DlgProxy.h"
  19. #include "PropDialog.h"
  20. #include "SelOptPage.h"
  21. #include "QueryDialog.h"
  22. #include "AddSymbolDlg.h"
  23. #include "SmartObjectInserDlg.h"
  24.  
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. const CLSID CLSID_Application  = {0x6A481001,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  32. const CLSID CLSID_XApplication = {0x6A481801,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  33.  
  34. const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  35. const IID IID_Graphics = {0x6A48110A,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  36. const IID IID_IDrawing = {0x6A481107,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CAboutDlg dialog used for App About
  40.  
  41. class CAboutDlg : public CDialog
  42. {
  43. public:
  44.     CAboutDlg();
  45.  
  46. // Dialog Data
  47.     //{{AFX_DATA(CAboutDlg)
  48.     enum { IDD = IDD_ABOUTBOX };
  49.     //}}AFX_DATA
  50.  
  51.     // ClassWizard generated virtual function overrides
  52.     //{{AFX_VIRTUAL(CAboutDlg)
  53.     //}}AFX_VIRTUAL
  54.  
  55. // Implementation
  56. protected:
  57.     //{{AFX_MSG(CAboutDlg)
  58.     //}}AFX_MSG
  59.     DECLARE_MESSAGE_MAP()
  60. };
  61.  
  62. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  63. {
  64.     //{{AFX_DATA_INIT(CAboutDlg)
  65.     //}}AFX_DATA_INIT
  66. }
  67.  
  68.  
  69. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  70.     //{{AFX_MSG_MAP(CAboutDlg)
  71.         // No message handlers
  72.     //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CLTSampleDlg dialog
  77.  
  78. IMPLEMENT_DYNAMIC(CLTSampleDlg, CDialog);
  79.  
  80. CLTSampleDlg::CLTSampleDlg(CWnd* pParent /*=NULL*/)
  81.     : CDialog(CLTSampleDlg::IDD, pParent)
  82. {
  83.     //{{AFX_DATA_INIT(CLTSampleDlg)
  84.         // NOTE: the ClassWizard will add member initialization here
  85.     //}}AFX_DATA_INIT
  86.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  87.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  88.     m_pAutoProxy = NULL;
  89.  
  90.     m_pLocalApp = NULL;
  91.     m_pInprocApp = NULL;
  92.     m_pApp = NULL;
  93.     m_iVersion = 0;
  94. }
  95.  
  96. CLTSampleDlg::~CLTSampleDlg()
  97. {
  98.     // If there is an automation proxy for this dialog, set
  99.     //  its back pointer to this dialog to NULL, so it knows
  100.     //  the dialog has been deleted.
  101.     if (m_pAutoProxy != NULL)
  102.         m_pAutoProxy->m_pDialog = NULL;
  103. }
  104.  
  105. BEGIN_MESSAGE_MAP(CLTSampleDlg, CDialog)
  106.     //{{AFX_MSG_MAP(CLTSampleDlg)
  107.     ON_WM_SYSCOMMAND()
  108.     ON_WM_PAINT()
  109.     ON_WM_QUERYDRAGICON()
  110.     ON_WM_CLOSE()
  111.     ON_BN_CLICKED(IDC_MERGEDRAWING, OnMergedrawing)
  112.     ON_BN_CLICKED(IDC_OPENDRAWING, OnOpendrawing)
  113.     ON_BN_CLICKED(IDC_PASTE, OnPaste)
  114.     ON_BN_CLICKED(IDC_PROPERTYSYMBOL, OnPropertysymbol)
  115.     ON_BN_CLICKED(IDC_SAVEDRAWING, OnSavedrawing)
  116.     ON_BN_CLICKED(IDC_SELECTSYMBOL, OnSelectsymbol)
  117.     ON_BN_CLICKED(IDC_CREATEAPP, OnCreateapp)
  118.     ON_BN_CLICKED(IDC_SETVIEW, OnSetview)
  119.     ON_BN_CLICKED(IDC_NEWDRAWING, OnNewdrawing)
  120.     ON_BN_CLICKED(IDC_LOCALMODE, OnLocalmode)
  121.     ON_BN_CLICKED(IDC_INPROCMODE, OnInprocmode)
  122.     ON_BN_CLICKED(IDC_DRAWINGPROPERTY, OnDrawingProperty)
  123.     ON_BN_CLICKED(IDC_CLOSEDRAWING, OnClosedrawing)
  124.     ON_BN_CLICKED(IDC_EXPLODESYMBOL, OnExplodesymbol)
  125.     ON_BN_CLICKED(IDC_QUERY, OnQuery)
  126.     ON_BN_CLICKED(IDC_COPYSYMBOL, OnCopysymbol)
  127.     ON_BN_CLICKED(IDC_ADDSYMBOL, OnAddsymbol)
  128.     ON_BN_CLICKED(IDC_REMOVESYMBOL, OnDeletesymbol)
  129.     ON_BN_CLICKED(IDC_APPPROPERTY, OnAppproperty)
  130.     ON_BN_CLICKED(IDC_OPTIONS, OnOptions)
  131.     ON_BN_CLICKED(IDC_GETBLOCK, OnGetblock)
  132.     ON_BN_CLICKED(IDC_ZOOM_IN, OnZoomIn)
  133.     ON_BN_CLICKED(IDC_ZOOM_OUT, OnZoomOut)
  134.     //}}AFX_MSG_MAP
  135. END_MESSAGE_MAP()
  136.  
  137. void CLTSampleDlg::SyncToApplication(IApplication *pApp, BOOL bGetSelection)
  138. {
  139.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  140.     if (pDwgList != NULL)        
  141.     {
  142.         int iCount = pDwgList->GetCount();
  143.         IDrawing *pIDwg = NULL;
  144.         for (int iItem = 0; iItem < iCount; iItem++)
  145.         {
  146.             pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  147.             if (pIDwg != NULL)
  148.                 pIDwg->Release();
  149.         }
  150.         pDwgList->ResetContent();
  151.     }
  152.  
  153.     if (pApp != NULL)
  154.     {
  155.         BSTR bstrVersion = NULL;
  156.         HRESULT hRes = pApp->get_Version(0, &bstrVersion);
  157.         if (SUCCEEDED(hRes)
  158.             && bstrVersion != NULL)
  159.         {
  160.             CString cstrBuild(bstrVersion);
  161.             int iDot = cstrBuild.Find('.');
  162.             CString cstrVersion = cstrBuild.Left(iDot);
  163.             m_iVersion = atoi(cstrVersion);
  164.         }
  165.         else
  166.             m_iVersion = 4;
  167.  
  168.         // Uncorrect reference counting of the Selection object
  169.         //  in SDK v 4.x - I have to correct it in the my sample
  170.         if (bGetSelection
  171.             && m_iVersion > 4)
  172.             bGetSelection = FALSE;
  173.         
  174.         // Get the handle to the drawings collection
  175.         Drawings* pDwgs = NULL;
  176.         hRes = pApp->get_Drawings(&pDwgs);
  177.         if (SUCCEEDED(hRes))
  178.         {
  179.             COleVariant varIndex;
  180.             varIndex.vt = VT_I4;
  181.  
  182.             Selection *pSelection = NULL;
  183.  
  184.             for (varIndex.lVal = 0L; ; ++varIndex.lVal)
  185.             {
  186.                 IDrawing* pIDwg = NULL;
  187.                 hRes = pDwgs->get_Item(&varIndex, &pIDwg);
  188.                 if (FAILED(hRes))
  189.                     break;
  190.                 AddDrawingToList(pDwgList, pIDwg);
  191.                 
  192.                 if (bGetSelection)
  193.                 {
  194.                     // correct reference count for the Selection object
  195.                     pIDwg->get_Selection(&pSelection);
  196.                     if (pSelection != NULL)
  197.                     {
  198.                         pSelection->AddRef();
  199.                         pSelection = NULL;
  200.                     }
  201.                 }
  202.  
  203.                 pIDwg->Release();
  204.             }
  205.             pDwgs->Release();
  206.         }
  207.     }
  208.     else
  209.         m_iVersion = 0;
  210.     CButton *pCreateAppBt = (CButton *)GetDlgItem(IDC_CREATEAPP);
  211.     if (pCreateAppBt != NULL)
  212.         pCreateAppBt->EnableWindow(pApp == NULL);
  213. }
  214.  
  215. void CLTSampleDlg::AddDrawingToList(CComboBox *pDwgList, IDrawing *pIDwg)
  216. {
  217.     if (pDwgList == NULL)
  218.         return;
  219.     if (pIDwg != NULL)
  220.     {
  221.         BSTR bstrName = NULL;
  222.         HRESULT hRes = pIDwg->get_Name(&bstrName);
  223.         if (SUCCEEDED(hRes))
  224.         {
  225.             ASSERT(bstrName != NULL);
  226.             CString strName = bstrName;
  227.             ::SysFreeString(bstrName);
  228.             int iString = pDwgList->AddString(strName);
  229.             pDwgList->SetCurSel(iString);
  230.  
  231.             pDwgList->SetItemDataPtr(iString, pIDwg);
  232.             pIDwg->AddRef();
  233.         }
  234.     }
  235. }
  236. /////////////////////////////////////////////////////////////////////////////
  237. // CLTSampleDlg message handlers
  238.  
  239. BOOL CLTSampleDlg::OnInitDialog()
  240. {
  241.     CDialog::OnInitDialog();
  242.  
  243.     m_wndView.SubclassDlgItem(IDC_TCVIEW, this);
  244.  
  245.     // Add "About..." menu item to system menu.
  246.  
  247.     // IDM_ABOUTBOX must be in the system command range.
  248.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  249.     ASSERT(IDM_ABOUTBOX < 0xF000);
  250.  
  251.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  252.     if (pSysMenu != NULL)
  253.     {
  254.         CString strAboutMenu;
  255.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  256.         if (!strAboutMenu.IsEmpty())
  257.         {
  258.             pSysMenu->AppendMenu(MF_SEPARATOR);
  259.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  260.         }
  261.     }
  262.  
  263.     // Set the icon for this dialog.  The framework does this automatically
  264.     //  when the application's main window is not a dialog
  265.     SetIcon(m_hIcon, TRUE);            // Set big icon
  266.     SetIcon(m_hIcon, FALSE);        // Set small icon
  267.     
  268.     CButton *pButton = (CButton *)GetDlgItem(IDC_LOCALMODE);
  269.     if (pButton != NULL
  270.         && ::IsWindow(pButton->GetSafeHwnd()))
  271.         pButton->SetCheck(1);
  272.  
  273.     
  274.     return TRUE;  // return TRUE  unless you set the focus to a control
  275. }
  276.  
  277. void CLTSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
  278. {
  279.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  280.     {
  281.         CAboutDlg dlgAbout;
  282.         dlgAbout.DoModal();
  283.     }
  284.     else
  285.     {
  286.         CDialog::OnSysCommand(nID, lParam);
  287.     }
  288. }
  289.  
  290. // If you add a minimize button to your dialog, you will need the code below
  291. //  to draw the icon.  For MFC applications using the document/view model,
  292. //  this is automatically done for you by the framework.
  293.  
  294. void CLTSampleDlg::OnPaint() 
  295. {
  296.     if (IsIconic())
  297.     {
  298.         CPaintDC dc(this); // device context for painting
  299.  
  300.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  301.  
  302.         // Center icon in client rectangle
  303.         int cxIcon = GetSystemMetrics(SM_CXICON);
  304.         int cyIcon = GetSystemMetrics(SM_CYICON);
  305.         CRect rect;
  306.         GetClientRect(&rect);
  307.         int x = (rect.Width() - cxIcon + 1) / 2;
  308.         int y = (rect.Height() - cyIcon + 1) / 2;
  309.  
  310.         // Draw the icon
  311.         dc.DrawIcon(x, y, m_hIcon);
  312.     }
  313.     else
  314.     {
  315.         CDialog::OnPaint();
  316.     }
  317. }
  318.  
  319. // The system calls this to obtain the cursor to display while the user drags
  320. //  the minimized window.
  321. HCURSOR CLTSampleDlg::OnQueryDragIcon()
  322. {
  323.     return (HCURSOR) m_hIcon;
  324. }
  325.  
  326. // Automation servers should not exit when a user closes the UI
  327. //  if a controller still holds on to one of its objects.  These
  328. //  message handlers make sure that if the proxy is still in use,
  329. //  then the UI is hidden but the dialog remains around if it
  330. //  is dismissed.
  331.  
  332. void CLTSampleDlg::OnClose() 
  333. {
  334.     if (CanExit())
  335.     {
  336.         CDialog::OnClose();
  337.  
  338.         m_wndView.SetView(NULL);
  339.  
  340.         CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  341.         if (pDwgList != NULL)        
  342.         {
  343.             int iCount = pDwgList->GetCount();
  344.             for (int iItem = 0; iItem < iCount; iItem++)
  345.             {
  346.                 IDrawing *pIDwg = NULL;
  347.                 pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  348.                 if (pIDwg != NULL)
  349.                     pIDwg->Release();
  350.             }
  351.         }
  352.         if (m_pLocalApp != NULL)
  353.             m_pLocalApp->Release();
  354.         if (m_pInprocApp != NULL)
  355.             m_pInprocApp->Release();
  356.     }
  357. }
  358.  
  359. void CLTSampleDlg::OnOK() 
  360. {
  361.     if (CanExit())
  362.         CDialog::OnOK();
  363. }
  364.  
  365. void CLTSampleDlg::OnCancel() 
  366. {
  367.     if (CanExit())
  368.         CDialog::OnCancel();
  369. }
  370.  
  371. BOOL CLTSampleDlg::CanExit()
  372. {
  373.     // If the proxy object is still around, then the automation
  374.     //  controller is still holding on to this application.  Leave
  375.     //  the dialog around, but hide its UI.
  376.     if (m_pAutoProxy != NULL)
  377.     {
  378.         ShowWindow(SW_HIDE);
  379.         return FALSE;
  380.     }
  381.  
  382.     return TRUE;
  383. }
  384.  
  385. static char BASED_CODE szFilter[] = "TurboCAD Drawing Files (*.tcw)|*.tcw|All Files (*.*)|*.*||";
  386.  
  387. void CLTSampleDlg::OnMergedrawing() 
  388. {
  389.     if (m_pApp == NULL)
  390.     {
  391.         AfxMessageBox(IDS_CREATEAPPFIRST);
  392.         return;
  393.     }
  394.  
  395.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  396.  
  397.     // Pointer to Drawings collection
  398.     Drawings* pDwgs = NULL;
  399.  
  400.     // Pointer to drawing intrface
  401.     IDrawing* pIDwgOpen = NULL;
  402.  
  403.     Properties *pProps = NULL;
  404.     Property *pProp = NULL;
  405.     Graphics *pGrs = NULL;
  406.  
  407.     Properties *pPropsOpen = NULL;
  408.     Property *pPropOpen = NULL;
  409.     Graphics *pGrsOpen = NULL;
  410.  
  411.     IGraphic *pIGr = NULL;
  412.     BSTR bstrPath = NULL;
  413.  
  414.     // Make a "missing" optional parameter
  415.     VARIANT varMissing;
  416.     varMissing.vt = VT_ERROR;
  417.     varMissing.scode = DISP_E_PARAMNOTFOUND;
  418.  
  419.     int iSelItem = pDwgList->GetCurSel();
  420.     if (iSelItem >= 0)
  421.     {
  422.         CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  423.         if (dlg.DoModal() != IDOK)
  424.             return;
  425.  
  426.         // Get the handle to the drawings collection
  427.         TRY
  428.         {
  429.  
  430.             IDrawing *pIDwg = NULL;
  431.             HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  432.             CHECK_HRESULT(hRes)
  433.  
  434.             // Get the file name into a BSTR
  435.             CString strPath = dlg.GetPathName();
  436.             bstrPath = strPath.AllocSysString();
  437.  
  438.             // Add the drawing to the drawings collection
  439.             hRes = pDwgs->Open(bstrPath, &varMissing, &varMissing, &pIDwgOpen);
  440.             CHECK_HRESULT(hRes)
  441.  
  442.             pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  443.             if (pIDwg != NULL)
  444.             {                
  445.                 COleVariant varPropName("TileMode");
  446.                 COleVariant varMode;
  447.                 COleVariant varOldMode;
  448.  
  449.                 hRes = pIDwgOpen->get_Properties(&pPropsOpen);
  450.                 CHECK_HRESULT(hRes)
  451.  
  452.                 hRes = pPropsOpen->get_Item(&varPropName, &pPropOpen);
  453.                 CHECK_HRESULT(hRes)
  454.  
  455.                 hRes = pIDwg->get_Properties(&pProps);
  456.                 CHECK_HRESULT(hRes)
  457.  
  458.                 hRes = pProps->get_Item(&varPropName, &pProp);
  459.                 CHECK_HRESULT(hRes)
  460.  
  461.                 hRes = pProp->get_Value(0, &varMode);
  462.                 CHECK_HRESULT(hRes)
  463.  
  464.                 varOldMode = varMode;
  465.  
  466.                 hRes = pPropOpen->put_Value(0, &varMode);
  467.                 CHECK_HRESULT(hRes)
  468.  
  469.                 hRes = pIDwgOpen->get_Graphics(&pGrsOpen);
  470.                 CHECK_HRESULT(hRes)
  471.  
  472.                 long lCount = 0;
  473.                 hRes = pGrsOpen->get_Count(&lCount);
  474.                 CHECK_HRESULT(hRes)
  475.  
  476.                 hRes = pIDwg->get_Graphics(&pGrs);
  477.                 CHECK_HRESULT(hRes)
  478.  
  479.                 COleVariant varIndex((const long&)0);
  480.  
  481.                 for (long lItem = 0; lItem < lCount; lItem++)
  482.                 {
  483.                     hRes = pGrsOpen->Remove(&varIndex, &pIGr);
  484.                     CHECK_HRESULT(hRes)
  485.  
  486.                     hRes = pGrs->AddGraphic(pIGr, &varMissing, &varMissing);
  487.                     CHECK_HRESULT(hRes)
  488.                     pIGr->Release();
  489.                     pIGr = NULL;
  490.                 }
  491.  
  492.                 pGrsOpen->Release();
  493.                 pGrsOpen = NULL;
  494.  
  495.                 pGrs->Release();
  496.                 pGrs = NULL;
  497.  
  498.                 // merge next space
  499.                 if (varMode.iVal == 0)
  500.                     varMode.iVal = 1;
  501.                 else
  502.                     varMode.iVal = 0;
  503.  
  504.                 hRes = pProp->put_Value(0, &varMode);
  505.                 CHECK_HRESULT(hRes)
  506.  
  507.                 hRes = pPropOpen->put_Value(0, &varMode);
  508.                 CHECK_HRESULT(hRes)
  509.  
  510.                 hRes = pIDwgOpen->get_Graphics(&pGrsOpen);
  511.                 CHECK_HRESULT(hRes)
  512.  
  513.                 hRes = pGrsOpen->get_Count(&lCount);
  514.                 CHECK_HRESULT(hRes)
  515.  
  516.                 hRes = pIDwg->get_Graphics(&pGrs);
  517.                 CHECK_HRESULT(hRes)
  518.  
  519.                 for (lItem = 0; lItem < lCount; lItem++)
  520.                 {
  521.                     hRes = pGrsOpen->Remove(&varIndex,&pIGr);
  522.                     CHECK_HRESULT(hRes)
  523.  
  524.                     hRes = pGrs->AddGraphic(pIGr, &varMissing, &varMissing);
  525.                     CHECK_HRESULT(hRes)
  526.                     pIGr->Release();
  527.                     pIGr = NULL;
  528.                 }
  529.  
  530.             }
  531.         }
  532.         CATCH_ALL(e)
  533.         {
  534.         }
  535.         END_CATCH_ALL
  536.     }
  537.     else
  538.         OnOpendrawing();
  539.  
  540.     if (bstrPath != NULL)
  541.         ::SysFreeString(bstrPath);
  542.  
  543.     if (pIGr != NULL)
  544.         pIGr->Release();
  545.  
  546.     if (pGrsOpen != NULL)
  547.         pGrsOpen->Release();
  548.  
  549.     if (pPropOpen != NULL)
  550.         pPropOpen->Release();
  551.  
  552.     if (pPropsOpen != NULL)
  553.         pPropsOpen->Release();
  554.  
  555.     if (pGrs != NULL)
  556.         pGrs->Release();
  557.  
  558.     if (pProp != NULL)
  559.         pProp->Release();
  560.  
  561.     if (pProps != NULL)
  562.         pProps->Release();
  563.  
  564.     if (pIDwgOpen != NULL)
  565.     {
  566.         pIDwgOpen->Close(&varMissing, &varMissing, &varMissing);
  567.         pIDwgOpen->Release();
  568.     }
  569.  
  570.     if (pDwgs != NULL)
  571.         pDwgs->Release();;
  572.  
  573. }
  574.  
  575. void CLTSampleDlg::OnOpendrawing() 
  576. {
  577.     if (m_pApp == NULL)
  578.     {
  579.         AfxMessageBox(IDS_CREATEAPPFIRST);
  580.         return;
  581.     }
  582.     CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  583.     if (dlg.DoModal() != IDOK)
  584.         return;
  585.  
  586.     // Pointer to Drawings collection
  587.     Drawings* pDwgs = NULL;
  588.  
  589.     // Get the handle to the drawings collection
  590.     HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  591.     if (FAILED(hRes))
  592.     {
  593.         return;
  594.     }
  595.     
  596.     // Pointer to drawing object
  597.     IDrawing* pIDwg = NULL;
  598.  
  599.     // Make a "missing" optional parameter
  600.     VARIANT var;
  601.     var.vt = VT_ERROR;
  602.     var.scode = DISP_E_PARAMNOTFOUND;
  603.  
  604.     // Get the file name into a BSTR
  605.     CString strPath = dlg.GetPathName();
  606.     BSTR bstrPath = strPath.AllocSysString();
  607.  
  608.     // Add the drawing to the drawings collection
  609.     hRes = pDwgs->Open(bstrPath, &var, &var, &pIDwg);
  610.  
  611.     // Free the system memory for the BSTR
  612.     ::SysFreeString(bstrPath);
  613.  
  614.     if (SUCCEEDED(hRes))
  615.     {
  616.         CComboBox* pDwgsList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  617.         AddDrawingToList(pDwgsList, pIDwg);
  618.         pIDwg->Release();
  619.     }
  620.     else
  621.     {
  622.         // File was not opened.  Maybe the filter gave us a reason.
  623.         CString strDesc("Unknown");
  624.  
  625.         // Try to get thread-wide error object
  626.         IErrorInfo* pErrorInfo = NULL;
  627.         if (SUCCEEDED(::GetErrorInfo(0, &pErrorInfo)))
  628.         {
  629.             // Try to get description string
  630.             BSTR bstrDesc = NULL;
  631.             if (SUCCEEDED(pErrorInfo->GetDescription(&bstrDesc)))
  632.             {
  633.                 strDesc = bstrDesc;
  634.                 ::SysFreeString(bstrDesc);
  635.             }
  636.             pErrorInfo->Release();
  637.         }
  638.  
  639.         // Display failure message
  640.         CString msg = "Could not open '" + strPath + "': " + strDesc;
  641.         MessageBox(msg);
  642.     }
  643.  
  644.     // Finished with drawings collection, decrement reference count
  645.     pDwgs->Release();
  646.     
  647. }
  648.  
  649. void CLTSampleDlg::OnPaste() 
  650. {
  651.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  652.     if (pDwgList != NULL)
  653.     {
  654.         int iSelItem = pDwgList->GetCurSel();
  655.         if (iSelItem >= 0)
  656.         {
  657.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  658.             if (pIDwg != NULL)
  659.             {
  660.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PASTE);
  661.                 pPropBt->EnableWindow(FALSE);
  662.  
  663.                 HRESULT hRes = pIDwg->Paste();
  664.                 if (FAILED(hRes))
  665.                     AfxMessageBox(IDS_PASTEFAILED);
  666.                 pPropBt->EnableWindow(TRUE);
  667.             }
  668.             else
  669.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  670.         }
  671.     }
  672. }
  673.  
  674. void CLTSampleDlg::OnPropertysymbol() 
  675. {
  676.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  677.     if (pDwgList != NULL)
  678.     {
  679.         int iSelItem = pDwgList->GetCurSel();
  680.         if (iSelItem >= 0)
  681.         {
  682.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  683.             if (pIDwg != NULL)
  684.             {
  685.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  686.                 pPropBt->EnableWindow(FALSE);
  687.                 Selection *pSelection = NULL;
  688.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  689.                 if (SUCCEEDED(hRes))
  690.                 {
  691.                     long lCount;
  692.                     hRes = pSelection->get_Count(&lCount);
  693.                     if (SUCCEEDED(hRes))
  694.                     {
  695.                         if (lCount = 1)
  696.                         {
  697.                             IGraphic *pIGr = NULL;
  698.                             COleVariant varIndex((const long&)0);
  699.  
  700.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  701.                             if (SUCCEEDED(hRes))
  702.                             {
  703.                                 Properties *pProps = NULL;
  704.                                 hRes = pIGr->get_Properties(&pProps);
  705.                                 if (SUCCEEDED(hRes))
  706.                                 {
  707.                                     CPropDialog dlgProp(pProps, this);
  708.                                     if (dlgProp.DoModal() == IDOK)
  709.                                     {
  710.                                     }
  711.                                     pProps->Release();
  712.                                 }
  713.                                 else
  714.                                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  715.                                 pIGr->Release();
  716.                             }
  717.                             else
  718.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  719.                         }
  720.                         else
  721.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  722.                     }
  723.                     else
  724.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  725.                     pSelection->Release();
  726.                 }
  727.                 else
  728.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  729.                 pPropBt->EnableWindow(TRUE);
  730.             }
  731.             else
  732.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  733.         }
  734.     }
  735. }
  736.  
  737. void CLTSampleDlg::OnSavedrawing() 
  738. {
  739.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  740.     HRESULT hRes = S_OK;
  741.     if (pDwgList != NULL)        
  742.     {
  743.         CButton *pSaveBt = (CButton *)GetDlgItem(IDC_SAVEDRAWING);
  744.         pSaveBt->EnableWindow(FALSE);
  745.  
  746.         int iItem = pDwgList->GetCurSel();
  747.         if (iItem >= 0)
  748.         {
  749.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  750.             if (pIDwg != NULL)
  751.             {
  752.                 CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  753.                 if (dlg.DoModal() == IDOK)
  754.                 {
  755.                     // Make a "missing" optional parameter
  756.                     VARIANT var;
  757.                     var.vt = VT_ERROR;
  758.                     var.scode = DISP_E_PARAMNOTFOUND;
  759.  
  760.                     // Get the file name into a BSTR
  761.                     CString strPath = dlg.GetPathName();
  762.                     BSTR bstrPath = strPath.AllocSysString();
  763.  
  764.                     HRESULT hRes = pIDwg->SaveAs(bstrPath, &var);
  765.  
  766.                     // Free the system memory for the BSTR
  767.                     ::SysFreeString(bstrPath);
  768.                 }
  769.             }
  770.         }
  771.         else
  772.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  773.         pSaveBt->EnableWindow(TRUE);
  774.     }
  775. }
  776.  
  777. void CLTSampleDlg::OnSelectsymbol() 
  778. {
  779.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  780.     HRESULT hRes = S_OK;
  781.     if (pDwgList != NULL)        
  782.     {
  783.         CButton *pSelectBt = (CButton *)GetDlgItem(IDC_SELECTSYMBOL);
  784.         if (pSelectBt->IsWindowEnabled())
  785.         {
  786.             int iItem = pDwgList->GetCurSel();
  787.             if (iItem >= 0)
  788.             {
  789.                 IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  790.                 if (pIDwg != NULL)
  791.                 {
  792.                     Selection *pSel = NULL;
  793.                     hRes = pIDwg->get_Selection(&pSel);
  794.                     if (SUCCEEDED(hRes))
  795.                     {
  796.                         pSel->Unselect();
  797.                         pSel->Release();
  798.                     }
  799.                 }
  800.                 m_wndView.SetSelectMode();
  801.                 pSelectBt->EnableWindow(FALSE);
  802.             }
  803.             else
  804.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  805.         }
  806.         else
  807.         {
  808.             pSelectBt->EnableWindow(TRUE);
  809.             m_wndView.SetSelectMode();
  810.         }
  811.     }
  812. }
  813.  
  814. void CLTSampleDlg::OnCreateapp() 
  815. {
  816.     CButton *pBtCreate = (CButton *)GetDlgItem(IDC_CREATEAPP);
  817.     if (pBtCreate != NULL
  818.         && ::IsWindow(pBtCreate->GetSafeHwnd()))
  819.         pBtCreate->EnableWindow(FALSE);
  820.  
  821.     int iLocal = 0;
  822.     CButton *pBtLocal = (CButton *)GetDlgItem(IDC_LOCALMODE);
  823.     if (pBtLocal != NULL
  824.         && ::IsWindow(pBtLocal->GetSafeHwnd()))
  825.         iLocal = pBtLocal->GetCheck();
  826.  
  827.     int iInproc = 0;
  828.     CButton *pBtInproc = (CButton *)GetDlgItem(IDC_INPROCMODE);
  829.     if (pBtInproc != NULL
  830.         && ::IsWindow(pBtInproc->GetSafeHwnd()))
  831.         iInproc = pBtInproc->GetCheck();
  832.  
  833.     HRESULT hRes = S_OK;
  834.     if (iLocal == 1)
  835.     {
  836.         ASSERT(iInproc != 1);
  837.         if (m_pLocalApp == NULL)
  838.         {
  839.             IUnknown* pIUnk = NULL;
  840.             hRes = ::GetActiveObject(CLSID_Application, NULL, &pIUnk);
  841.             if (FAILED(hRes))
  842.             {
  843.                 hRes = CoCreateInstance(CLSID_Application,    //Class identifier (CLSID) of the object
  844.                                         NULL,    //Object is or isn't part of an aggregate 
  845.                                         CLSCTX_LOCAL_SERVER,    //Context for running executable code
  846.                                         IID_IUnknown,    //Interface identifier
  847.                                         (void**)&pIUnk    //Points to requested interface pointer
  848.                 );    
  849.  
  850.                 if (FAILED(hRes))
  851.                 {
  852.                     AfxMessageBox(IDS_COULDNOTCREATELOCALSERVER);
  853.                     return;
  854.                 }
  855.             }
  856.  
  857.             hRes = pIUnk->QueryInterface(IID_IApplication, (void**)&m_pLocalApp);
  858.             pIUnk->Release();
  859.             if (FAILED(hRes))
  860.             {
  861.                 AfxMessageBox(IDS_OBJECTISNOTTURBOCADAPPLICATION);
  862.             }
  863.         }
  864.         else
  865.             AfxMessageBox(IDS_LOCALSERVERALREADYRUNNING);
  866.         m_pApp = m_pLocalApp;
  867.     }
  868.     else if (iInproc == 1)
  869.     {
  870.         if (m_pInprocApp == NULL)
  871.         {
  872.             hRes = CoCreateInstance(CLSID_XApplication,    //Class identifier (CLSID) of the object
  873.                                     NULL,    //Object is or isn't part of an aggregate
  874.                                     CLSCTX_INPROC_SERVER,    //Context for running executable code
  875.                                     IID_IApplication,    //Interface identifier
  876.                                     (void**)&m_pInprocApp    //Points to requested interface pointer
  877.             );
  878.  
  879.             if (FAILED(hRes))
  880.                 AfxMessageBox(IDS_COULDNOTCREATEINPROCSERVER);
  881.     
  882.         }
  883.         else
  884.             AfxMessageBox(IDS_INPROCSERVERALREADYCREATED);
  885.         m_pApp = m_pInprocApp;
  886.     }
  887.     else
  888.         ASSERT(FALSE);
  889.  
  890.     // uncorrect reference counting of the Selection object
  891.     // in SDK v 4.x - I have to correct it in the my sample
  892.     // when create Application object
  893.     SyncToApplication(m_pApp, TRUE);
  894.     if (m_pApp != NULL)
  895.         AfxMessageBox(IDS_APPCOMPLETE);
  896. }
  897.  
  898.  
  899. void CLTSampleDlg::OnSetview() 
  900. {
  901.     
  902.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  903.     if (pDwgList != NULL)        
  904.     {
  905.         int iItem = pDwgList->GetCurSel();
  906.         if (iItem >= 0)
  907.         {
  908.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  909.             Views *pViews = NULL;
  910.             HRESULT hRes = pIDwg->get_Views(&pViews);
  911.             if (SUCCEEDED(hRes))
  912.             {
  913.                 // Pointer to view object
  914.                 View* pView = NULL;
  915.  
  916.                 // Make a "missing" optional parameter
  917.                 VARIANT var;
  918.                 var.vt = VT_ERROR;
  919.                 var.scode = DISP_E_PARAMNOTFOUND;
  920.  
  921.                 // Add the view to the collection
  922.                 hRes = pViews->Add(&var, &var, &pView);
  923.  
  924.                 if (SUCCEEDED(hRes))
  925.                 {
  926.                     // Set up view to be the active view
  927.                     m_wndView.SetView(pView);
  928.  
  929.                     // Finished with view, decrement reference count
  930.                     pView->Release();
  931.                 }
  932.  
  933.                 // Finished with views, decrement reference count
  934.                 pViews->Release();
  935.             }
  936.         }
  937.         else
  938.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  939.     }
  940. }
  941.  
  942. void CLTSampleDlg::OnNewdrawing() 
  943. {
  944.     if (m_pApp == NULL)
  945.     {
  946.         AfxMessageBox(IDS_CREATEAPPFIRST);
  947.         return;
  948.     }
  949.  
  950.     Drawings* pDwgs = NULL;
  951.  
  952.     // Get the handle to the drawings collection
  953.     HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  954.     if (FAILED(hRes))
  955.     {
  956.         return;
  957.     }
  958.     
  959.     // Pointer to drawing object
  960.     IDrawing* pIDwg = NULL;
  961.  
  962.     // Make a "missing" optional parameter
  963.     VARIANT var;
  964.     var.vt = VT_ERROR;
  965.     var.scode = DISP_E_PARAMNOTFOUND;
  966.  
  967.     // Add the drawing to the drawings collection
  968.     hRes = pDwgs->Add(&var, &pIDwg);
  969.     if (SUCCEEDED(hRes))
  970.     {
  971.         CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  972.         AddDrawingToList(pDwgList, pIDwg);
  973.         pIDwg->Release();
  974.     }
  975.  
  976.     // Finished with drawings collection, decrement reference count
  977.     pDwgs->Release();
  978. }
  979.  
  980. void CLTSampleDlg::OnLocalmode() 
  981. {
  982.     m_pApp = m_pLocalApp;
  983.     SyncToApplication(m_pApp);
  984. }
  985.  
  986. void CLTSampleDlg::OnInprocmode() 
  987. {
  988.     m_pApp = m_pInprocApp;
  989.     SyncToApplication(m_pApp);
  990. }
  991.  
  992. void CLTSampleDlg::OnDrawingProperty() 
  993. {
  994.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  995.     if (pDwgList != NULL)
  996.     {
  997.         int iSelItem = pDwgList->GetCurSel();
  998.         if (iSelItem >= 0)
  999.         {
  1000.             CButton *pPropBt = (CButton *)GetDlgItem(IDC_DRAWINGPROPERTY);
  1001.             pPropBt->EnableWindow(FALSE);
  1002.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1003.             if (pIDwg != NULL)
  1004.             {
  1005.                 Properties *pProps = NULL;
  1006.                 HRESULT hRes = pIDwg->get_Properties(&pProps);
  1007.                 if (SUCCEEDED(hRes))
  1008.                 {
  1009.                     CPropDialog dlgProp(pProps, this);
  1010.                     if (dlgProp.DoModal() == IDOK)
  1011.                     {
  1012.                     }
  1013.                     pProps->Release();
  1014.                 }
  1015.                 else
  1016.                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1017.             }
  1018.             pPropBt->EnableWindow(TRUE);
  1019.         }
  1020.         else
  1021.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1022.     }
  1023. }
  1024.  
  1025. void CLTSampleDlg::OnClosedrawing() 
  1026. {
  1027.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1028.     if (pDwgList != NULL)
  1029.     {
  1030.         int iSelItem = pDwgList->GetCurSel();
  1031.         if (iSelItem >= 0)
  1032.         {
  1033.             CButton *pPropBt = (CButton *)GetDlgItem(IDC_DRAWINGPROPERTY);
  1034.             pPropBt->EnableWindow(FALSE);
  1035.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1036.             if (pIDwg != NULL)
  1037.             {
  1038.                 IDrawing *pIDwgView = m_wndView.GetDrawing();
  1039.                 if (pIDwgView == pIDwg)
  1040.                 {
  1041.                     m_wndView.SetView(NULL);
  1042.                     m_wndView.Invalidate();
  1043.                     m_wndView.UpdateWindow();
  1044.                     pIDwgView->Release();
  1045.                 }
  1046.  
  1047.                 VARIANT var;
  1048.                 var.vt = VT_ERROR;
  1049.                 var.scode = DISP_E_PARAMNOTFOUND;
  1050.                 pIDwg->Close(&var, &var, &var);
  1051.                 pIDwg->Release();
  1052.  
  1053.                 pDwgList->DeleteString(iSelItem);
  1054.                 pDwgList->SetCurSel(iSelItem - 1);
  1055.             }
  1056.             pPropBt->EnableWindow(TRUE);
  1057.         }
  1058.         else
  1059.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1060.     }    
  1061. }
  1062.  
  1063. void CLTSampleDlg::OnExplodesymbol() 
  1064. {
  1065.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1066.     if (pDwgList != NULL)
  1067.     {
  1068.         int iSelItem = pDwgList->GetCurSel();
  1069.         if (iSelItem >= 0)
  1070.         {
  1071.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1072.             if (pIDwg != NULL)
  1073.             {
  1074.                 CButton *pExplBt = (CButton *)GetDlgItem(IDC_EXPLODESYMBOL);
  1075.                 pExplBt->EnableWindow(FALSE);
  1076.                 Selection *pSelection = NULL;
  1077.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1078.                 if (SUCCEEDED(hRes))
  1079.                 {
  1080.                     long lCount;
  1081.                     hRes = pSelection->get_Count(&lCount);
  1082.                     if (SUCCEEDED(hRes))
  1083.                     {
  1084.                         if (lCount = 1)
  1085.                         {
  1086.                             IGraphic *pIGr = NULL;
  1087.                             COleVariant varIndex((const long&)0);
  1088.  
  1089.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  1090.                             if (SUCCEEDED(hRes))
  1091.                             {
  1092.                                 GraphicSet *pSet = NULL;
  1093.                                 hRes = pIGr->Explode(&pSet);
  1094.                                 if (SUCCEEDED(hRes))
  1095.                                 {
  1096.                                     pSet->Release();
  1097.                                 }
  1098.                                 else
  1099.                                     AfxMessageBox(IDS_CANNOTEXPLODEGRAPHIC);
  1100.                                 pIGr->Release();
  1101.                             }
  1102.                             else
  1103.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1104.                         }
  1105.                         else
  1106.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1107.                     }
  1108.                     else
  1109.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1110.                     pSelection->Release();
  1111.                 }
  1112.                 else
  1113.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1114.                 pExplBt->EnableWindow(TRUE);
  1115.             }
  1116.             else
  1117.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1118.         }
  1119.     }
  1120. }
  1121.  
  1122. void CLTSampleDlg::OnQuery() 
  1123. {
  1124.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1125.     if (pDwgList != NULL)
  1126.     {
  1127.         int iSelItem = pDwgList->GetCurSel();
  1128.         if (iSelItem >= 0)
  1129.         {
  1130.             CButton *pQueryBt = (CButton *)GetDlgItem(IDC_QUERY);
  1131.             pQueryBt->EnableWindow(FALSE);
  1132.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1133.             if (pIDwg != NULL)
  1134.             {
  1135.                 Graphics *pGrs = NULL;
  1136.                 HRESULT hRes = pIDwg->get_Graphics(&pGrs);
  1137.                 if (SUCCEEDED(hRes))
  1138.                 {
  1139.                     CQueryDialog dlgQuery(this);
  1140.                     if (dlgQuery.DoModal() == IDOK)
  1141.                     {
  1142.                         GraphicSet *pGrSet = NULL;
  1143.                         BSTR bstrQuery = dlgQuery.m_cstrQueryString.AllocSysString();
  1144.                         hRes = pGrs->QuerySet(bstrQuery, &pGrSet);
  1145.                         if (SUCCEEDED(hRes))
  1146.                         {
  1147.                             if (pGrSet != NULL)
  1148.                             {
  1149.                                 hRes = pGrSet->Select();
  1150.                                 if (SUCCEEDED(hRes))
  1151.                                     AfxMessageBox(IDS_QUERYSET_SUCCEEDED);
  1152.                                 else
  1153.                                     AfxMessageBox(IDS_CANNOTSELECTGRAPHIC);
  1154.                                 pGrSet->Release();
  1155.                             }
  1156.                             m_wndView.Invalidate();
  1157.                             m_wndView.UpdateWindow();
  1158.                         }
  1159.                         else
  1160.                             AfxMessageBox(IDS_QUERYSET_FAILED);
  1161.                         ::SysFreeString(bstrQuery);
  1162.                     }
  1163.                     pGrs->Release();
  1164.                 }
  1165.                 else
  1166.                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1167.             }
  1168.             pQueryBt->EnableWindow(TRUE);
  1169.         }
  1170.         else
  1171.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1172.     }
  1173. }
  1174.  
  1175. void CLTSampleDlg::OnCopysymbol() 
  1176. {
  1177.     // TODO: Add your control notification handler code here
  1178.     
  1179. }
  1180.  
  1181. void CLTSampleDlg::OnAddsymbol() 
  1182. {
  1183.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1184.     if (pDwgList != NULL)
  1185.     {
  1186.         int iSelItem = pDwgList->GetCurSel();
  1187.         if (iSelItem >= 0)
  1188.         {
  1189.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1190.             if (pIDwg != NULL)
  1191.             {
  1192.                 CAddSymbolDlg dlgAdd(this);
  1193.                 if (dlgAdd.DoModal() == IDOK)
  1194.                 {
  1195.                     HRESULT hRes = S_OK;
  1196.                     switch (dlgAdd.m_iInsert)
  1197.                     {
  1198.                         case 0:
  1199.                         {
  1200.                             RegenMethods *pRegens = NULL;
  1201.                             hRes = m_pApp->get_RegenMethods(&pRegens);
  1202.                             if (SUCCEEDED(hRes))
  1203.                             {
  1204.                                 CSmartObjectInserDlg dlgInsert(pRegens, this);
  1205.                                 if (dlgInsert.DoModal())
  1206.                                 {
  1207.                                     VARIANT varMissing;
  1208.                                     ::VariantInit(&varMissing);
  1209.                                     varMissing.vt = VT_ERROR;
  1210.                                     varMissing.scode = DISP_E_PARAMNOTFOUND;
  1211.                                     
  1212.                                     VARIANT varType;
  1213.                                     ::VariantInit(&varType);
  1214.                                     varType.vt = VT_I4;
  1215.                                     varType.lVal = imsiPolyline;
  1216.  
  1217.                                     VARIANT varRegenType;
  1218.                                     ::VariantInit(&varRegenType);
  1219.                                     varRegenType.vt = VT_I4;
  1220.                                     varRegenType.lVal = dlgInsert.m_dwID;
  1221.  
  1222.                                     IGraphic *pIGr = NULL;
  1223.                                     Graphics *pGrs = NULL;
  1224.                                     hRes = pIDwg->get_Graphics(&pGrs);
  1225.                                     if (SUCCEEDED(hRes))
  1226.                                     {
  1227.                                         
  1228.                                         switch (dlgInsert.m_rmType)
  1229.                                         {
  1230.                                             case imsiAutomation:
  1231.                                             {
  1232.                                                 hRes = pGrs->Add(&varType,
  1233.                                                                  &varRegenType,
  1234.                                                                  &varMissing,
  1235.                                                                  &varMissing,
  1236.                                                                  &varMissing,
  1237.                                                                  &varMissing,
  1238.                                                                  &pIGr);
  1239.                                             }
  1240.                                             break;
  1241.                                             case imsiVTbl:
  1242.                                                 AfxMessageBox(IDS_NOTIMPLEMENTED);
  1243.                                             break;
  1244.                                             case imsiScript:
  1245.                                                 AfxMessageBox(IDS_NOTIMPLEMENTED);
  1246.                                             break;
  1247.                                         }
  1248.                                         if (pIGr != NULL)
  1249.                                             pIGr->Release();
  1250.                                         pGrs->Release();
  1251.                                     }
  1252.                                     else
  1253.                                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1254.                                 }
  1255.                             }
  1256.                             else
  1257.                                 AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1258.                         }
  1259.                         break;
  1260.                         case 1:
  1261.                         default:
  1262.                             AfxMessageBox(IDS_NOTIMPLEMENTED);
  1263.                         break;
  1264.                     }
  1265.                 }
  1266.             }
  1267.             else
  1268.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1269.         }
  1270.         else
  1271.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1272.     }
  1273. }
  1274.  
  1275. void CLTSampleDlg::OnDeletesymbol() 
  1276. {
  1277.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1278.     if (pDwgList != NULL)
  1279.     {
  1280.         int iSelItem = pDwgList->GetCurSel();
  1281.         if (iSelItem >= 0)
  1282.         {
  1283.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1284.             if (pIDwg != NULL)
  1285.             {
  1286.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  1287.                 pPropBt->EnableWindow(FALSE);
  1288.                 Selection *pSelection = NULL;
  1289.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1290.                 if (SUCCEEDED(hRes))
  1291.                 {
  1292.                     long lCount;
  1293.                     hRes = pSelection->get_Count(&lCount);
  1294.                     if (SUCCEEDED(hRes))
  1295.                     {
  1296.                         IGraphic *pIGr = NULL;
  1297.                         COleVariant varIndex((const long&)0);
  1298.  
  1299.                         hRes = pSelection->get_Item(varIndex, &pIGr);
  1300.                         if (SUCCEEDED(hRes))
  1301.                         {
  1302.                             long index;
  1303.                             hRes = pIGr->get_Index(&index);
  1304.                             if (SUCCEEDED(hRes))
  1305.                             {
  1306.                                 IDispatch *pIDisp = NULL;
  1307.                                 hRes = pIGr->get_Parent(&pIDisp);
  1308.                                 if (SUCCEEDED(hRes))
  1309.                                 {
  1310.                                     Graphics *pGrs = NULL;
  1311.                                     IDrawing *pIDwg = NULL;
  1312.                                     hRes = pIDisp->QueryInterface(IID_IDrawing, (void **)&pIDwg);
  1313.                                     if (SUCCEEDED(hRes))
  1314.                                         hRes = pIDwg->get_Graphics(&pGrs);
  1315.                                     else
  1316.                                         hRes = pIDisp->QueryInterface(IID_Graphics, (void **)&pGrs);
  1317.                                     pIDisp->Release();
  1318.                                     if (SUCCEEDED(hRes))
  1319.                                     {
  1320.                                         varIndex = index;
  1321.                                         IGraphic *pIGrRemoved = NULL;
  1322.                                         hRes = pGrs->Remove(&varIndex, &pIGrRemoved);
  1323.                                         if (SUCCEEDED(hRes))
  1324.                                         {
  1325.                                             AfxMessageBox(IDS_SYMBOLREMOVEDFROMDRAWING);
  1326.                                             pIGrRemoved->Release();
  1327.                                         }
  1328.                                         pGrs->Release();
  1329.                                     }
  1330.                                 }
  1331.                             }
  1332.                             pIGr->Release();
  1333.                         }
  1334.                         else
  1335.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1336.                     }
  1337.                     else
  1338.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1339.                     pSelection->Release();
  1340.                 }
  1341.                 else
  1342.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1343.                 pPropBt->EnableWindow(TRUE);
  1344.             }
  1345.         }
  1346.         else
  1347.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1348.     }
  1349. }
  1350.  
  1351. void CLTSampleDlg::OnAppproperty() 
  1352. {
  1353.     if (m_pApp != NULL)
  1354.     {
  1355.         CButton *pAppPropsBt = (CButton *)GetDlgItem(IDC_APPPROPERTY);
  1356.         if (pAppPropsBt != NULL)
  1357.             pAppPropsBt->EnableWindow(FALSE);
  1358.         Properties *pProps = NULL;
  1359.         HRESULT hRes = m_pApp->get_Properties(&pProps);
  1360.         if (SUCCEEDED(hRes))
  1361.         {
  1362.             CPropDialog dlgProp(pProps, this);
  1363.             if (dlgProp.DoModal() == IDOK)
  1364.             {
  1365.             }
  1366.             pProps->Release();
  1367.         }
  1368.         else
  1369.             AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1370.         if (pAppPropsBt != NULL)
  1371.             pAppPropsBt->EnableWindow(TRUE);
  1372.     }
  1373.     else
  1374.         AfxMessageBox(IDS_CREATEAPPFIRST);
  1375.     
  1376. }
  1377.  
  1378. void CLTSampleDlg::OnOptions() 
  1379. {
  1380.     CPropertySheet     sheet("Options", this);
  1381.     CSelOptPage    select;
  1382.  
  1383.     select.m_iVersion    = m_iVersion;
  1384.     select.m_bTopLevel    = m_wndView.m_varTopLevel.boolVal;
  1385.     select.m_bInvisible    = m_wndView.m_varInvisible.boolVal;
  1386.     select.m_bSegments    = m_wndView.m_varSegments.boolVal;
  1387.     select.m_bArcs        = m_wndView.m_varArcs.boolVal;
  1388.     select.m_bTexts        = m_wndView.m_varTexts.boolVal;
  1389.     select.m_bBlocks    = m_wndView.m_varBlocks.boolVal;
  1390.  
  1391.     sheet.AddPage(&select);
  1392.     if (sheet.DoModal() == IDOK)
  1393.     {
  1394.         m_wndView.m_varTopLevel.boolVal        = select.m_bTopLevel;
  1395.         m_wndView.m_varInvisible.boolVal    = select.m_bInvisible;
  1396.         m_wndView.m_varSegments.boolVal        = select.m_bSegments;
  1397.         m_wndView.m_varArcs.boolVal            = select.m_bArcs;
  1398.         m_wndView.m_varTexts.boolVal        = select.m_bTexts;
  1399.         m_wndView.m_varBlocks.boolVal        = select.m_bBlocks;
  1400.     }
  1401. }
  1402.  
  1403. void CLTSampleDlg::OnGetblock() 
  1404. {
  1405.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1406.     if (pDwgList != NULL)
  1407.     {
  1408.         int iSelItem = pDwgList->GetCurSel();
  1409.         if (iSelItem >= 0)
  1410.         {
  1411.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1412.             if (pIDwg != NULL)
  1413.             {
  1414.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  1415.                 pPropBt->EnableWindow(FALSE);
  1416.                 Selection *pSelection = NULL;
  1417.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1418.                 if (SUCCEEDED(hRes))
  1419.                 {
  1420.                     long lCount;
  1421.                     hRes = pSelection->get_Count(&lCount);
  1422.                     if (SUCCEEDED(hRes))
  1423.                     {
  1424.                         if (lCount = 1)
  1425.                         {
  1426.                             IGraphic *pIGr = NULL;
  1427.                             COleVariant varIndex((const long&)0);
  1428.  
  1429.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  1430.                             if (SUCCEEDED(hRes))
  1431.                             {
  1432.                                 Block *pBlock = NULL;
  1433.                                 hRes = pIGr->get_Block(&pBlock);
  1434.                                 if (SUCCEEDED(hRes) && pBlock)
  1435.                                 {
  1436.                                     pBlock->Release();
  1437.                                 }
  1438.                                 else
  1439.                                     AfxMessageBox(IDS_CANNOTGETBLOCK);
  1440.                                 pIGr->Release();
  1441.                             }
  1442.                             else
  1443.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1444.                         }
  1445.                         else
  1446.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1447.                     }
  1448.                     else
  1449.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1450.                     pSelection->Release();
  1451.                 }
  1452.                 else
  1453.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1454.                 pPropBt->EnableWindow(TRUE);
  1455.             }
  1456.             else
  1457.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1458.         }
  1459.     }
  1460. }
  1461.  
  1462. void CLTSampleDlg::OnZoomIn() 
  1463. {
  1464.     CString strStr;
  1465.     strStr.LoadString(IDS_ADDYOUR_CODE_HERE);
  1466.     AfxMessageBox(strStr);
  1467.     // TODO: Add your control notification handler code here
  1468. }
  1469.  
  1470. void CLTSampleDlg::OnZoomOut() 
  1471. {
  1472.     CString strStr;
  1473.     strStr.LoadString(IDS_ADDYOUR_CODE_HERE);
  1474.     AfxMessageBox(strStr);
  1475.     // TODO: Add your control notification handler code here
  1476.     
  1477. }
  1478.