March 28, 2024, 10:46:46 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


How to: Add AutoComplete

Started by ZeroDog, July 26, 2012, 03:56:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ZeroDog






' How to: Add AutoComplete
' By ZeroDog
' ----------------------------------------------------------------------------------
' This tutorial describes how to add AutoComplete to an edit control.
' AutoComplete will automatically list previous URL and file system locations
' depending on the flags set.
' ----------------------------------------------------------------------------------

'The first thing we need to do is declare the API function and constants that
'are used with the AutoComplete.
declare import, AutoComplete alias SHAutoComplete(hwndEdit as uint,dwFlags as int)
' hwndEdit - handle to the control to use AutoComplete on.
' dwFlags - A set of flags that specify the AutoComplete behavior.

' The following constants are used for the dwFlags in AutoComplete.
const SHACF_AUTOSUGGEST_FORCE_ON = 0x10000000
' SHACF_AUTOSUGGEST_FORCE_ON - Force AutoSuggest on even if registry settings are off.
const SHACF_AUTOSUGGEST_FORCE_OFF = 0x20000000
' SHACF_AUTOSUGGEST_FORCE_OFF - Force AutoSuggest off even if registry settings are on.
const SHACF_AUTOAPPEND_FORCE_ON = 0x40000000
' SHACF_AUTOAPPEND_FORCE_ON - Force AutoAppend on even if registry settings are off.
const SHACF_AUTOAPPEND_FORCE_OFF = 0x80000000
' SHACF_AUTOAPPEND_FORCE_OFF - Force AutoAppend off even if registry settings are on.
const SHACF_DEFAULT = 0x0
' SHACF_DEFAULT - Use default settings from registry.
const SHACF_FILESYSTEM = 0x1
' SHACF_FILESYSTEM - Include the file system in AutoComplete.
const SHACF_URLHISTORY = 0x2
' SHACF_URLHISTORY - Include the URL History in AutoComplete.
const SHACF_URLMRU = 0x4
' SHACF_URLMRU - Include the URL Most Recently Used in AutoComplete.
const SHACF_USETAB = 0x8
' SHACF_USETAB -
const SHACF_FILESYS_ONLY = 0x10
' SHACF_FILESYS_ONLY - Only use the file system in AutoComplete.
const SHACF_URLALL = (SHACF_URLHISTORY || SHACF_URLMRU)
' SHACF_URLALL - Use both URL History and URL Most Recently Used in AutoComplete.

'We will need to know the handle of the edit control for the hwndEdit member of
'AutoComplete, so we will declare the GetDlgItem API function so we can retrieve it.
declare import,GetDlgItem(hwnd as uint,nID as int),int
' hwnd - handle to the window parent of the control.
' nID - ID of the control to get the handle of.

' Our window variable.
def win as window

' We will now open the window.
openwindow win,0,0,244,35,@nocaption|@border,0,"How to: Add AutoComplete",&winproc

' The edit control we will use autocomplete on.
control win,@edit,"",4,4,190,25,@cteditautoh,1

' The Go button that will launch the default program for the URL or file.
control win,@button,"Go",200,4,25,25,0,2

' The X button that will close the window.
control win,@button,"X",230,2,10,10,@ctlbtnflat|@border,3

' Color the X button red.
setcontrolcolor win,3,rgb(255,255,255),rgb(255,0,0)

'Now we will apply the AutoComplete to the edit control we created.
'We use the GetDlgItem in the first parameter of AutoComplete to pass the handle
'of the edit control to the function.
'The second parameter in AutoComplete is a set of the dwFlags to specify the behavior
'We have set it to force the autocomplete on, and to use the file system and
'both the URL History and the URL Most Recently Used in AutoComplete.
'Note: Unless FORCE mode flags are used, AutoComplete options are taken from registry settings.
AutoComplete(GetDlgItem(win.hwnd,1), SHACF_AUTOSUGGEST_FORCE_ON | SHACF_URLALL | SHACF_FILESYSTEM )

' Process window messages until run=0 (program closed).
run=1
waituntil run=0
closewindow win
end
' ----------------------------------------------------------------------------------


' ----------------------------------------------------------------------------------
' Our window message handler.
sub winproc(),int
select @message
'---------------------------------------------------------------
'Drag the window when the left mouse button is held down.
case @idlbuttondn
CONST WM_NCLBUTTONDOWN = 0xA1
sendmessage win, (WM_NCLBUTTONDOWN),2,0
'---------------------------------------------------------------
case @idcontrol
'If the user clicks the X button, close the program.
if (@controlid = 3) then run = 0
'If the user clicks the Go button,
if (@controlid = 2)
'If the edit box isnt empty, launch the default program for the URL or file.
if len(getcontroltext(win,1)) > 0 then system getcontroltext(win,1)
endif
'---------------------------------------------------------------
' When the window is first created, center it.
case @idcreate
centerwindow win
'---------------------------------------------------------------
' When the user closes the window, end the program.
case @idclosewindow
run=0
'---------------------------------------------------------------
endselect
return 0
endsub
' ----------------------------------------------------------------------------------