Jump to content

Winlist in c#


c0desmyth
 Share

Recommended Posts

Hi there!

I've been converting some code to c# and have run into a few road blocks. First I cannot use WinList as I've grown accustom to in AutoIt.

AutoIt

$aListOfWindows = WinList("[REGEXPTITLE:\ANotepad.*\z]", "")
For $a = 1 to $aListOfWindows[0][0]
    Console.Write($aListOfWindows[$a][0] & @CRLF)
Next

c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static AutoItX3Lib.AutoItX3Class au3;

        static void Main(string[] args)
        {
            au3 = new AutoItX3Lib.AutoItX3Class();
            object aListOfWindows;
            aListOfWindows = au3.WinList("[REGEXPTITLE:\\ANotepad.*\\z]", "");
            for (int a = 1; a < aListOfWindows [0][0]; a++) //Error 18  Cannot apply indexing with [] to an expression of type 'object'

            {
                Console.WriteLine(aListOfWindows[a][0]);
            }
        }
    }
}

Any help would be GREATLY appreciated!

Link to comment
Share on other sites

Ok - I did this.. I dunno if it's the actual fix, but the compiler didn't complain. (I'll test it tomorrow - 1am here)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static AutoItX3Lib.AutoItX3Class au3;

        static void Main(string[] args)
        {
            au3 = new AutoItX3Lib.AutoItX3Class();
            int [][] aListOfWindows;
            aListOfWindows = au3.WinList("[REGEXPTITLE:\\ANotepad.*\\z]", "");
            for (int a = 1; a < aListOfWindows [0][0]; a++) //Error 18  Cannot apply indexing with [] to an expression of type 'object'

            {
                Console.WriteLine(aListOfWindows[0][a]);  
            }
        }
    }
}

Now from the example in the help file it looks like the array is switched - in autoit, $array[$a][0] is the title and $array[$a][1] is the handle... in c# is it the same or is it array[0][a] for the title and array[1][a] for the handle? A little confused. I guess I'll find out when I test it tomorrow.

Funny that the tool tip for the function WinList says it returns an object - but doesn't complain when I set the return value to int [][]....

Link to comment
Share on other sites

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



namespace Test

{

    class Program

    {

        static AutoItX3Lib.AutoItX3Class au3;



        static void Main(string[] args)

        {

            au3 = new AutoItX3Lib.AutoItX3Class();

            Object [,] aListOfWindows;

            // aListOfWindows = au3.WinList("[REGEXPTITLE:\\ANotepad.*\\z]", "");



            aListOfWindows = (Object[,])au3.WinList("[CLASS:Notepad]", "");



            for (int a = 1; a <= (int)aListOfWindows[0, 0]; a++)

            {

                Console.WriteLine(aListOfWindows[0, a] + ", " + aListOfWindows[1, a]);

            }



            //foreach (object item in aListOfWindows)

            //{

            //    Console.WriteLine(item);

            //}

        }

    }

}

Link to comment
Share on other sites

I write in so many different languages it's hard to keep it all straight. Thank you for pointing this out. (using [][] didn't work as you predicted)

Your example helped me make 342 changes to my script - and now the winlist functions all work.

Edited by c0desmyth
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...