ComboBoxSearch.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:4k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // ComboBoxSearch.cpp: implementation of the CComboBoxSearch class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "styler.h"
  6. #include "ComboBoxSearch.h"
  7. #include "PageSearch.h"
  8. #include "InetTools.h"
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[]=__FILE__;
  12. #define new DEBUG_NEW
  13. #endif
  14. IMPLEMENT_XTP_CONTROL(CComboBoxURL, CXTPControlComboBox)
  15. CComboBoxURL::CComboBoxURL(CXTPCommandBars* pCommandBars)
  16. {
  17. GetCommandBar()->SetCommandBars(pCommandBars); // Require to find Site.
  18. ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
  19. m_nEditIconId = ID_FAVORITE_LINK;
  20. }
  21. void CComboBoxURL::OnClick(BOOL bKeyboard , CPoint pt)
  22. {
  23. if (!bKeyboard && pt.x < m_rcControl.left + 16 + 5 && !m_pParent->IsCustomizeMode())
  24. {
  25. NMXTPCONTROL tagNMCONTROL;
  26. tagNMCONTROL.hdr.code = ID_LINK_STARTDRAG;
  27. tagNMCONTROL.hdr.idFrom = m_nId;
  28. tagNMCONTROL.hdr.hwndFrom = 0;
  29. tagNMCONTROL.pControl = this;
  30. NotifySite(ID_LINK_STARTDRAG, &tagNMCONTROL);
  31. return;
  32. }
  33. CXTPControlComboBox::OnClick(bKeyboard, pt);
  34. }
  35. void CComboBoxURL::OnMouseMove(CPoint pt) 
  36. {
  37. if (pt.x < m_rcControl.left + 16 + 5)
  38. {
  39. SetCursor(XTAuxData().hcurHand);
  40. }
  41. else
  42. {
  43. CXTPControlComboBox::OnMouseMove(pt);
  44. }
  45. }
  46. void CComboBoxURL::DoPropExchange(CXTPPropExchange* pPX)
  47. {
  48. CXTPControlComboBox::DoPropExchange(pPX);
  49. }
  50. void CComboBoxURL::UpdateComboBox()
  51. {
  52. CString strEntry;
  53. HKEY hReg;
  54. TCHAR chData[MAX_PATH];
  55. DWORD dwType = REG_SZ;
  56. ResetContent();
  57. if (RegOpenKeyEx(HKEY_CURRENT_USER, 
  58. _T("Software\Microsoft\Internet Explorer\TypedUrls"), 0, KEY_READ, &hReg) == ERROR_SUCCESS)
  59. {
  60. for (int iMRU = 0; ;iMRU++ )
  61. {
  62. strEntry.Format(_T("url%i"), iMRU + 1);
  63. DWORD dwData = MAX_PATH - 1;
  64. if (RegQueryValueEx(hReg, strEntry, NULL, &dwType , (LPBYTE)&chData, &dwData) == ERROR_SUCCESS)
  65. {
  66. AddString(chData);
  67. else break;
  68. }
  69. RegCloseKey(hReg);
  70. }
  71. }
  72. void CComboBoxURL::SaveTypedURL()
  73. {
  74. HKEY            hKey;
  75. try
  76. {
  77. RegDeleteKey(HKEY_CURRENT_USER, _T("Software\Microsoft\Internet Explorer\TypedUrls"));
  78. if(RegCreateKey(HKEY_CURRENT_USER, _T("Software\Microsoft\Internet Explorer\TypedUrls"), &hKey) != ERROR_SUCCESS)
  79. return ;
  80. int nCount = GetCount();
  81. CString str;
  82. CString id;
  83. int j = 0;
  84. for(int i = 0; i < nCount; i++)
  85. {
  86. GetLBText(i, str);
  87. if (!str.IsEmpty())
  88. {
  89. id.Format(_T("url%i"), ++j);
  90. RegSetValueEx(hKey, id, NULL, REG_SZ, (LPBYTE)(LPCTSTR)str, (str.GetLength() + 1) * sizeof(TCHAR));
  91. }
  92. }
  93. RegCloseKey(hKey);
  94. }
  95. catch(...)
  96. {
  97. }
  98. }
  99. /////////////////////////////////////////////////////////////////////
  100. // Construction/Destruction
  101. //////////////////////////////////////////////////////////////////////
  102. IMPLEMENT_XTP_CONTROL(CComboBoxSearch, CXTPControlComboBox)
  103. CComboBoxSearch::CComboBoxSearch(CXTPCommandBars* pCommandBars)
  104. {
  105. m_brWindow.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  106. GetCommandBar()->SetCommandBars(pCommandBars); // Require to find Site.
  107. ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
  108. CPageSearch::UpdateComboBox(this);
  109. if (CPageSearch::m_arrEngines.GetSize() > 0)
  110. {
  111. m_strEditHint = CPageSearch::m_arrEngines[0].strTitle;
  112. m_nCurrentEngine = 0;
  113. }
  114. else
  115. m_nCurrentEngine = -1;
  116. m_strEditText = m_strEditHint;
  117. }
  118. CComboBoxSearch::~CComboBoxSearch()
  119. {
  120. }
  121. void CComboBoxSearch::OnEditChanged()
  122. {
  123. }
  124. void CComboBoxSearch::OnSelChanged()
  125. {
  126. BOOL bUpdateText = (GetEditText().IsEmpty() && !IsFocused()) || GetEditText() == m_strEditHint;
  127. m_nCurrentEngine = GetCurSel();
  128. m_strEditHint = m_nCurrentEngine != -1? CPageSearch::m_arrEngines[m_nCurrentEngine].strTitle: _T("");
  129. if (bUpdateText)
  130. CXTPControlComboBox::OnSelChanged();
  131. }
  132. BOOL CComboBoxSearch::OnSetPopup(BOOL bPopup)
  133. {
  134. if (bPopup && m_pCommandBar)
  135. {
  136. CPageSearch::UpdateComboBox(this);
  137. }
  138. return CXTPControlComboBox::OnSetPopup(bPopup);
  139. }