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 / pbagdg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.4 KB  |  134 lines

  1. // CPropertyBagDlg.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. void AutoSetColumnWidth( CListCtrl& list, int iColumn )
  15. {
  16.    int nAutoWidth;
  17.    int nAutoHeaderWidth;
  18.  
  19.    list.SetColumnWidth( iColumn, LVSCW_AUTOSIZE );
  20.    nAutoWidth = list.GetColumnWidth( iColumn );
  21.    list.SetColumnWidth( iColumn, LVSCW_AUTOSIZE_USEHEADER );
  22.    nAutoHeaderWidth = list.GetColumnWidth( iColumn );
  23.    list.SetColumnWidth( iColumn, max( nAutoWidth, nAutoHeaderWidth ) );
  24. }
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CPropertyBagDlg dialog
  28.  
  29.  
  30. CPropertyBagDlg::CPropertyBagDlg( CPropertyBag* pPropertyBag, CWnd* pParent ) :
  31.    CDialog( CPropertyBagDlg::IDD, pParent ),
  32.    m_pPropertyBag( pPropertyBag )
  33. {
  34.    ASSERT( m_pPropertyBag != NULL );
  35.  
  36.     //{{AFX_DATA_INIT(CPropertyBagDlg)
  37.         // NOTE: the ClassWizard will add member initialization here
  38.     //}}AFX_DATA_INIT
  39. }
  40.  
  41.  
  42. void CPropertyBagDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44.     CDialog::DoDataExchange(pDX);
  45.     //{{AFX_DATA_MAP(CPropertyBagDlg)
  46.     DDX_Control(pDX, IDC_PROPERTIES, m_lvProperties);
  47.     //}}AFX_DATA_MAP
  48. }
  49.  
  50.  
  51. BEGIN_MESSAGE_MAP(CPropertyBagDlg, CDialog)
  52.     //{{AFX_MSG_MAP(CPropertyBagDlg)
  53.     ON_WM_HELPINFO()
  54.     ON_WM_CONTEXTMENU()
  55.     //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CPropertyBagDlg message handlers
  60.  
  61. BOOL CPropertyBagDlg::OnInitDialog()
  62. {
  63.    USES_CONVERSION;
  64.    POSITION posItem;
  65.    CPropertyBagItem* pItem;
  66.    int iItem;
  67.    int iLVItem;
  68.    COleVariant varString;
  69.    CString strColumnTitle;
  70.    CString str;
  71.  
  72.    CDialog::OnInitDialog();
  73.  
  74.    // Add the appropriate columns to the parameter list control.
  75.    strColumnTitle.LoadString( IDS_PROPERTY );
  76.    m_lvProperties.InsertColumn( 0, strColumnTitle, LVCFMT_LEFT, 100 );
  77.    strColumnTitle.LoadString( IDS_VALUE );
  78.    m_lvProperties.InsertColumn( 1, strColumnTitle, LVCFMT_LEFT, 100 );
  79.    strColumnTitle.LoadString( IDS_TYPE );
  80.    m_lvProperties.InsertColumn( 2, strColumnTitle, LVCFMT_LEFT, 100 );
  81.  
  82.    iItem = 0;
  83.    posItem = m_pPropertyBag->GetFirstItemPosition();
  84.    while( posItem != NULL )
  85.    {
  86.       pItem = m_pPropertyBag->GetNextItem( posItem );
  87.       iLVItem = m_lvProperties.InsertItem( iItem, pItem->m_strName );
  88.       m_lvProperties.SetItemText( iLVItem, 0, pItem->m_strName );
  89.  
  90.       TRY
  91.       {
  92.          varString.ChangeType( VT_BSTR, pItem->m_varValue );
  93.          str = varString.bstrVal;
  94.       }
  95.       CATCH( COleException, e )
  96.       {
  97.          str.LoadString( IDS_UNABLETOREPRESENT );
  98.       }
  99.       END_CATCH
  100.  
  101.       m_lvProperties.SetItemText( iLVItem, 1, str );
  102.       m_lvProperties.SetItemText( iLVItem, 2, VTToString(
  103.          pItem->m_varValue.vt ) );
  104.  
  105.       iItem++;
  106.    }
  107.  
  108.    AutoSetColumnWidth( m_lvProperties, 0 );
  109.    AutoSetColumnWidth( m_lvProperties, 1 );
  110.    AutoSetColumnWidth( m_lvProperties, 2 );
  111.  
  112.     return( TRUE );
  113. }
  114.  
  115.  
  116. static DWORD rgmapCHID[] =
  117. {
  118.    IDC_PROPERTIES, HIDC_PROPERTIES,
  119.    0, 0
  120. };
  121.  
  122. BOOL CPropertyBagDlg::OnHelpInfo( HELPINFO* pHelpInfo )
  123. {
  124.    return( ::WinHelp( HWND( pHelpInfo->hItemHandle ),
  125.       AfxGetApp()->m_pszHelpFilePath, HELP_WM_HELP, DWORD( LPVOID(
  126.       rgmapCHID ) ) ) );
  127. }
  128.  
  129. void CPropertyBagDlg::OnContextMenu( CWnd* pWnd, CPoint /* point */ )
  130. {
  131.    ::WinHelp( HWND( *pWnd ), AfxGetApp()->m_pszHelpFilePath, HELP_CONTEXTMENU,
  132.       DWORD( LPVOID( rgmapCHID ) ) );
  133. }
  134.