ferradavi Posted May 24, 2016 Share Posted May 24, 2016 (edited) Hi guys! Once again I need your help. I would like to change the below Melba23's code to make the following list $hList = GUICtrlCreateList("", 5, 40, 300, 30, BitOR(0x00100000, 0x00200000)) appearing only while I write something in the input box and disappearing after clicking on the chosen word (i.e. one of the seven dwarfs). expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> #Include <GuiListBox.au3> Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100] ; Create list full of random 5 character "words" Keywords() $hGUI = GUICreate("Example", 400, 500) $hInput = GUICtrlCreateInput("", 5, 5, 300, 28) GUICtrlSetFont(-1, 14, 400, 0, "Verdana") $hList = GUICtrlCreateList("", 5, 40, 300, 90, BitOR(0x00100000, 0x00200000)) GUICtrlSetFont(-1, 14, 400, 0, "Verdana") $hButton = GUICtrlCreateButton("Read", 310, 3, 80, 30) $hUP = GUICtrlCreateDummy() $hDOWN = GUICtrlCreateDummy() $hENTER = GUICtrlCreateDummy() GUISetState(@SW_SHOW, $hGUI) ; Set accelerators for Cursor up/down and Enter Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]] GUISetAccelerators($AccelKeys) $sCurr_Input = "" $iCurrIndex = -1 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hList $sChosen = GUICtrlRead($hList) If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen) Case $hButton If $sPartialData <> "" Then $sFinal = GUICtrlRead($hInput) If _ArraySearch($asKeyWords, $sFinal) >= 0 Then MsgBox(0, "Chosen", $sFinal) EndIf EndIf Case $hUP If $sPartialData <> "" Then $iCurrIndex -= 1 If $iCurrIndex < 0 Then $iCurrIndex = 0 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hDOWN If $sPartialData <> "" Then $iTotal = _GUICtrlListBox_GetCount($hList) $iCurrIndex += 1 If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hENTER If $iCurrIndex <> -1 Then $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex) GUICtrlSetData($hInput, $sText) $iCurrIndex = -1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf EndSwitch ; If input has changed, refill list with matching items If GUICtrlRead($hInput) <> $sCurr_Input Then CheckInputText() $sCurr_Input = GUICtrlRead($hInput) EndIf WEnd Func CheckInputText() $sPartialData = "|" ; Start with delimiter so new data always replaces old Local $sInput = GUICtrlRead($hInput) If $sInput <> "" Then For $i = 0 To 99 If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|" Next GUICtrlSetData($hList, $sPartialData) EndIf EndFunc ;==>CheckInputText Func Keywords() Local $sData For $i = 0 To 6 $asKeyWords[0] = "Bashful" $asKeyWords[1] = "Sleepy " $asKeyWords[2] = "Happy" $asKeyWords[3] = "Sneezy" $asKeyWords[4] = "Doc" $asKeyWords[5] = "Grumpy" $asKeyWords[6] = "Dopey" $sData &= $asKeyWords[$i] & "|" Next GUICtrlSetData($hList, $sData) $iCurrIndex = -1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndFunc ;==>Keywords Func _PopupSelector($hMainGUI, ByRef $hListGUI, $sCurr_List) Local $hList = -1 If $sCurr_List = "" Then Return $hList EndIf $hListGUI = GUICreate("", 420, 160, 10, 120, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_MDICHILD), $hMainGUI) ;GUICtrlSetFont(-1, 14, 400, 0, "Arial Rounded") $hList = GUICtrlCreateList("", 0, 0, 420, 150, BitOR(0x00100000, 0x00200000)) GUICtrlSetFont(-1, 13, 400, 0, "Arial Rounded") GUICtrlSetData($hList, $sCurr_List) GUISetControlsVisible($hListGUI) ; To Make Control Visible And Window Invisible. GUISetState(@SW_SHOWNOACTIVATE, $hListGUI) Return $hList EndFunc ;==>_PopupSelector Thanks a lot!!! Edited May 24, 2016 by ferradavi Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 24, 2016 Moderators Share Posted May 24, 2016 ferradavi, To keep it simple, I would just add a few lines like this in the main loop: If GUICtrlRead($cInput) = "" And $fShowing Then GUICtrlSetState($cList, $GUI_HIDE) $fShowing = False ElseIf GUICtrlRead($cInput) <> "" And Not $fShowing Then GUICtrlSetState($cList, $GUI_SHOW) $fShowing = True EndIf You will need to set $fShowing to False and hide the list initially as well. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ferradavi Posted May 24, 2016 Author Share Posted May 24, 2016 Thank you M23 for your prompt reply. I tried it but without success. Maybe I'm wrong. Could you show me how to do? Forgive me if I take advantage of your kindness Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 24, 2016 Moderators Share Posted May 24, 2016 ferradavi, Of course: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #Include <GuiListBox.au3> Global $hGUI, $cInput, $cList, $sPartialData, $asKeyWords[100], $fShowing = True ; Create list full of random 5 character "words" Keywords() $hGUI = GUICreate("Example", 400, 500) $cInput = GUICtrlCreateInput("", 5, 5, 300, 28) GUICtrlSetFont(-1, 14, 400, 0, "Verdana") $cList = GUICtrlCreateList("", 5, 40, 300, 90, BitOR(0x00100000, 0x00200000)) GUICtrlSetFont($cList, 14, 400, 0, "Verdana") GUICtrlSetBkColor($cList, 0xFFCCCC) GUISetState($cList, $GUI_HIDE) $cButton = GUICtrlCreateButton("Read", 310, 3, 80, 30) $cUP = GUICtrlCreateDummy() $cDOWN = GUICtrlCreateDummy() $cENTER = GUICtrlCreateDummy() GUISetState(@SW_SHOW, $hGUI) ; Set accelerators for Cursor up/down and Enter Dim $AccelKeys[3][2]=[["{UP}", $cUP], ["{DOWN}", $cDOWN], ["{ENTER}", $cENTER]] GUISetAccelerators($AccelKeys) $sCurr_Input = "" $iCurrIndex = -1 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cList $sChosen = GUICtrlRead($cList) If $sChosen <> "" Then GUICtrlSetData($cInput, $sChosen) Case $cButton If $sPartialData <> "" Then $sFinal = GUICtrlRead($cInput) If $sFinal And _ArraySearch($asKeyWords, $sFinal) >= 0 Then MsgBox($MB_SYSTEMMODAL, "Chosen", $sFinal) GUICtrlSetData($cInput, "") EndIf EndIf Case $cUP If $sPartialData <> "" Then $iCurrIndex -= 1 If $iCurrIndex < 0 Then $iCurrIndex = 0 _GUICtrlListBox_SetCurSel($cList, $iCurrIndex) EndIf Case $cDOWN If $sPartialData <> "" Then $iTotal = _GUICtrlListBox_GetCount($cList) $iCurrIndex += 1 If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1 _GUICtrlListBox_SetCurSel($cList, $iCurrIndex) EndIf Case $cENTER If $iCurrIndex <> -1 Then $sText = _GUICtrlListBox_GetText($cList, $iCurrIndex) GUICtrlSetData($cInput, $sText) $iCurrIndex = -1 _GUICtrlListBox_SetCurSel($cList, $iCurrIndex) EndIf EndSwitch ; If input has changed, refill list with matching items If GUICtrlRead($cInput) <> $sCurr_Input Then CheckInputText() $sCurr_Input = GUICtrlRead($cInput) EndIf If GUICtrlRead($cInput) = "" And $fShowing Then GUICtrlSetState($cList, $GUI_HIDE) $fShowing = False ElseIf GUICtrlRead($cInput) <> "" And Not $fShowing Then GUICtrlSetState($cList, $GUI_SHOW) $fShowing = True EndIf WEnd Func CheckInputText() $sPartialData = "|" ; Start with delimiter so new data always replaces old Local $sInput = GUICtrlRead($cInput) If $sInput <> "" Then For $i = 0 To 99 If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|" Next GUICtrlSetData($cList, $sPartialData) EndIf EndFunc ;==>CheckInputText Func Keywords() Local $sData For $i = 0 To 6 $asKeyWords[0] = "Bashful" $asKeyWords[1] = "Sleepy " $asKeyWords[2] = "Happy" $asKeyWords[3] = "Sneezy" $asKeyWords[4] = "Doc" $asKeyWords[5] = "Grumpy" $asKeyWords[6] = "Dopey" $sData &= $asKeyWords[$i] & "|" Next GUICtrlSetData($cList, $sData) $iCurrIndex = -1 _GUICtrlListBox_SetCurSel($cList, $iCurrIndex) EndFunc ;==>Keywords Func _PopupSelector($hMainGUI, ByRef $cListGUI, $sCurr_List) Local $cList = -1 If $sCurr_List = "" Then Return $cList EndIf $cListGUI = GUICreate("", 420, 160, 10, 120, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_MDICHILD), $hMainGUI) ;GUICtrlSetFont(-1, 14, 400, 0, "Arial Rounded") $cList = GUICtrlCreateList("", 0, 0, 420, 150, BitOR(0x00100000, 0x00200000)) GUICtrlSetFont(-1, 13, 400, 0, "Arial Rounded") GUICtrlSetData($cList, $sCurr_List) GUISetState(@SW_SHOWNOACTIVATE, $cListGUI) Return $cList EndFunc ;==>_PopupSelector M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ferradavi Posted May 24, 2016 Author Share Posted May 24, 2016 Thank you for your precious help M23! You've been a real lifesaver Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now