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

  1. // MacroComboBox.Cpp : implementation file
  2. //
  3.  
  4. #include "StdAfx.H"
  5. #include "TestCon.H"
  6.  
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. const int MACROCOMBOBOX_MRUSIZE = 8;
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMacroComboBox
  17.  
  18. CMacroComboBox::CMacroComboBox()
  19. {
  20. }
  21.  
  22. CMacroComboBox::~CMacroComboBox()
  23. {
  24. }
  25.  
  26. void CMacroComboBox::AddMRUEntry( LPCTSTR pszMacroName )
  27. {
  28.    int iString;
  29.  
  30.    iString = FindStringExact( -1, pszMacroName );
  31.    if( iString != CB_ERR )
  32.    {
  33.       DeleteString( iString );
  34.    }
  35.  
  36.    ASSERT( GetCount() <= MACROCOMBOBOX_MRUSIZE );
  37.    if( GetCount() == MACROCOMBOBOX_MRUSIZE )
  38.    {
  39.       DeleteString( MACROCOMBOBOX_MRUSIZE-1 );
  40.    }
  41.  
  42.    InsertString( 0, pszMacroName );
  43. }
  44.  
  45. BEGIN_MESSAGE_MAP(CMacroComboBox, CComboBox)
  46.     //{{AFX_MSG_MAP(CMacroComboBox)
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CMacroComboBox message handlers
  52.  
  53. BOOL CMacroComboBox::PreTranslateMessage( MSG* pMsg )
  54. {
  55.    CString strMacroName;
  56.  
  57.    if( pMsg->message == WM_KEYDOWN )
  58.    {
  59.       if( pMsg->wParam == VK_RETURN )
  60.       {
  61.          if( (pMsg->lParam&0x04000000) == 0 )
  62.          {
  63.             if( GetWindowTextLength() > 0 )
  64.             {
  65.                GetWindowText( strMacroName );
  66.                AddMRUEntry( strMacroName );
  67.  
  68.                SetCurSel( 0 );
  69.                GetOwner()->SendMessage( WM_COMMAND, MAKELONG( ID_RUNMACRO, 0 ),
  70.                   LPARAM( m_hWnd ) );
  71.             }
  72.          }
  73.  
  74.          return( TRUE );
  75.       }
  76.    }
  77.  
  78.     return( CComboBox::PreTranslateMessage( pMsg ) );
  79. }
  80.