Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some questions about drop-down lists with filter function
#1
Hi,
The drop-down list with the filter function is very powerful, and I encountered the following problems in using it

1. How to match letters according to the order in which they appear?
For example, when I type the following letter, it doesn't match what I want,(Items matched from the beginning do not appear at the top)
wi
we
pr
o

I've set the sort tag to 8
ShowDropdownList(x i 0 8 hEdit 0 0 0 ddl)
[Image: 1671143713]
2. How to set the color of the border line of the edit box control?
The current border line color is white(Red arrow), I want to change it to green
[Image: 1671143810]
3. How bold only the text in the edit box? After set bold parameters for the edit box, but the text in the drop-down list(Red arrow) is also bolded
[Image: 1671144055]

Thank you in advance for any advice and help
david


Function AT_D_2
Trigger Aq     Help - how to add the trigger to the macro
Code:
Copy      Help
_s=
;sw 1 Switch
;wi 2 b
;wi 1 a
;ps Powershell
;we howc
;we how
;fun c Process
;fun b Pro
;pr file
;co ac
;oc cc

ARRAY(str) aList=_s
IQmDropdown ddl; int inERS

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 184 16 "Autotext" "4"
;3 Edit 0x54030080 0x200 0 0 184 16 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3"
str e3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam
__GdiHandle- t_hbrush
sel message
,case WM_INITDIALOG
,,int- backcolor=0x955100
,,int- textcolor=0xffffff
,,t_hbrush=CreateSolidBrush(backcolor)
,,__Font- f.Create("Consolas" 12 1)
,,f.SetDialogFont(hDlg "3")
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_CTLCOLOREDIT
,,if(lParam=id(3 hDlg))
,,,SetTextColor wParam textcolor
,,,SetBkColor wParam backcolor
,,,ret t_hbrush
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case EN_CHANGE<<16|3 sub.OnTextChanged lParam
ret 1

#sub OnTextChanged v
function hEdit

if(inERS) ret
if(ddl) ddl.Close; ddl=0

str s.getwintext(hEdit)
if(!s.len) ret

ICsv x._create
x.AddRow1(0 "0")
int i
for i 0 aList.len
,if(find(aList[i] s 0 1)<0) continue
,x.AddRow1(-1 aList[i])
if(!x.RowCount) ret

