(已解决)ComboBox 监控输入,自动匹配字符后弹出列表框问题
本帖最后由 lixiaolong 于 2011-3-13 21:52 编辑本人语言不好,请原谅.
请问如何实现ComboBox 实时监控输入,自动匹配字符后弹出列表框.
就是想实现和系统自带的“运行”一样的效果,用户输入字符后自动弹出列表框,显示匹配的字符.
这样的效果,好像是独立的列表框?
要匹配urllist.txt中的网址,路径.http://www.baidu.com
http://www.autoitscript.com/forum/index.php?app=core&module=attach§ion=attach&attach_id=11789
http://www.autoitscript.com/forum/topic/58072-autoit-operating-system-support
http://www.autoitscript.com/forum/topic/53453-run-script-as-system
http://www.autoitscript.com/forum/topic/54475-shellexecute-canceled
http://www.autoitscript.com/forum/topic/35500-system-level-run
http://www.autoitscript.com/forum/topic/18387-start-menu-run-dialog-with-registered-file-type
http://www.autoitscript.com/forum/topic/15785-how-to-open-the-start-menu-properties-with-run
http://www.autoitx.com/thread-15405-1-1.html
http://www.autoitx.com/logging.php?action=login&loginsubmit=yes&floatlogin=yes&inajax=1
http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=22733&pid=275258
http://www.autoitx.com/forum.php?mod=viewthread&tid=22733&rpid=275258&ordertype=0&page=1
http://www.autoitx.com
http://www.autoitx.com/archiver/tid-10908.html
http://www.zhcw.com/
%temp%\low
C:\Program Files\CCleaner\CCleaner.exe代码
#RequireAdmin
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=C:\Windows\System32\shell32.dll|-25
#AutoIt3Wrapper_outfile=运行.exe
#AutoIt3Wrapper_Res_Comment=模仿系统自带的“运行”
#AutoIt3Wrapper_Res_Description=模仿系统自带的“运行”
#AutoIt3Wrapper_Res_Fileversion=1.0.0.2
#AutoIt3Wrapper_Res_LegalCopyright=Lixiaolong
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("!b", "liulan")
HotKeySet("!d", "del")
GUICreate(" 模仿系统自带的运行", 411, 252, 8, 473, $WS_SYSMENU, $WS_EX_ACCEPTFILES)
GUISetBkColor(0xffffff)
GUISetFont(9, 400, '', '微软雅黑')
GUICtrlCreateIcon("shell32.dll", -77, 12, 23, 32, 32)
GUICtrlCreateLabel("Windows 将根据您所输入的名称,为您打开相应的程序、文件夹、文档或 Internet 资源。", _
63, 23, 319, 47)
GUICtrlCreateLabel("打开(&O):", 12, 83, 47, 21)
$file = GUICtrlCreateCombo("", 63, 79, 320, 500)
GUICtrlSetState($file, $GUI_DROPACCEPTED)
GUICtrlCreateIcon("user32.dll", -7, 63, 111, 16, 16)
GUICtrlCreateLabel("使用管理权限创建此任务。", 88, 113, 333, 23)
$btn = GUICtrlCreateButton("确定", 109, 174, 88, 30, 0x0001)
GUICtrlSetState(-1, $GUI_DISABLE)
$btn2 = GUICtrlCreateButton("取消", 203, 174, 88, 30)
$btn3 = GUICtrlCreateButton("浏览(&B)...", 298, 174, 88, 30)
GUISetState()
AdlibRegister("check", 100)
GUICtrlSetData($file, RegRead("HKEY_CURRENT_USER\Software\运行", "key"))
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_DROPPED
GUICtrlSetData($file, @GUI_DragFile, @GUI_DragFile)
Case $msg = $btn
yunxing(StringStripWS(GUICtrlRead($file), 3))
Case $msg = $btn2
ExitLoop
Case $msg = $btn3
$var = FileOpenDialog('浏览', @UserProfileDir & "\", "程序 (*.exe;*.pif;*.com;*.bat;*.cmd)")
If $var Then GUICtrlSetData($file, $var, $var)
EndSelect
WEnd
Func liulan()
ControlClick(" 模仿系统自带的运行", "", "Button3")
EndFunc ;==>liulan
Func del()
RegDelete("HKEY_CURRENT_USER\Software\运行")
GUICtrlSetData($file, "")
EndFunc ;==>del
Func check()
If GUICtrlRead($file) <> '' Then
GUICtrlSetState($btn, $GUI_ENABLE)
Else
GUICtrlSetState($btn, $GUI_DISABLE)
EndIf
EndFunc ;==>check
Func yunxing($set)
Local $test, $test2, $Right4 = StringRight($set, 4)
While 1
If $set = "" Then
ExitLoop
Else
If StringInStr($set, '%') <> 0 Then
_ShellExecute($set)
ExitLoop
Else
_ShellExecuteW($set)
ExitLoop
EndIf
EndIf
WEnd
EndFunc ;==>yunxing
Func _ShellExecuteW($Str)
$len = StringLen($Str)
For $i = 1 To 1000
If StringInStr(StringRight($Str, $i), ' ') <> 0 Then
ExitLoop
EndIf
Next
If StringInStr(StringMid($Str, $len - $i + 1), '\') <> 0 Then
$frag = ShellExecute(StringMid($Str, 1, $len - $i) & StringMid($Str, $len - $i + 1))
If $frag Then reg($Str)
Else
$frag = ShellExecute(StringMid($Str, 1, $len - $i), StringMid($Str, $len - $i + 1))
If $frag Then reg($Str)
EndIf
EndFunc ;==>_ShellExecuteW
Func _ShellExecute($run)
$run2 = StringRegExp($run, '([^%]+)', 3)
For $i = 0 To UBound($run2) - 2
Next
If $i Then
$frag = ShellExecute(EnvGet($run2) & $run2)
If $frag Then reg($run)
Else
$frag = ShellExecute(EnvGet($run2))
If $frag Then reg($run)
EndIf
EndFunc ;==>_ShellExecute
Func reg($Tong)
$s = 0
$REG = RegRead("HKEY_CURRENT_USER\Software\运行", "key")
$key = $REG
If $REG = '' Then
RegWrite("HKEY_CURRENT_USER\Software\运行", "key", "REG_SZ", $Tong)
Else
$key = StringSplit($key, '|')
For $i = 1 To UBound($key) - 1
If $key[$i] = $Tong Then
$s = 1
ExitLoop
EndIf
Next
If Not $s Then RegWrite("HKEY_CURRENT_USER\Software\运行", "key", "REG_SZ", $REG & '|' & $Tong)
EndIf
$REG = RegRead("HKEY_CURRENT_USER\Software\运行", "key")
GUICtrlSetData($file, '')
GUICtrlSetData($file, $REG, $Tong)
EndFunc ;==>reg
我试了很多方法还是不行,实在是不明白,请大家帮帮忙,谢谢.
AdlibRegister('UrlList', 100); 这是例子
Func UrlList()
If GUICtrlRead($file) <> '' And StringLen(GUICtrlRead($file)) < 10 Then
Dim $UrlUrl
$UrlList = FileRead(FileOpen('Urllist.txt', 0))
$UrlList = StringRegExp($UrlList, '.+', 3)
For $i = 0 To UBound($UrlList) - 1
If StringInStr($UrlList[$i], GUICtrlRead($file)) <> 0 Then
If $i = 0 Then GUICtrlSetData($file, '')
GUICtrlSetData($file, $UrlList[$i])
EndIf
Next
_GUICtrlComboBox_ShowDropDown($file, 1)
EndIf
EndFunc ;==>UrlList 本帖最后由 boyhong 于 2011-3-13 14:07 编辑
不知道用事件模式能搞定不?例如我曾经有:
$Combo1 = GUICtrlCreateCombo("↓选择查找条件↓", 240, 56, 170, 25,$CBS_DROPDOWNLIST)
GUICtrlSetData($Combo1, $bumen&","&$gzdata&","&$bibtsj&","&$gyzt&","&$mem&","&$mem1&","&$zcgs&","&$gonghao&","&$sn&","&$xinghao&","&$name)
GUICtrlSetOnEvent(-1, "_xuanze")
再不行,就把想法接着写进事件模式的循环里去呢?
这样来监控这个GUICtrlCreateCombo。关于怎么匹配,抱歉。我不会。。。我的想法并不成熟,仅供您参考一下。
忘记上传测试用的list文件
本帖最后由 lynfr8 于 2011-3-13 19:47 编辑PS
这类型需要监听控件的问题尽量还是从控件通知消息入手,简单直接!
UDF关键:_GUICtrlComboBox_ShowDropDown,_GUICtrlComboBox_ResetContent,_GUICtrlComboBox_SetEditText,_GUICtrlComboBox_AddString
论坛资料参考:Autoit系统消息详解——GUI通知补充
拓展参考:
windows控件消息和控件通知消息c/c++资料篇
Edit Control Notification Codes
EN_SETFOCUS
EN_KILLFOCUS
EN_CHANGE
EN_UPDATE
EN_ERRSPACE
EN_MAXTEXT
EN_HSCROLL
EN_VSCROLL
Edit Control Messages
EM_GETSEL
EM_SETSEL
EM_GETRECT
EM_SETRECT
EM_SETRECTNP
EM_SCROLL
EM_LINESCROLL
EM_SCROLLCARET
EM_GETMODIFY
EM_SETMODIFY
EM_GETLINECOUNT
EM_LINEINDEX
EM_SETHANDLE
EM_GETHANDLE
EM_GETTHUMB
EM_LINELENGTH
EM_REPLACESEL
EM_GETLINE
EM_LIMITTEXT
EM_CANUNDO
EM_UNDO
EM_FMTLINES
EM_LINEFROMCHAR
EM_SETTABSTOPS
EM_SETPASSWORDCHAR
EM_EMPTYUNDOBUFFER
EM_GETFIRSTVISIBLELINE
EM_SETREADONLY
EM_SETWORDBREAKPROC
EM_GETWORDBREAKPROC
EM_GETPASSWORDCHAR
EM_SETMARGINS
EM_GETMARGINS
EM_SETLIMITTEXT
EM_GETLIMITTEXT
EM_POSFROMCHAR
EM_CHARFROMPOS
EM_SETIMESTATUS
EM_GETIMESTATUS
User Button Notification Codes
BN_CLICKED
BN_PAINT
BN_HILITE
BN_UNHILITE
BN_DISABLE
BN_DOUBLECLICKED
BN_PUSHED
BN_UNPUSHED
BN_DBLCLK
BN_SETFOCUS
BN_KILLFOCUS
Button Control Messages
BM_GETCHECK
BM_SETCHECK
BM_GETSTATE
BM_SETSTATE
BM_SETSTYLE
BM_CLICK
BM_GETIMAGE
BM_SETIMAGE
BST_UNCHECKED
BST_CHECKED
BST_INDETERMINATE
BST_PUSHED
BST_FOCUS
Static Control Message
STM_SETICON
STM_GETICON
STM_SETIMAGE
STM_GETIMAGE
STN_CLICKED
STN_DBLCLK
STN_ENABLE
STN_DISABLE
STM_MSGMAX
Listbox Notification Codes
LBN_ERRSPACE
LBN_SELCHANGE
LBN_DBLCLK
LBN_SELCANCEL
LBN_SETFOCUS
LBN_KILLFOCUS
Listbox messages
LB_ADDSTRING
LB_INSERTSTRING
LB_DELETESTRING
LB_SELITEMRANGEEX
LB_RESETCONTENT
LB_SETSEL
LB_SETCURSEL
LB_GETSEL
LB_GETCURSEL
LB_GETTEXT
LB_GETTEXTLEN
LB_GETCOUNT
LB_SELECTSTRING
LB_DIR
LB_GETTOPINDEX
LB_FINDSTRING
LB_GETSELCOUNT
LB_GETSELITEMS
LB_SETTABSTOPS
LB_GETHORIZONTALEXTENT
LB_SETHORIZONTALEXTENT
LB_SETCOLUMNWIDTH
LB_ADDFILE
LB_SETTOPINDEX
LB_GETITEMRECT
LB_GETITEMDATA
LB_SETITEMDATA
LB_SELITEMRANGE
LB_SETANCHORINDEX
LB_GETANCHORINDEX
LB_SETCARETINDEX
LB_GETCARETINDEX
LB_SETITEMHEIGHT
LB_GETITEMHEIGHT
LB_FINDSTRINGEXACT
LB_SETLOCALE
LB_GETLOCALE
LB_SETCOUNT
LB_INITSTORAGE
LB_ITEMFROMPOINT
LB_MSGMAX
LB_MSGMAX
Combo Box Notification Codes
CBN_ERRSPACE
CBN_SELCHANGE
CBN_DBLCLK
CBN_SETFOCUS
CBN_KILLFOCUS
CBN_EDITCHANGE
CBN_EDITUPDATE
CBN_DROPDOWN
CBN_CLOSEUP
CBN_SELENDOK
CBN_SELENDCANCEL
Combo Box messages
NOWINMESSAGES
CB_GETEDITSEL
CB_LIMITTEXT
CB_SETEDITSEL
CB_ADDSTRING
CB_DELETESTRING
CB_DIR
CB_GETCOUNT
CB_GETCURSEL
CB_GETLBTEXT
CB_GETLBTEXTLEN
CB_INSERTSTRING
CB_RESETCONTENT
CB_FINDSTRING
CB_SELECTSTRING
CB_SETCURSEL
CB_SHOWDROPDOWN
CB_GETITEMDATA
CB_SETITEMDATA
CB_GETDROPPEDCONTROLRECT
CB_SETITEMHEIGHT
CB_GETITEMHEIGHT
CB_SETEXTENDEDUI
CB_GETEXTENDEDUI
CB_GETDROPPEDSTATE
CB_FINDSTRINGEXACT
CB_SETLOCALE
CB_GETLOCALE
CB_GETTOPINDEX
CB_SETTOPINDEX
CB_GETHORIZONTALEXTENT
CB_SETHORIZONTALEXTENT
CB_GETDROPPEDWIDTH
CB_SETDROPPEDWIDTH
CB_INITSTORAGE
CB_MSGMAX
CB_MSGMAX
Scroll bar messages
SBM_SETPOS
SBM_GETPOS
SBM_SETRANGE
SBM_SETRANGEREDRAW
SBM_GETRANGE
SBM_ENABLE_ARROWS
SBM_SETSCROLLINFO
SBM_GETSCROLLINFO
Date Time Picker Message
DTM_GETMCCOLOR
DTM_GETMCFONT
DTM_GETMONTHCAL
DTM_GETRANGE
DTM_GETSYSTEMTIME
DTM_SETFORMAT
DTM_SETMCCOLOR
DTM_SETMCFONT
DTM_SETRANGE
DTM_SETSYSTEMTIME
Date Time Picker Notifications
DTN_CLOSEUP
DTN_DATETIMECHANGE
DTN_DROPDOWN
DTN_FORMAT
IP Address Control
IPM_CLEARADDRESS
IPM_GETADDRESS
IPM_ISBLANK
IPM_SETADDRESS
IPM_SETFOCUS
IPM_SETRANGE
IP Address Control Notifications
IPN_FIELDCHANGED
Month Calendar Control Messages
MCM_GETCOLOR
MCM_GETCURSEL
MCM_GETFIRSTDAYOFWEEK
MCM_GETMAXSELCOUNT
MCM_GETMAXTODAYWIDTH
MCM_GETMINREQRECT
MCM_GETMONTHDELTA
MCM_GETMONTHRANGE
MCM_GETRANGE
MCM_GETSELRANGE
MCM_GETTODAY
MCM_GETUNICODEFORMAT
MCM_HITTEST
MCM_SETCOLOR
MCM_SETCURSEL
MCM_SETDAYSTATE
MCM_SETFIRSTDAYOFWEEK
MCM_SETMAXSELCOUNT
MCM_SETMONTHDELTA
MCM_SETRANGE
MCM_SETSELRANGE
MCM_SETTODAY
MCM_SETUNICODEFORMAT
Month Calendar Control Notification Messages
MCN_GETDAYSTATE
MCN_SELCHANGE
MCN_SELECT
NM_RELEASEDCAPTURE
Progress Bar Control Messages
PBM_DELTAPOS
PBM_GETPOS
PBM_GETRANGE
PBM_SETBARCOLOR
PBM_SETBKCOLOR
PBM_SETPOS
PBM_SETRANGE
PBM_SETRANGE32
PBM_SETSTEP
PBM_STEPIT
Pager Control Messages
PGM_FORWARDMOUSE
PGM_GETBKCOLOR
PGM_GETBORDER
PGM_GETBUTTONSIZE
PGM_GETBUTTONSTATE
PGM_GETDROPTARGET
PGM_GETPOS
PGM_RECALCSIZE
PGM_SETBKCOLOR
PGM_SETBORDER
PGM_SETBUTTONSIZE
PGM_SETCHILD
PGM_SETPOS
Pager Control Notifications
NM_RELEASEDCAPTURE
PGN_CALCSIZE
PGN_SCROLL
Animation Control Messages
ACM_OPEN
ACM_PLAY
ACM_STOP
Animation Control Notifications
ACN_START
ACN_STOP
Tab Control Messages
TCM_ADJUSTRECT
TCM_DELETEALLITEMS
TCM_DELETEITEM
TCM_DESELECTALL
TCM_GETCURFOCUS
TCM_GETCURSEL
TCM_GETEXTENDEDSTYLE
TCM_GETIMAGELIST
TCM_GETITEM
TCM_GETITEMCOUNT
TCM_GETITEMRECT
TCM_GETROWCOUNT
TCM_GETTOOLTIPS
TCM_GETUNICODEFORMAT
TCM_HIGHLIGHTITEM
TCM_HITTEST
TCM_INSERTITEM
TCM_REMOVEIMAGE
TCM_SETCURFOCUS
TCM_SETCURSEL
TCM_SETEXTENDEDSTYLE
TCM_SETIMAGELIST
TCM_SETITEM
TCM_SETITEMEXTRA
TCM_SETITEMSIZE
TCM_SETMINTABWIDTH
TCM_SETPADDING
TCM_SETTOOLTIPS
TCM_SETUNICODEFORMAT
Tab Control Notification Messages
NM_CLICK
NM_RCLICK
NM_RELEASEDCAPTURE
TCN_GETOBJECT
TCN_KEYDOWN
TCN_SELCHANGE
TCN_SELCHANGING
Tree View Control Messages
TVM_CREATEDRAGIMAGE
TVM_DELETEITEM
TVM_EDITLABEL
TVM_ENDEDITLABELNOW
TVM_ENSUREVISIBLE
TVM_EXPAND
TVM_GETBKCOLOR
TVM_GETCOUNT
TVM_GETEDITCONTROL
TVM_GETIMAGELIST
TVM_GETINDENT
TVM_GETINSERTMARKCOLOR
TVM_GETISEARCHSTRING
TVM_GETITEM
TVM_GETITEMHEIGHT
TVM_GETITEMRECT
TVM_GETNEXTITEM
TVM_GETSCROLLTIME
TVM_GETTEXTCOLOR
TVM_GETTOOLTIPS
TVM_GETUNICODEFORMAT
TVM_GETVISIBLECOUNT
TVM_HITTEST
TVM_INSERTITEM
TVM_SELECTITEM
TVM_SETBKCOLOR
TVM_SETIMAGELIST
TVM_SETINDENT
TVM_SETINSERTMARK
TVM_SETINSERTMARKCOLOR
TVM_SETITEM
TVM_SETITEMHEIGHT
TVM_SETSCROLLTIME
TVM_SETTEXTCOLOR
TVM_SETTOOLTIPS
TVM_SETUNICODEFORMAT
TVM_SORTCHILDREN
TVM_SORTCHILDRENCB
Tree View Notification Messages
NM_CLICK (tree view)
NM_CUSTOMDRAW (tree view)
NM_DBLCLK (tree view)
NM_KILLFOCUS (tree view)
NM_RCLICK (tree view)
NM_RCLICK (tree view)
NM_RETURN (tree view)
NM_SETCURSOR (tree view)
NM_SETFOCUS (tree view)
TVN_BEGINDRAG
TVN_BEGINLABELEDIT
TVN_BEGINRDRAG
TVN_DELETEITEM
TVN_ENDLABELEDIT
TVN_GETDISPINFO
TVN_GETINFOTIP
TVN_ITEMEXPANDED
TVN_ITEMEXPANDING
TVN_KEYDOWN
TVN_SELCHANGED
TVN_SELCHANGING
TVN_SETDISPINFO
TVN_SINGLEEXPAND
Hot Key Control Messages
HKM_GETHOTKEY
HKM_SETHOTKEY
HKM_SETRULES 谢谢分享!! 用消息,强,感谢楼上分享,已下载收藏了。。。 回复 2# boyhong
谢谢回复!这个我也试过,这次参考lynfr8前辈的代码问题解决了. 回复 4# lynfr8
谢谢前辈!问题解决了.
我还没学到消息之类的,有些看不懂,这次的问题我琢磨一个多星期了.
您给的代码我会慢慢研究的,这次真的谢谢您了! 弹出的列表没有向下展开的过程,且比Combox控件要窄,应该是Listbox或者Listview(SysListView32)控件,且是独立的窗体,可以用窗口信息探测工具确认下。 回复 9# afan
谢谢指点,我开始也觉得是个独立的,刚才确认了,好像是ListBox.
但是不知道怎么加到我的代码里...{:face (270):} 用消息比较准确而且及时,学习了。 lynfr8前辈真厉害,AU3在他手里就无所不能了 多谢 学习了 强大, 有用的东西太多了,前面的路还很长 回复 3# lynfr8
今天终于写完了模仿系统自带的“运行”.
再次感谢lynfr8前辈!
源码在http://www.autoitx.com/thread-17677-1-1.html(25楼)
页:
[1]
2