Jump to content

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


 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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!!

Link to comment
Share on other sites

  • Moderators

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)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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.

 

Link to comment
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
 Share

×
×
  • Create New...