if(ShowDropdownList(x i 0 8 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret
s=x.Cell(i+1 0)

inERS=1
EditReplaceSel hEdit 0 s 1|2|4
inERS=0
#2
for #1 succeed

if(find(aList[i] s 0 1)<0) continue
to:
if(findrx(aList[i] F"^{s}" 0 1)<0) continue

for #2 #3 
No relevant information was found
#3
for #2 easiest solution is this
 
Code:
Copy      Help
_s=
;sw 1 Switch
;wi 2 b
;wi 1 a
;ps Powershell
;we howc
;we how
;fun c Process
;fun b Pro
;pr file
;co ac
;oc cc

ARRAY(str) aList=_s
IQmDropdown ddl; int inERS

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 184 16 "Autotext" "4"
;3 Edit 0x54030080 0x200 0 0 184 16 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3"
str e3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam
__GdiHandle- t_hbrush
sel message
,case WM_INITDIALOG
,,int- backcolor=0x955100
,,int- textcolor=0xffffff
,,t_hbrush=CreateSolidBrush(backcolor)
,,__Font- f.CreateNew(hDlg "Consolas" 12 1)
,,f.SetDialogFont(hDlg "3")
,case WM_DESTROY
,case WM_DRAWITEM
,DT_SCFC_on_WM_DRAWITEM hDlg wParam lParam
,case WM_COMMAND goto messages2
,case WM_CTLCOLOREDIT
,,if(lParam=id(3 hDlg))
,,,SetTextColor wParam textcolor
,,,SetBkColor wParam backcolor
,,,ret t_hbrush
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case EN_CHANGE<<16|3 sub.OnTextChanged lParam
,case EN_SETFOCUS<<16|3
,DT_ShowColorFocusControl hDlg
ret 1

#sub OnTextChanged v
function hEdit

if(inERS) ret
if(ddl) ddl.Close; ddl=0

str s.getwintext(hEdit)
if(!s.len) ret

ICsv x._create
x.AddRow1(0 "0")
int i
for i 0 aList.len
,if(find(aList[i] s 0 1)<0) continue
,x.AddRow1(-1 aList[i])
if(!x.RowCount) ret

if(ShowDropdownList(x i 0 8 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret
s=x.Cell(i+1 0)

inERS=1
EditReplaceSel hEdit 0 s 1|2|4
inERS=0

need two extra functions
Function DT_SCFC_on_WM_DRAWITEM
 
Code:
Copy      Help
function hDlg wParam lParam

;Call this from dialog procedure on WM_DRAWITEM.
;Makes the focus rectangle blue.

int color=0x00FF000 ;;green

if(wParam!999) ret
__GdiHandle-- t_brush=CreateSolidBrush(color)
DRAWITEMSTRUCT& d=+lParam
RECT r; GetClientRect d.hWndItem &r
FillRect d.hDC &r t_brush

Function DT_ShowColorFocusControl
Code:
Copy      Help
function hDlg

;Call this from dialog procedure whenever focused control changed.

int borderWidth=2

;create static control that will be the focus rectangle
int hr=id(999 hDlg 1)
if(!hr) hr=CreateControl(0 "Static" 0 SS_OWNERDRAW 0 0 0 0 hDlg 999)
ShowWindow hr 0

;get rectangle of focused control and move our focus rect control there
int hf=GetFocus; if(!hf) ret
RECT r; GetWindowRect hf &r; MapWindowPoints 0 hDlg +&r 2
MoveWindow hr r.left r.top r.right-r.left r.bottom-r.top 0

;make our focus rect control hollow, to look like a rectangle with 1 pixel border
OffsetRect &r -r.left -r.top
int r1=CreateRectRgnIndirect(&r)
__GdiHandle r2; InflateRect &r -borderWidth -borderWidth; r2=CreateRectRgnIndirect(&r)
CombineRgn r1 r1 r2 RGN_DIFF
SetWindowRgn hr r1 0

BringWindowToTop hr
ShowWindow hr SW_SHOW
#4
Thanks for your help, adding border lines works

The following code has no effect and does not select the first item, But it works in another post
x.AddRow1(0 "0")
#5
seems when using the sort function of the dropdown list the selected item will be the original first item so
to fix sort the csv before then all will work
 
Code:
Copy      Help
_s=
;sw 1 Switch
;wi 2 b
;wi 1 a
;ps Powershell
;we howc
;we how
;fun c Process
;fun b Pro
;pr file
;co ac
;oc cc

ARRAY(str) aList=_s

IQmDropdown ddl; int inERS

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 184 16 "Autotext" "4"
;3 Edit 0x54030080 0x200 0 0 184 16 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3"
str e3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
out e3
#sub DlgProc
function# hDlg message wParam lParam

__GdiHandle- t_hbrush
sel message
,case WM_INITDIALOG
,int- backcolor=0x955100
,int- textcolor=0xffffff
,t_hbrush=CreateSolidBrush(backcolor)
,__Font- f.CreateNew(hDlg "Consolas" 12 1)
,f.SetDialogFont(hDlg "3")
,case WM_DESTROY
,case WM_DRAWITEM
,DT_SCFC_on_WM_DRAWITEM hDlg wParam lParam
,case WM_COMMAND goto messages2
,case WM_CTLCOLOREDIT
,,if(lParam=id(3 hDlg))
,,,SetTextColor wParam textcolor
,,,SetBkColor wParam backcolor
,,,ret t_hbrush
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case EN_CHANGE<<16|3 sub.OnTextChanged lParam
,case EN_SETFOCUS<<16|3
,DT_ShowColorFocusControl hDlg
ret 1

#sub OnTextChanged v
function hEdit

if(inERS) ret
if(ddl) ddl.Close; ddl=0

str s.getwintext(hEdit)
if(!s.len) ret
int iSelected
ICsv x._create
x.AddRow1(0 "")
int i
for i 0 aList.len
,if(find(aList[i] s 0 1)<0) continue
,x.AddRow1(-1 aList[i])
if(!x.RowCount) ret
x.Sort(3)
if(ShowDropdownList(x iSelected 0 0 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret
s=x.Cell(iSelected+1 0)

inERS=1
EditReplaceSel hEdit 0 s 1|2|4
inERS=0
SendMessage(GetParent(hEdit) WM_COMMAND IDOK 0)
#6
thank you so much
#7
@Kevin
How set the color of EM_SETCUEBANNER text, Now the color is gray. It's hard to see

,case WM_INITDIALOG
,SendMessage id(3 hDlg) EM_SETCUEBANNER 1 @" Please type the word "
#8
Cuebanner text color is not supported. Would  be complicated to try and implement. Would involve subclassing and then custom drawing the text. But it's has known issues.
#9
@Kevin
about #5 code (I made some changes):

I don't need to sort. I deleted the following line of code, but it doesn't work
 
Code:
Copy      Help
x.Sort(3)
demo:
[Image: a.gif]
I expect the result:
Type a:
c   1a
b   2a
a   3a
-------------
Type b:
c   1b
b   2b
a   3b    


Macro M8
Code:
Copy      Help
str _ts=
;a01c   1a
;a02b   2a
;a03a   3a
;b01c   1b
;b02b   2b
;b03a   3b    

IQmDropdown ddl; int inERS; 

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 158 13 "ABC" "4"
;3 Edit 0x54030080 0x200 0 0 158 13 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3"
str e3

if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case EN_CHANGE<<16|3 sub.OnTextChanged lParam
ret 1

#sub OnTextChanged v
function hEdit

if(inERS) ret
if(ddl) ddl.Close; ddl=0

str s.getwintext(hEdit)
if(!s.len) ret

ICsv x._create
x.AddRow1(0 "")

ARRAY(str) a=_ts

if s="a"
,for _i 0 a.len
,,if(findrx(a[_i] "^a\d{2}(\S+\s+.+)" 0 0 _s 1)<0) continue
,,x.AddRow1(-1 _s)

if s="b"
,for _i 0 a.len
,,if(findrx(a[_i] "^b\d{2}(\S+\s+.+)" 0 0 _s 1)<0) continue
,,x.AddRow1(-1 _s)

if(!x.RowCount) ret
;x.Sort(3)

int iSelected
if(ShowDropdownList(x iSelected 0 8 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret
s=x.Cell(iSelected+1 0)

inERS=1
EditReplaceSel hEdit 0 s 1|2|4
inERS=0
#10
solved!

if(ShowDropdownList(x iSelected 0 8 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret
to
if(ShowDropdownList(x iSelected 0 0 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret


Forum Jump:


Users browsing this thread: 1 Guest(s)