autocomplete for edit/combobox

To enable autocomplete for edit/combobox

Starting from IE 5.5 Microsoft added a very cool feature to any editboxes/comboboxes – you may start to enter some value and automatically will be suggested a value from "list" (previous typed)

As you understand now I’ll describe how to add such possibility to any editbox from your application:-)

1. you must declare a few const values:

const
SHACF_AUTOSUGGEST_FORCE_ON = $10000000;
SHACF_AUTOSUGGEST_FORCE_OFF = $20000000;
SHACF_AUTOAPPEND_FORCE_ON = $40000000;
SHACF_AUTOAPPEND_FORCE_OFF = $80000000;
SHACF_DEFAULT = $0;
SHACF_FILESYSTEM = $1;
SHACF_URLHISTORY = $2;
SHACF_URLMRU = $4;

2. you must declare a SHAutoComplete function from Shlwapi.dll library:

function SHAutoComplete(hwndEdit: HWnd; dwFlags: DWORD): HResult; stdcall; external ‘Shlwapi.dll’;

3. now you’re ready to add an autosuggestion to your editbox:

var
  Options: dWord;
begin
  Options := SHACF_FILESYSTEM or SHACF_URLHISTORY or SHACF_URLMRU or
              SHACF_AUTOSUGGEST_FORCE_ON or SHACF_AUTOAPPEND_FORCE_ON;
  SHAutoComplete(yourEditBox.Handle, Options);
end;

Of course, you may remove some flags from Options parameter. For example, if you’ll exclude the SHACF_URLHISTORY flag, end-user will not see the history of visited URLs

NOTE:

if your application must work in any environment (not only with IE 5.5+), then better to load Shlwapi.dll library dinamically but not link as I shown in this tip. You may read a tip#130 where I described how to work with dll’s: Article# 130

[From]Delphi tip#148: autocomplete for edit/combobox

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据