📄 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 + -