home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / tstcon / coninfdg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  4.6 KB  |  170 lines

  1. // CContainerInfoDlg.Cpp : implementation file
  2. //
  3.  
  4. #include "StdAfx.H"
  5. #include "TestCon.H"
  6. #include "resource.hm"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CContainerInfoDlg dialog
  16.  
  17.  
  18. CContainerInfoDlg::CContainerInfoDlg( CWnd* pParent,
  19.    CTestContainer98Doc* pDoc ) :
  20.    CDialog( CContainerInfoDlg::IDD, pParent ),
  21.    m_pDoc( pDoc )
  22. {
  23.    ASSERT( m_pDoc != NULL );
  24.  
  25.     //{{AFX_DATA_INIT(CContainerInfoDlg)
  26.         // NOTE: the ClassWizard will add member initialization here
  27.     //}}AFX_DATA_INIT
  28. }
  29.  
  30.  
  31. void CContainerInfoDlg::DoDataExchange(CDataExchange* pDX)
  32. {
  33.     CDialog::DoDataExchange(pDX);
  34.     //{{AFX_DATA_MAP(CContainerInfoDlg)
  35.     DDX_Control(pDX, IDC_OBJECTS, m_listObjects);
  36.     //}}AFX_DATA_MAP
  37. }
  38.  
  39.  
  40. BEGIN_MESSAGE_MAP(CContainerInfoDlg, CDialog)
  41.     //{{AFX_MSG_MAP(CContainerInfoDlg)
  42.     ON_WM_HELPINFO()
  43.     ON_WM_CONTEXTMENU()
  44.     //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CContainerInfoDlg message handlers
  49.  
  50. BOOL CContainerInfoDlg::OnInitDialog()
  51. {
  52.    POSITION posItem;
  53.    CTestContainer98Item* pItem;
  54.    int iItem;
  55.    CString strItemName;
  56.    CString strState;
  57.    CString strObject;
  58.    CString strWindowStatus;
  59.    int nAutoWidth;
  60.    int nAutoHeaderWidth;
  61.  
  62.     CDialog::OnInitDialog();
  63.  
  64.    strObject.LoadString( IDS_CONTAINERINFOOBJECTHEADER );
  65.    m_listObjects.InsertColumn( 0, strObject, LVCFMT_LEFT, 100 );
  66.  
  67.    strState.LoadString( IDS_CONTAINERINFOSTATEHEADER );
  68.    m_listObjects.InsertColumn( 1, strState, LVCFMT_LEFT, 100 );
  69.  
  70.    strWindowStatus.LoadString( IDS_CONTAINERINFOWINDOWHEADER );
  71.    m_listObjects.InsertColumn( 2, strWindowStatus, LVCFMT_LEFT, 100 );
  72.  
  73.    iItem = 0;
  74.    posItem = m_pDoc->GetStartPosition();
  75.    while( posItem != NULL )
  76.    {
  77.       pItem = (CTestContainer98Item*)m_pDoc->GetNextItem( posItem );
  78.       strItemName = pItem->GetDisplayName();
  79.       m_listObjects.InsertItem( iItem, strItemName );
  80.       m_listObjects.SetItemText( iItem, 0, strItemName );
  81.       switch( pItem->GetItemState() )
  82.       {
  83.       case COleClientItem::activeState:
  84.          strState.LoadString( IDS_ACTIVESTATE );
  85.          if( pItem->IsWindowless() )
  86.          {
  87.             strWindowStatus.LoadString( IDS_WINDOWLESS );
  88.          }
  89.          else
  90.          {
  91.             strWindowStatus.LoadString( IDS_WINDOWED );
  92.          }
  93.          break;
  94.  
  95.       case COleClientItem::activeUIState:
  96.          strState.LoadString( IDS_UIACTIVESTATE );
  97.          if( pItem->IsWindowless() )
  98.          {
  99.             strWindowStatus.LoadString( IDS_WINDOWLESS );
  100.          }
  101.          else
  102.          {
  103.             strWindowStatus.LoadString( IDS_WINDOWED );
  104.          }
  105.          break;
  106.  
  107.       case COleClientItem::openState:
  108.          strState.LoadString( IDS_OPENSTATE );
  109.          strWindowStatus.Empty();
  110.          break;
  111.  
  112.       case COleClientItem::loadedState:
  113.          strState.LoadString( IDS_LOADEDSTATE );
  114.          strWindowStatus.Empty();
  115.          break;
  116.  
  117.       case COleClientItem::emptyState:
  118.          strState.LoadString( IDS_EMPTYSTATE );
  119.          strWindowStatus.Empty();
  120.          break;
  121.  
  122.       default:
  123.          ASSERT( FALSE );
  124.          break;
  125.       }
  126.       m_listObjects.SetItemText( iItem, 1, strState );
  127.       m_listObjects.SetItemText( iItem, 2, strWindowStatus );
  128.       iItem++;
  129.    }
  130.  
  131.    m_listObjects.SetColumnWidth( 0, LVSCW_AUTOSIZE );
  132.    nAutoWidth = m_listObjects.GetColumnWidth( 0 );
  133.    m_listObjects.SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER );
  134.    nAutoHeaderWidth = m_listObjects.GetColumnWidth( 0 );
  135.    m_listObjects.SetColumnWidth( 0, max( nAutoWidth, nAutoHeaderWidth ) );
  136.  
  137.    m_listObjects.SetColumnWidth( 1, LVSCW_AUTOSIZE );
  138.    nAutoWidth = m_listObjects.GetColumnWidth( 1 );
  139.    m_listObjects.SetColumnWidth( 1, LVSCW_AUTOSIZE_USEHEADER );
  140.    nAutoHeaderWidth = m_listObjects.GetColumnWidth( 1 );
  141.    m_listObjects.SetColumnWidth( 1, max( nAutoWidth, nAutoHeaderWidth ) );
  142.  
  143.    m_listObjects.SetColumnWidth( 2, LVSCW_AUTOSIZE );
  144.    nAutoWidth = m_listObjects.GetColumnWidth( 2 );
  145.    m_listObjects.SetColumnWidth( 2, LVSCW_AUTOSIZE_USEHEADER );
  146.    nAutoHeaderWidth = m_listObjects.GetColumnWidth( 2 );
  147.    m_listObjects.SetColumnWidth( 2, max( nAutoWidth, nAutoHeaderWidth ) );
  148.  
  149.     return( TRUE );
  150. }
  151.  
  152. static DWORD rgmapCHID[] =
  153. {
  154.    IDC_OBJECTS, HIDC_OBJECTS,
  155.    0, 0
  156. };
  157.  
  158. BOOL CContainerInfoDlg::OnHelpInfo( HELPINFO* pHelpInfo )
  159. {
  160.    return( ::WinHelp( HWND( pHelpInfo->hItemHandle ),
  161.       AfxGetApp()->m_pszHelpFilePath, HELP_WM_HELP, DWORD( LPVOID(
  162.       rgmapCHID ) ) ) );
  163. }
  164.  
  165. void CContainerInfoDlg::OnContextMenu( CWnd* pWnd, CPoint /* point */ )
  166. {
  167.    ::WinHelp( HWND( *pWnd ), AfxGetApp()->m_pszHelpFilePath, HELP_CONTEXTMENU,
  168.       DWORD( LPVOID( rgmapCHID ) ) );
  169. }
  170.