home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / blockinsertdialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-16  |  3.0 KB  |  120 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. // BlockInsertDialog.cpp : implementation file
  11. //
  12.  
  13. #include "stdafx.h"
  14. #include "SDKDemo.h"
  15. #include "BlockInsertDialog.h"
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CBlockInsertDialog dialog
  25.  
  26.  
  27. CBlockInsertDialog::CBlockInsertDialog(IDrawing* pIDrawing, CWnd* pParent /*=NULL*/) : 
  28.     CDialog(CBlockInsertDialog::IDD, pParent),
  29.     m_pBlocks(NULL)
  30. {
  31.     //{{AFX_DATA_INIT(CBlockInsertDialog)
  32.     m_strBlockName = _T("");
  33.     //}}AFX_DATA_INIT
  34.  
  35.     if (pIDrawing != NULL)
  36.     {
  37.         Blocks* pBlocks = NULL;
  38.         HRESULT hRes = pIDrawing->get_Blocks(&pBlocks);
  39.         if (SUCCEEDED(hRes))
  40.         {
  41.             long lCount = 0;
  42.             hRes = pBlocks->get_Count(&lCount);
  43.             if (SUCCEEDED(hRes) && lCount > 0)
  44.             {
  45.                 m_pBlocks = pBlocks;
  46.                 return;
  47.             }
  48.             pBlocks->Release();
  49.         }
  50.     }
  51. }
  52.  
  53. CBlockInsertDialog::~CBlockInsertDialog()
  54. {
  55.     if (m_pBlocks != NULL)
  56.         m_pBlocks->Release();
  57. }
  58.  
  59. void CBlockInsertDialog::DoDataExchange(CDataExchange* pDX)
  60. {
  61.     CDialog::DoDataExchange(pDX);
  62.     //{{AFX_DATA_MAP(CBlockInsertDialog)
  63.     DDX_LBString(pDX, IDC_BLOCKS, m_strBlockName);
  64.     //}}AFX_DATA_MAP
  65. }
  66.  
  67. BOOL CBlockInsertDialog::OnInitDialog()
  68. {
  69.     CDialog::OnInitDialog();
  70.  
  71.     BOOL bSuccess = FALSE;
  72.     if (m_pBlocks != NULL)
  73.     {
  74.         long lCount = 0;
  75.         HRESULT hRes = m_pBlocks->get_Count(&lCount);
  76.         if (SUCCEEDED(hRes) && lCount > 0)
  77.         {
  78.             CListBox* pList = (CListBox*)GetDlgItem(IDC_BLOCKS);
  79.             for (long i = 0; i < lCount; ++i)
  80.             {
  81.                 Block* pBlock = NULL;
  82.                 COleVariant varIndex(i);
  83.                 hRes = m_pBlocks->get_Item(&varIndex, &pBlock);
  84.                 if (SUCCEEDED(hRes))
  85.                 {
  86.                     BSTR bstrName = NULL;
  87.                     hRes = pBlock->get_Name(&bstrName);
  88.                     if (SUCCEEDED(hRes))
  89.                     {
  90.                         CString str(bstrName);
  91.                         SysFreeString(bstrName);
  92.  
  93.                         if (pList->AddString(str) != LB_ERR)
  94.                             bSuccess = TRUE;
  95.                     }
  96.                 }
  97.             }
  98.         }
  99.     }
  100.     if (!bSuccess)
  101.         EndDialog(IDCANCEL);
  102.     return TRUE;
  103. }
  104.  
  105. BEGIN_MESSAGE_MAP(CBlockInsertDialog, CDialog)
  106.     //{{AFX_MSG_MAP(CBlockInsertDialog)
  107.     ON_LBN_DBLCLK(IDC_BLOCKS, OnDblclkBlocks)
  108.     //}}AFX_MSG_MAP
  109. END_MESSAGE_MAP()
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CBlockInsertDialog message handlers
  113.  
  114. void CBlockInsertDialog::OnDblclkBlocks() 
  115. {
  116.     UpdateData(TRUE);
  117.     EndDialog(IDOK);
  118. }
  119.  
  120.