⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comboboxex.cpp

📁 网络管理器源码
💻 CPP
字号:
// ComboBoxEx.cpp : implementation file
//
// Copyright (c) Chris Maunder 1997.
// Please feel free to use and distribute.

#include "stdafx.h"
#include "ComboBoxEx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CComboBoxEx

CComboBoxEx::CComboBoxEx()
{
	m_bAutoComplete = TRUE;
}

CComboBoxEx::~CComboBoxEx()
{
}


BEGIN_MESSAGE_MAP(CComboBoxEx, CComboBox)
	//{{AFX_MSG_MAP(CComboBoxEx)
	ON_CONTROL_REFLECT(CBN_EDITUPDATE, OnEditUpdate)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CComboBoxEx message handlers

BOOL CComboBoxEx::PreTranslateMessage(MSG* pMsg)
{
	// Need to check for backspace/delete. These will modify the text in
	// the edit box, causing the auto complete to just add back the text
	// the user has just tried to delete. 

	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 CComboBoxEx::OnEditUpdate() 
{
  DWORD dwCurSel = GetEditSel();
  int nStart = dwCurSel >> 16;
  int nEnd = dwCurSel & 0xffff;

  // if we are not to auto update the text, get outta here
	if (!m_bAutoComplete) return;

	// Get the text in the edit box
	CString str;
	GetWindowText(str);
	int nLength = str.GetLength();

	// Search for, and select in, and string in the combo box that is prefixed
	// by the text in the edit box
	if (SelectString(-1, str) == CB_ERR) 
		SetWindowText(str);		// No text selected, so restore what was there before

	// Set the text selection as the additional text that we have added
  if(nEnd < nLength)
    SetEditSel(nStart, nEnd);
  else
    SetEditSel(nLength, -1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -