实现文本框输入的自动提示

admin2021-08-01  318

import win.ui;
/*DSG{{*/
var winform = win.form(parent=...; right=349;text="aardio Form";bottom=249 )
winform.add(
button={ bottom=110;text="button";left=256;top=76;font=LOGFONT( name="宋体";h=-12 );z=3;right=326;cls="button" };
static={ bottom=62;text="实现文本框输入的自动提示,请输入0或a";left=28;top=36;font=LOGFONT( name="宋体";h=-12 );transparent=1;z=4;right=328;cls="static" };
listbox={ cls="listbox";bgcolor=16777215;vscroll=1;text="listbox";left=27;bottom=186;top=111;font=LOGFONT( name="宋体";h=-12 );
items={  };z=2;right=237;edge=1;hide=1 };
edit={ bottom=111;right=237;left=27;multiline=1;top=77;font=LOGFONT( name="宋体";h=-12 );z=1;text="";edge=1;cls="edit" }
)
/*}}*/

var keywords = /**
abc
abcd
abcdefg
012
0760
099998
**/;

winform.edit.wndproc = function(hwnd,message,wparam,lparam){
    if (message == 0x101/*_WM_KEYUP*/) {
        var str = string.trim(winform.edit.text);
        if (#str) {
            winform.listbox.clear();
            for m in string.gmatch( keywords, "(<@" ++ str ++ "@>+[^\r\n]+)") {
                winform.listbox.add(m);
            }
            if (winform.listbox.count) {
                winform.listbox.hide = 0;
                import  key.hook
                hk = key.hook();
                hk.proc=function(msg,vkcode,scancode){
                if (vkcode==40){
                    win.setFocus(winform.listbox.hwnd)
                 }              
              }
            } else {
                winform.listbox.hide = 1;
            }
        }
    }
}

winform.listbox.oncommand = function(id,event){
        if (winform.listbox.selText) {
            winform.edit.text = winform.listbox.selText;
            win.delay(500);
            winform.listbox.hide = 1;
            win.setFocus(winform.edit.hwnd)
            winform.edit.setsel(10,10)
        }
}

winform.show()
win.loopMessage();
return winform
转载请注明原文地址: http://aardio.net/read-194.html
最新回复(0)