ComboBoxSearch.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // ComboBoxSearch.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "ComboBoxSearch.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CComboBoxSearch
  13. CComboBoxSearch::CComboBoxSearch()
  14. {
  15. m_bShowingDropDown = FALSE;
  16. }
  17. CComboBoxSearch::~CComboBoxSearch()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(CComboBoxSearch, CComboBox)
  21. //{{AFX_MSG_MAP(CComboBoxSearch)
  22. ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropdown)
  23. ON_CONTROL_REFLECT(CBN_SELENDCANCEL, OnSelendcancel)
  24. ON_CONTROL_REFLECT(CBN_SELENDOK, OnSelendok)
  25. //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CComboBoxSearch message handlers
  29. void CComboBoxSearch::OnDropdown()
  30. {
  31. m_bShowingDropDown = TRUE;
  32. SetCurSel(0);
  33. }
  34. void CComboBoxSearch::OnSelendcancel()
  35. {
  36. m_bShowingDropDown = FALSE;
  37. }
  38. void CComboBoxSearch::OnSelendok()
  39. {
  40. m_bShowingDropDown = FALSE;
  41. }
  42. BOOL CComboBoxSearch::PreTranslateMessage(MSG* pMsg)
  43. {
  44. switch(pMsg->message)
  45. {
  46. case WM_KEYDOWN:
  47. {
  48. if(pMsg->wParam == VK_RETURN && m_bShowingDropDown == FALSE)
  49. {
  50. CWnd *pWnd = GetParent();
  51. if(pWnd)
  52. {
  53. if(GetCurSel() == -1)
  54. {
  55. //Add the text to the combo
  56. CString csText;
  57. GetWindowText(csText);
  58. int nRet = InsertString(0, csText);
  59. SetCurSel(nRet);
  60. }
  61. //Send a message to the parent to refill the lb from the search
  62. pWnd->PostMessage(CB_SEARCH, 0, 0);
  63. }
  64. return TRUE;
  65. }
  66. if (pMsg->wParam == VK_DOWN)
  67. {
  68. if(!m_bShowingDropDown)
  69. {
  70. ShowDropDown();
  71. return TRUE;
  72. }
  73. }
  74. break;
  75. }
  76. }
  77. return CComboBox::PreTranslateMessage(pMsg);
  78. }