Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SHAutoComplete
#1
How can I use SHAutoComplete in a dialog?
#2
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str e3
if(!ShowDialog("Dialog14" &Dialog14 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 222 134 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 12 10 96 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010900 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init hDlg lParam
,SHAutoComplete id(3 hDlg) 0 ;;read more in MSDN library
,case WM_DESTROY DT_DeleteData hDlg
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
#3
How can I create a combobox with own values and use autocomplete?
#4
There should be a very old topic for this, although not sure.
#5
can you show me an example, I don't find the old topic?
#6
QM Combo or Listbox with search
#7
Thanks.
#8
How can I get something like this (combobox):


Attached Files Image(s)
   
#9
Function CB_AutoComplete
Code:
Copy      Help
;/
function hcb

;Automatically completes when you type in combo box.
;Call from dialog procedure, on CBN_EDITCHANGE.
;hcb - combo box handle (use lParam).


;Does not allow to delete text from the end.

;EXAMPLE
,;case CBN_EDITCHANGE<<16|3
,;CB_AutoComplete lParam


str s ss; int i

s.getwintext(hcb)
if(s.len)
,i=CB_FindItem(hcb s)
,if(i>=0)
,,CB_GetItemText(hcb i ss)
,,if(ss.len>s.len)
,,,ss.setwintext(hcb)
,,,SendMessage(hcb CB_SETEDITSEL 0 ss.len<<16|s.len)

Example function Dialog14
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str cb3
cb3="&one[]two[]three[]four[]five[]six[]seven[]eight[]nine"
if(!ShowDialog("Dialog14" &Dialog14 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 220 132 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ComboBox 0x54230342 0x0 6 4 96 213 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010900 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam) ;;not necessary in QM >= 2.1.9
,ret 1 ;;not necessary in QM >= 2.1.9
,case WM_DESTROY DT_DeleteData(hDlg) ;;not necessary in QM >= 2.1.9
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case CBN_EDITCHANGE<<16|3
,CB_AutoComplete lParam
,case IDOK
,DT_Ok hDlg ;;not necessary in QM >= 2.1.9
,case IDCANCEL DT_Cancel hDlg ;;not necessary in QM >= 2.1.9
ret 1
#10
Thanks again.
and for delete text from the end?
#11
I would try to subclass the edit control, or install hook, and look for Delete and Backspace keys.
#12
Ok.
#13
It seems that it works.

Code:
Copy      Help
;/
function hcb

;Automatically completes when you type in combo box.
;Call from dialog procedure, on CBN_EDITCHANGE.
;hcb - combo box handle (use lParam).


;Allow to delete text from the end.

;EXAMPLE
,;case CBN_EDITCHANGE<<16|3
,;CB_AutoComplete lParam


str s ss; int i

s.getwintext(hcb)
if(s.len)
,i=CB_FindItem(hcb s)
,if(i>=0)
,,CB_GetItemText(hcb i ss)
,,if(ss.len>s.len)
,,,ss.setwintext(hcb)
,,,SendMessage(hcb CB_SETEDITSEL 0 ss.len<<16|s.len)
ifk(B)
,,str a.getwintext(hcb)
,,int s1 s2
,,SendMessage(hcb CB_GETEDITSEL &s1 &s2)
,,_i=s2-s1
,,_s.left(a a.len-_i)
,,_s.setwintext(hcb)
,,'E
#14
Yes, I forgot that Backspace is pressed at that time.
#15
This is my version:
Code:
Copy      Help
;/
function hcb

;Automatically completes when you type in combo box.
;Call from dialog procedure, on CBN_EDITCHANGE.
;hcb - combo box handle (use lParam).


;EXAMPLE
,;case CBN_EDITCHANGE<<16|3
,;CB_AutoComplete lParam


ifk(B) ret
ifk(X) ret

str s ss; int i

s.getwintext(hcb)
if(s.len)
,i=CB_FindItem(hcb s)
,if(i>=0)
,,CB_GetItemText(hcb i ss)
,,if(ss.len>s.len)
,,,ss.setwintext(hcb)
,,,SendMessage(hcb CB_SETEDITSEL 0 ss.len<<16|s.len)
#16
Simply Perfect.
#17
When I press the tab or enter key, the item in the combobox is not selected
[Image: a.png]
How to achieve the following effect?
[Image: b.png]
#18
Without the above functions,
In some cases, the match cannot be found, resulting in output errors

For example, typing qmd does not match QMD
[Image: b.gif]

Macro M2
Code:
Copy      Help
_s=
;abc
;ba
;QM
;QM3
;QMD
;cp
;es
;fw
;hw

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;4 Edit 0x54030080 0x200 116 8 96 12 ""
;5 Edit 0x54030080 0x204 116 32 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""

str controls = "3 4 5"
str cb3 e4 e5
cb3=_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
mes cb3


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,str e3sf.getwintext(id(4 hDlg))
,,e3sf.setwintext(id(5 hDlg))
,,e3sf.setwintext(id(3 hDlg))
,,
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case EN_CHANGE<<16|4
,SetTimer hDlg 1 100 0
,case CBN_EDITCHANGE<<16|3
,sub.CB_AutoComplete lParam
ret 1

#sub CB_AutoComplete
function hcb

ifk(B) ret
ifk(X) ret
str s ss; int i
s.getwintext(hcb)
if(s.len)
,i=CB_FindItem(hcb s)
,if(i>=0)
,,CB_GetItemText(hcb i ss)
,,if(ss.len>s.len)
,,,ss.setwintext(hcb)
,,,SendMessage(hcb CB_SETEDITSEL 0 ss.len<<16|s.len)


Forum Jump:


Users browsing this thread: 1 Guest(s)