?? comboboxex.cpp
字號:
#include "stdafx.h"
#include "ComboBoxEx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAutoComplete
CAutoComplete::CAutoComplete()
{
m_bAutoComplete = TRUE;
}
CAutoComplete::~CAutoComplete()
{
}
BEGIN_MESSAGE_MAP(CAutoComplete, CComboBox)
//{{AFX_MSG_MAP(CAutoComplete)
ON_CONTROL_REFLECT(CBN_EDITUPDATE, OnEditUpdate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAutoComplete message handlers
//處理消息循環
BOOL CAutoComplete::PreTranslateMessage(MSG* pMsg)
{
//捕捉按鍵消息
if (pMsg->message == WM_KEYDOWN)
{
m_bAutoComplete = TRUE;
int nVirtKey = (int) pMsg->wParam;
if (nVirtKey == VK_DELETE || nVirtKey == VK_BACK)
m_bAutoComplete = FALSE;
}
return CComboBox::PreTranslateMessage(pMsg);
}
//編輯框更新消息
void CAutoComplete::OnEditUpdate()
{
if (!m_bAutoComplete)
return;
//獲得編輯框的字符串
CString str;
GetWindowText(str);
int nLength = str.GetLength();
//當前選擇范圍
DWORD dwCurSel = GetEditSel();
WORD dStart = LOWORD(dwCurSel);
WORD dEnd = HIWORD(dwCurSel);
//在列表框中搜索與編輯框中匹配的字符串,然后使其被選擇
if (SelectString(-1, str) == CB_ERR)
{
SetWindowText(str);
if (dwCurSel != CB_ERR)
SetEditSel(dStart, dEnd);
}
if (dEnd < nLength && dwCurSel != CB_ERR)
SetEditSel(dStart, dEnd);
else
SetEditSel(nLength, -1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -