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

  1. // PropertyEditRequestsPage.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. CPropertyEditRequestsPage::CPropertyInfo::CPropertyInfo() :
  15.    m_tLogged( TRUE ),
  16.    m_iResponse( REQUESTEDIT_ALWAYS )
  17. {
  18. }
  19.  
  20. CPropertyEditRequestsPage::CPropertyInfo::CPropertyInfo( LPCTSTR pszName,
  21.    BOOL tLogged, int iResponse ) :
  22.    m_strName( pszName ),
  23.    m_tLogged( tLogged ),
  24.    m_iResponse( iResponse )
  25. {
  26. }
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CPropertyEditRequestsPage dialog
  30.  
  31. IMPLEMENT_DYNCREATE( CPropertyEditRequestsPage, CPropertyPage )
  32.  
  33. CPropertyEditRequestsPage::CPropertyEditRequestsPage() :
  34.    CPropertyPage( CPropertyEditRequestsPage::IDD )
  35. {
  36.    m_psp.dwFlags &= ~PSP_HASHELP;
  37.  
  38.     //{{AFX_DATA_INIT(CPropertyEditRequestsPage)
  39.     m_iAllowEdit = -1;
  40.     //}}AFX_DATA_INIT
  41. }
  42.  
  43.  
  44. void CPropertyEditRequestsPage::DoDataExchange( CDataExchange* pDX )
  45. {
  46.    int iProperty;
  47.    int iItem;
  48.  
  49.     CDialog::DoDataExchange(pDX);
  50.     //{{AFX_DATA_MAP(CPropertyEditRequestsPage)
  51.     DDX_Control(pDX, IDC_PROPERTIES_EDITREQUESTS, m_lbProperties);
  52.     DDX_Radio(pDX, IDC_ALWAYS, m_iAllowEdit);
  53.     //}}AFX_DATA_MAP
  54.  
  55.    if( m_lbProperties.GetCount() > 0 )
  56.    {
  57.       for( iItem = 0; iItem < m_lbProperties.GetCount(); iItem++ )
  58.       {
  59.          iProperty = m_lbProperties.GetItemData( iItem );
  60.          if( pDX->m_bSaveAndValidate )
  61.          {
  62.             m_aProperties[iProperty].m_tLogged = m_lbProperties.GetCheck(
  63.                iItem );
  64.          }
  65.          else
  66.          {
  67.             m_lbProperties.SetCheck( iItem, m_aProperties[
  68.                iProperty].m_tLogged != FALSE );
  69.          }
  70.       }
  71.    }
  72. }
  73.  
  74.  
  75. BEGIN_MESSAGE_MAP(CPropertyEditRequestsPage, CDialog)
  76.     //{{AFX_MSG_MAP(CPropertyEditRequestsPage)
  77.     ON_LBN_SELCHANGE(IDC_PROPERTIES_EDITREQUESTS, OnPropertiesSelChange)
  78.     ON_BN_CLICKED(IDC_ALWAYS, OnAlways)
  79.     ON_BN_CLICKED(IDC_NEVER, OnNever)
  80.     ON_BN_CLICKED(IDC_PROMPT, OnPrompt)
  81.     ON_BN_CLICKED(IDC_SELECTALL_EDITREQUESTS, OnSelectAll)
  82.     ON_WM_HELPINFO()
  83.     ON_WM_CONTEXTMENU()
  84.     //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CPropertyEditRequestsPage message handlers
  89.  
  90. BOOL CPropertyEditRequestsPage::OnInitDialog()
  91. {
  92.    int iProperty;
  93.    int iItem;
  94.  
  95.     CDialog::OnInitDialog();
  96.  
  97.    for( iProperty = 0; iProperty < m_aProperties.GetSize(); iProperty++ )
  98.    {
  99.       iItem = m_lbProperties.AddString( m_aProperties[iProperty].m_strName );
  100.       m_lbProperties.SetItemData( iItem, iProperty );
  101.    }
  102.  
  103.    UpdateData( FALSE );
  104.  
  105.    OnPropertiesSelChange();
  106.  
  107.     return( TRUE );
  108. }
  109.  
  110. void CPropertyEditRequestsPage::OnPropertiesSelChange()
  111. {
  112.    int iResponse;
  113.    CWnd* pAlways;
  114.    CWnd* pNever;
  115.    CWnd* pPrompt;
  116.  
  117.    pAlways = GetDlgItem( IDC_ALWAYS );
  118.    pNever = GetDlgItem( IDC_NEVER );
  119.    pPrompt = GetDlgItem( IDC_PROMPT );
  120.  
  121.    if( m_lbProperties.GetSelCount() == 0 )
  122.    {
  123.       // Nothing is selected, so disable the radio buttons.
  124.       pAlways->EnableWindow( FALSE );
  125.       pNever->EnableWindow( FALSE );
  126.       pPrompt->EnableWindow( FALSE );
  127.    }
  128.    else
  129.    {
  130.       pAlways->EnableWindow( TRUE );
  131.       pNever->EnableWindow( TRUE );
  132.       pPrompt->EnableWindow( TRUE );
  133.    }
  134.  
  135.    iResponse = GetSelectionResponse();
  136.  
  137.    pAlways->SendMessage( BM_SETCHECK, 0, 0 );
  138.    pNever->SendMessage( BM_SETCHECK, 0, 0 );
  139.    pPrompt->SendMessage( BM_SETCHECK, 0, 0 );
  140.  
  141.    switch( iResponse )
  142.    {
  143.    case REQUESTEDIT_ALWAYS:
  144.       pAlways->SendMessage( BM_SETCHECK, 1, 0 );
  145.       break;
  146.  
  147.    case REQUESTEDIT_NEVER:
  148.       pNever->SendMessage( BM_SETCHECK, 1, 0 );
  149.       break;
  150.  
  151.    case REQUESTEDIT_PROMPT:
  152.       pPrompt->SendMessage( BM_SETCHECK, 1, 0 );
  153.       break;
  154.    }
  155. }
  156.  
  157. int CPropertyEditRequestsPage::GetSelectionResponse()
  158. {
  159.    int iProperty;
  160.    int iSelectedItem;
  161.    int* piSelectedItems;
  162.    int iResponse;
  163.    int nSelectedItems;
  164.    int nItemsInBuffer;
  165.    int iMultiResponse;
  166.  
  167.    nSelectedItems = m_lbProperties.GetSelCount();
  168.    if( nSelectedItems == 0 )
  169.    {
  170.       iMultiResponse = -1;
  171.    }
  172.    else
  173.    {
  174.       piSelectedItems = (int*)_alloca( nSelectedItems*sizeof( int ) );
  175.       nItemsInBuffer = m_lbProperties.GetSelItems( nSelectedItems,
  176.          piSelectedItems );
  177.       ASSERT( nItemsInBuffer == nSelectedItems );
  178.       iProperty = m_lbProperties.GetItemData( piSelectedItems[0] );
  179.       iMultiResponse = m_aProperties[iProperty].m_iResponse;
  180.       for( iSelectedItem = 1; iSelectedItem < nSelectedItems; iSelectedItem++ )
  181.       {
  182.          iProperty = m_lbProperties.GetItemData( piSelectedItems[
  183.             iSelectedItem] );
  184.          iResponse = m_aProperties[iProperty].m_iResponse;
  185.          if( iResponse != iMultiResponse )
  186.          {
  187.             iMultiResponse = -1;
  188.          }
  189.       }
  190.    }
  191.  
  192.    return( iMultiResponse );
  193. }
  194.  
  195. void CPropertyEditRequestsPage::SetSelectionResponse( int iResponse )
  196. {
  197.    int iSelectedItem;
  198.    int* piSelectedItems;
  199.    int nSelectedItems;
  200.    int nItemsInBuffer;
  201.  
  202.    ASSERT( iResponse != -1 );
  203.  
  204.    nSelectedItems = m_lbProperties.GetSelCount();
  205.    if( nSelectedItems > 0 )
  206.    {
  207.       piSelectedItems = (int*)_alloca( nSelectedItems*sizeof( int ) );
  208.       nItemsInBuffer = m_lbProperties.GetSelItems( nSelectedItems,
  209.          piSelectedItems );
  210.       ASSERT( nItemsInBuffer == nSelectedItems );
  211.       for( iSelectedItem = 0; iSelectedItem < nSelectedItems; iSelectedItem++ )
  212.       {
  213.          m_aProperties[piSelectedItems[iSelectedItem]].m_iResponse = iResponse;
  214.       }
  215.    }
  216. }
  217.  
  218. void CPropertyEditRequestsPage::OnAlways()
  219. {
  220.    SetSelectionResponse( REQUESTEDIT_ALWAYS );
  221. }
  222.  
  223. void CPropertyEditRequestsPage::OnNever()
  224. {
  225.    SetSelectionResponse( REQUESTEDIT_NEVER );
  226. }
  227.  
  228. void CPropertyEditRequestsPage::OnPrompt()
  229. {
  230.    SetSelectionResponse( REQUESTEDIT_PROMPT );
  231. }
  232.  
  233. void CPropertyEditRequestsPage::OnSelectAll()
  234. {
  235.    int nItems;
  236.  
  237.    nItems = m_lbProperties.GetCount();
  238.    m_lbProperties.SelItemRange( TRUE, 0, nItems-1 );
  239.  
  240.    OnPropertiesSelChange();
  241. }
  242.  
  243.  
  244. static DWORD rgmapCHID[] =
  245. {
  246.    IDC_PROPERTIES_EDITREQUESTS, HIDC_PROPERTIES_EDITREQUESTS,
  247.    IDC_PROMPT, HIDC_PROMPT,
  248.    IDC_ALWAYS, HIDC_ALWAYS,
  249.    IDC_NEVER, HIDC_NEVER,
  250.    IDC_SELECTALL_EDITREQUESTS, HIDC_SELECTALL_EDITREQUESTS,
  251.    0, 0
  252. };
  253.  
  254. BOOL CPropertyEditRequestsPage::OnHelpInfo( HELPINFO* pHelpInfo )
  255. {
  256.    return( ::WinHelp( HWND( pHelpInfo->hItemHandle ),
  257.       AfxGetApp()->m_pszHelpFilePath, HELP_WM_HELP, DWORD( LPVOID(
  258.       rgmapCHID ) ) ) );
  259. }
  260.  
  261. void CPropertyEditRequestsPage::OnContextMenu( CWnd* pWnd, CPoint /* point */ )
  262. {
  263.    ::WinHelp( HWND( *pWnd ), AfxGetApp()->m_pszHelpFilePath, HELP_CONTEXTMENU,
  264.       DWORD( LPVOID( rgmapCHID ) ) );
  265. }
  266.