COMCATDG.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:4k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // ComponentCategoriesDlg.Cpp : implementation file
  2. //
  3. #include "StdAfx.H"
  4. #include "TestCon.H"
  5. #include "resource.hm"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CComponentCategoriesDlg dialog
  13. CComponentCategoriesDlg::CComponentCategoriesDlg( UINT idCaption,
  14.    CWnd* pParent ) :
  15.    CDialog( CComponentCategoriesDlg::IDD, pParent ),
  16.    m_idCaption( idCaption )
  17. {
  18. //{{AFX_DATA_INIT(CComponentCategoriesDlg)
  19. // NOTE: the ClassWizard will add member initialization here
  20. //}}AFX_DATA_INIT
  21. }
  22. void CComponentCategoriesDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24.    int iItem;
  25.    int iCategory;
  26.    POSITION posSelectedCategory;
  27.    CATID catid;
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CComponentCategoriesDlg)
  30. DDX_Control(pDX, IDC_CATEGORIES, m_lbCategories);
  31. //}}AFX_DATA_MAP
  32.    if( pDX->m_bSaveAndValidate )
  33.    {
  34.   m_lSelectedCategories.RemoveAll();
  35.   for( iItem = 0; iItem < m_lbCategories.GetCount(); iItem++ )
  36.   {
  37.  if( m_lbCategories.GetCheck( iItem ) )
  38.  {
  39. iCategory = m_lbCategories.GetItemData( iItem );
  40. m_lSelectedCategories.AddTail( m_aAvailableCategories[iCategory] );
  41.  }
  42.   }
  43.    }
  44.    else
  45.    {
  46.   posSelectedCategory = m_lSelectedCategories.GetHeadPosition();
  47.   while( posSelectedCategory != NULL )
  48.   {
  49.  catid = m_lSelectedCategories.GetNext( posSelectedCategory );
  50.  iCategory = 0;
  51.  while( (iCategory < m_aAvailableCategories.GetSize()) && !IsEqualGUID(
  52. m_aAvailableCategories[iCategory], catid ) )
  53.  {
  54. iCategory++;
  55.  }
  56.  if( iCategory < m_aAvailableCategories.GetSize() )
  57.  {
  58. // We found the category
  59. iItem = 0;
  60. while( int( m_lbCategories.GetItemData( iItem ) ) != iCategory )
  61. {
  62.    iItem++;
  63.    ASSERT( iItem < m_lbCategories.GetCount() );
  64. }
  65. m_lbCategories.SetCheck( iItem, 1 );
  66.  }
  67.   }
  68.    }
  69. }
  70. BEGIN_MESSAGE_MAP(CComponentCategoriesDlg, CDialog)
  71. //{{AFX_MSG_MAP(CComponentCategoriesDlg)
  72. ON_BN_CLICKED(IDC_SELECTALL, OnSelectAll)
  73. ON_WM_HELPINFO()
  74. ON_WM_CONTEXTMENU()
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CComponentCategoriesDlg message handlers
  79. BOOL CComponentCategoriesDlg::OnInitDialog()
  80. {
  81.    IEnumCATEGORYINFOPtr pEnum;
  82.    HRESULT hResult;
  83.    BOOL tDone;
  84.    CATEGORYINFO info;
  85.    CString strCategory;
  86.    CString strCaption;
  87.    int iItem;
  88.    int iCategory;
  89. CDialog::OnInitDialog();
  90.    strCaption.LoadString( m_idCaption );
  91.    SetWindowText( strCaption );
  92.    hResult = m_pCatInfo.CreateInstance( CLSID_StdComponentCategoriesMgr, NULL,
  93.   CLSCTX_INPROC_SERVER );
  94.    if( FAILED( hResult ) )
  95.    {
  96.   TRACE( "Failed to create category manager.n" );
  97.   return( TRUE );
  98.    }
  99.    strCaption.LoadString( m_idCaption );
  100.    SetWindowText( strCaption );
  101.    hResult = m_pCatInfo->EnumCategories( GetUserDefaultLCID(), &pEnum );
  102.    if( FAILED( hResult ) )
  103.    {
  104.   TRACE( "Failed to enumerate categories.n" );
  105.   return( TRUE );
  106.    }
  107.    tDone = FALSE;
  108.    while( !tDone )
  109.    {
  110.   hResult = pEnum->Next( 1, &info, NULL );
  111.   if( hResult == S_OK )
  112.   {
  113.  strCategory = info.szDescription;
  114.  iItem = m_lbCategories.AddString( strCategory );
  115.  iCategory = m_aAvailableCategories.Add( info.catid );
  116.  m_lbCategories.SetItemData( iItem, iCategory );
  117.   }
  118.   else
  119.   {
  120.  tDone = TRUE;
  121.   }
  122.    }
  123.    UpdateData( FALSE );
  124. return( TRUE );
  125. }
  126. void CComponentCategoriesDlg::OnSelectAll()
  127. {
  128.    m_lbCategories.SelItemRange( TRUE, 0, m_lbCategories.GetCount() );
  129. }
  130. static DWORD rgmapCHID[] =
  131. {
  132.    IDC_CATEGORIES, HIDC_CATEGORIES,
  133.    IDC_SELECTALL, HIDC_SELECTALL,
  134.    0, 0
  135. };
  136. BOOL CComponentCategoriesDlg::OnHelpInfo( HELPINFO* pHelpInfo )
  137. {
  138.    return( ::WinHelp( HWND( pHelpInfo->hItemHandle ),
  139.   AfxGetApp()->m_pszHelpFilePath, HELP_WM_HELP, DWORD( LPVOID(
  140.   rgmapCHID ) ) ) );
  141. }
  142. void CComponentCategoriesDlg::OnContextMenu( CWnd* pWnd, CPoint /* point */ )
  143. {
  144.    ::WinHelp( HWND( *pWnd ), AfxGetApp()->m_pszHelpFilePath, HELP_CONTEXTMENU,
  145.   DWORD( LPVOID( rgmapCHID ) ) );
  146. }