cappy2112

Which widget to use when displaying list of Windows to the user

5 posts in this topic

I've used WinList() to give me a list of all the windows it finds on the system.

I then search through that list to find a few windows which match a title string.

Now I want to present that smaller list of Title/strings to the user, so that they can select ONE of them.

Which widget would be best for this operation? Ideally, the widget should return the index of the item selected, and if possible only allow the user to select 1 item.

I don't expect there will be more than 10 Windows running on the systems I'm working with. In all practicality, I've only seen 4 at the max.

 

Thanks

Share this post


Link to post
Share on other sites



Personally, I would do a GUI with the ListView. I typically take the teach a man to fish approach, but I already had this old one lying about. You will have to tweak it to your needs:

Opt("WinTitleMatchMode", 2)
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Local $aList, $hGUI

    $aList = WinList("WiFi")
        If IsArray($aList) Then
            $hGUI = GUICreate("Test", 300, 300)
            $btnGo = GUICtrlCreateButton("Go", 240, 250, 50, 40)
            $hListView = GUICtrlCreateListView("Windows", 10, 10, 280, 200)
            _GUICtrlListView_SetColumnWidth($hListView, 0, 270)

                For $a = 1 To $aList[0][0]
                    GUICtrlCreateListViewItem($aList[$a][0], $hListView)
                Next

            GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
            GUISetState(@SW_SHOW)

            While 1
                Switch GUIGetMsg()
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $btnGo
                        Local $aTemp = _GUICtrlListView_GetItemTextArray($hListView)
                        MsgBox($MB_OK, "", (($aTemp[0] = 0) ? "Please select a window first" : "You selected " & $aTemp[1]))
                EndSwitch
            WEnd

            GUIDelete()
        EndIf


Func _WM_NOTIFY($nWnd, $iMsg = "", $wParam = "", $lParam = "")
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) = $NM_CLICK Then ; Code
        $hCurrListView = DllStructGetData($tStruct, 1) ; ListView handle
    EndIf
EndFunc

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Thanks.

I've found some of the examples in the Examples directory, and started with something very similar.

I see your example handles the issue I was struggling with though, creating dynamic list entries on the fly.

Your approach makes sense- I knew there has to be some way to do this, I was just looking for an example of a dynamic GUI.

 

BTW- Does AutoIt have the equivalent (~workalike) of C's memset()?

 

Thanks!!

Share this post


Link to post
Share on other sites

I am sure one of our Regex experts will wander by and offer better, but you could use StringReplace to get close functionality:

Local $sString = "mmmmmmMMMMMMMMMM"
Local $outString = StringReplace($sString, "m", "x", 0, 1)
    ConsoleWrite($outString & @CRLF)

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Thanks.

StringReplace() requires that you know what the contents are. I am looking for a function to initialize the contents of an array to a known value.

I know a for loop would work, and that I can easily wrap that in my own function, and pass in the array and the size.

If that functionality can be replaced by a builtin function that is written in C (or C++, whichever language AutoIt is written in), that's what I would use.

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • kcvinu
      How to get the list of windows opened in task bar.
      By kcvinu
      Hi all, I need to get the list of windows which are resting in taskar. That means, windows which i can toggle through ALT TAB. I use "WinList" function. But it gives me all the windows. Then i tried to filter it like this; Local $lst = WinList() Local $Row = 0 For $i = 1 To $lst[0][0] If $lst[$i][0] = "" And Not BitAND(WinGetState($lst[$i][1]), 1) Then _ArrayDelete($lst,$Row) EndIf $Row +=1 Next _ArrayDisplay($lst) But this code doesn't delete the 2nd column. I have read the help file and saw an example which deletes an entire row from a 2 dimensional array. I have used the same method but please look this image. This is what i have got.