home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / docktool / searchbx.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  61 lines

  1. // searchbx.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "docktool.h"
  15. #include "searchbx.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CSearchBox
  24.  
  25. CSearchBox::CSearchBox()
  26. {
  27. }
  28.  
  29. CSearchBox::~CSearchBox()
  30. {
  31. }
  32.  
  33. BEGIN_MESSAGE_MAP(CSearchBox, CComboBox)
  34.     //{{AFX_MSG_MAP(CSearchBox)
  35.         // NOTE - the ClassWizard will add and remove mapping macros here.
  36.     //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CSearchBox message handlers
  41.  
  42. BOOL CSearchBox::PreTranslateMessage(MSG* pMsg)
  43. {
  44.     if ((pMsg->message != WM_KEYDOWN) || (pMsg->wParam != VK_RETURN))
  45.         return CComboBox::PreTranslateMessage(pMsg);
  46.  
  47.     // when the enter key is hit in the ComboBox we want to add the string
  48.     // to the top of the list and hilight it.  We also want to limit the
  49.     // list to the last 15 entries.
  50.     if ((pMsg->lParam & 0x40000000) == 0)   // Not a repeat.
  51.     {
  52.         CString strText;
  53.         GetWindowText(strText);
  54.         InsertString(0, strText);
  55.         SetCurSel(0);
  56.         if (GetCount() > 15)
  57.             DeleteString(GetCount()-1);
  58.     }
  59.     return TRUE;
  60. }
  61.