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

📄 comboboxex.cpp

📁 一个多窗口的浏览器的程序benbrowse
💻 CPP
字号:
// ComboBoxEx.cpp : implementation file
//
// Autocompleting combo-box (like the URL edit box in netscape)
//
// Written by Chris Maunder (Chris.Maunder@cbr.clw.csiro.au)
// Copyright (c) 1998.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name is included. If 
// the source code in  this file is used in any commercial application 
// then acknowledgement must be made to the author of this file 
// (in whatever form you wish).
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to your
// computer, causes your pet cat to fall ill, increases baldness or
// makes you car start emitting strange noises when you start it up.
//
// Expect bugs.
// 
// Please use and enjoy. Please let me know of any bugs/mods/improvements 
// that you have found/implemented and I will fix/incorporate them into this
// file. 
//
// Modified: 12 Sep 1998 Setting correct cursor position after 
//                       auto-complete: Petr Stejskal and Ryan Schneider
//
/////////////////////////////////////////////////////////////////////////////

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

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

/////////////////////////////////////////////////////////////////////////////
// CComboBoxExBen

CComboBoxExBen::CComboBoxExBen()
{
	m_bAutoComplete = FALSE;
}

CComboBoxExBen::~CComboBoxExBen()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CComboBoxExBen message handlers

BOOL CComboBoxExBen::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 CComboBoxExBen::OnEditUpdate() 
{
  // if we are not to auto update the text, get outta here
  if (!m_bAutoComplete) 
      return;
  //ssShowDropDown(TRUE);
  // Get the text in the edit box
  CString str;
  GetWindowText(str);
  int nLength = str.GetLength();
  
  // Currently selected range
  DWORD dwCurSel = GetEditSel();
  WORD dStart = LOWORD(dwCurSel);
  WORD dEnd   = HIWORD(dwCurSel);

  // 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
      if (dwCurSel != CB_ERR)
        SetEditSel(dStart, dEnd);	//restore cursor postion
  }

  // Set the text selection as the additional text that we have added
  if (dEnd < nLength && dwCurSel != CB_ERR)
      SetEditSel(dStart, dEnd);
  else
      SetEditSel(nLength, -1);
}

int CComboBoxExBen::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CComboBox::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	TCHAR           sz[MAX_PATH];
	TCHAR           sz2[MAX_PATH];
	TCHAR           szPath[MAX_PATH];
	HKEY            hKey;
	DWORD           dwSize;
	if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Internet Explorer\\TypedUrls"), &hKey) != ERROR_SUCCESS)
	{
		TRACE0("Favorites folder not found\n");
		return 0;
	}
	CString URL;
	dwSize = sizeof(sz);
	
	for(int i=0;i<25;i++)
	{
		dwSize = sizeof(sz);
		memset(sz,0,dwSize);
		RegEnumValue(hKey,i,szPath,&dwSize,NULL,NULL,(LPBYTE)sz, &dwSize);
		ExpandEnvironmentStrings(sz, sz2, MAX_PATH);
		URL=sz2;
		if(URL)
			AddString(URL);
	}


	RegCloseKey(hKey);

	return 0;
}

⌨️ 快捷键说明

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