#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <GuiListBox.au3>
Global $ini = ".\set.ini"
Global $X = -1
Global $sText = FileRead(@ScriptDir & "\key.txt") ;读取所有关键词
$Form1 = GUICreate("输入框搜索", 466, 343, 192, 124)
$Button1 = GUICtrlCreateButton("读取", 272, 256, 75, 25, 0)
$Input1 = GUICtrlCreateInput("", 8, 16, 185, 21)
$list = GUICtrlCreateList("", 8, 16 + 21, 185, 140, 0x1000)
GUICtrlSetState(-1, $GUI_HIDE)
$wProcNew = DllCallbackRegister("_MyInputProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input1), -4, DllCallbackGetPtr($wProcNew))
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
Case $list ;得到$list点击消息
$sel = _GUICtrlListBox_GetCurSel($list)
Local $str = _GUICtrlListBox_GetText($list, $sel)
ConsoleWrite($str)
GUICtrlSetData($Input1, StringRegExpReplace($str, '\v', ''))
Case $Button1
$info = GUICtrlRead($Input1)
;MsgBox(0, "搜索结果", $info)
$res = IniRead($ini, $info, "工资", "")
MsgBox(0, $info, $res)
EndSwitch
WEnd
Func _MyInputProc($hWnd, $uiMsg, $wParam, $lParam)
Switch $uiMsg
Case $WM_KEYUP
Switch $wParam
Case 0x28 ;$VK_DOWN
$X += 1
_GUICtrlListBox_ClickItem($list, $X)
If $X = 9 Then $X = -1
Case 0x26 ;$VK_UP
$X -= 1
_GUICtrlListBox_ClickItem($list, $X)
If $X = 0 Then $X = 10
Case Else
_GUICtrlListBox_ResetContent($list)
$sInput= GUICtrlRead($Input1)
If $sInput= "" Then
GUICtrlSetState($list, $GUI_HIDE)
Return 1
EndIf
_set_data($sInput)
EndSwitch
EndSwitch
;向默认窗口进程传递未处理过的消息
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>_MyInputProc
Func _set_data($sKey)
$sre = StringRegExp($sText, '.+', 3)
If @error Then Return GUICtrlSetState($list, $GUI_HIDE)
Local $str = '', $C
For $i = 0 To UBound($sre) - 1
$C = StringLeft(StringStripWS($sre[$i], 1 + 2), 1)
If _C($C) = $sKey Then $str &= $sre[$i] & '|'
Next
$str = StringRegExpReplace($str, '\|, '')
_GUICtrlListBox_BeginUpdate($list)
GUICtrlSetData($list, $str)
_GUICtrlListBox_EndUpdate($list)
GUICtrlSetState($list, $GUI_SHOW)
EndFunc ;==>_set_data
Func _C($s, $f = 0, $e = 26) ;改进的中值法 (by 蜘蛛抱蛋)
If StringRegExp($s, '^[A-Za-Z]) Then Return $s
Local Const $key[27] = ['吖', '八', '擦', '耷', '俄', '发', '噶', '哈', '丌', '丌', '卡', '拉', '马', '拿', '哦', '趴', '七', '然', '撒', '他', '挖', '挖', '挖', '西', '丫', '匝', '匝']
Local $mid = Int(($e - $f) / 2) + $f
If $mid = $f Then Return Chr(97 + $f)
If StringCompare($s, $key[$mid]) = 0 Then
Return Chr(97 + $mid)
ElseIf StringCompare($s, $key[$mid]) > 0 Then
Return _C($s, $mid, $e)
ElseIf StringCompare($s, $key[$mid]) < 0 Then
Return _C($s, $f, $mid)
EndIf
EndFunc ;==>_C