Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:29:16+00:00 2026-06-09T23:29:16+00:00

Is there a way to get a bi-dimensional array containing pairs of a windows

  • 0

Is there a way to get a bi-dimensional array containing pairs of a windows title and handle for all existing windows?

I think this would require to get the titles of all opened windows first and then retrieve their handles and build the bi-dimensional array from two lists, but I’m not completely sure how to do that.

I also know it involves the Process.GetProcesses() method, but I am not entirely sure how to do it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:29:18+00:00Added an answer on June 9, 2026 at 11:29 pm

    Look at the http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx and read about the MainWindowTitle and MainWindowHandle properties.

    The GetProcesses method returns you a list of exactly such Process objects. Thus, in verbose form:

    Process[] procs = Process.GetProcesses();
    object[,] thearray = new object[procs.Length,2];
    for(int i=0;i<procs.Length;++i)
    {
        thearray[i,0] = procs[i].MainWindowTitle;
        thearray[i,1] = procs[i].MainWindowHandle;
    }
    

    and this is it. Now if you want to get N-th process information:

    string title = (string)thearray[n][0];
    IntPtr handle = (IntPtr)thearray[n][1];
    

    As you see, there’s a problem that the array has only ONE data type. That means that keeping a string and an IntPtr (the handle) forces you to find a common super type, which is .. the most general ‘object’ type. Thus, you have to cast when you are reading the data, because only you know that at [0] the object is actually a string.

    Consider using a Dictionary class. That way you will have your data nicely typed – but you will lose the “order” of the processes. They will be sorted randomly. But I dont think that at this point you needed the order anyways? See the code here:

    Process[] procs = Process.GetProcesses();
    Dictionary<string, IntPtr> theMap = new Dictionary<string,IntPtr>();
    foreach(var p in procs)
        theMap[p.MainWindowTitle] = p.MainWindowHandle;
    

    and this is it. Now if you want to read the process information:

    foreach(var aPair in theMap)
    {
        string title = aPair.Key;
        IntPtr handle = aPair.Value;
        ...
    }
    

    Note that with Dictionary the access to N-th element is a little difficult, but usually you do not need that anyways. If you need it – you can add LINQ to the toolset:

    using System.Linq;
    
    var myNthPair = theMap.ElementAt(n);
    string title = myNthPair.Key;
    IntPtr handle = myNthPair.Value;
    

    so, not that bad. As we have the LINQ in hand, we can write the initial dictionary-creating code even shorter:

    var theMap = Process.GetProcesses().ToDictionary(p => p.MainWindowTitle, p => p.MainWindowHandle);
    

    Ok. So lets fix one thing – I’ve fooled you with the dictionary a little. The Dictio has a constraint: the keys must be unique. And the window titles may be any! They may repeat and surely they will. Thus, you have to either SWAP the key with the value and form a Dictionary – as the handles should never repeat – or else you may use a LINQ .ToLookup method instead of .ToDictionary. The Lookup holds multiple values for a single key, so for an “Internet explorer” window title it will be capable of holding a list of 15 handles, etc.

    Have fun.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way to get an two-dimensional array or something similar that
Is there way to get file from windows xp command prompt? I tried to
is there way how to get name ov event from Lambda expression like with
Is there a way to get the item pointed at by an iterator in
Is there a way to get distance between two objects in meters? I'm trying
Is there a way to get the path to where WordPress is installed? I
Is there any way to get the previous hash using the history object ?I
Is there a way to get the actual columns name with ActiveRecord? When I
Is there a way to get HTML contents from TinyMCE editor using jQuery so
Is there any way to get direct URL to a JSF bean action method?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.