Accessing other process' windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    Accessing other process' windows

    I'd like to know how to access another process' main window (if it exists) and get information like screen location and size, and whether it's visible at the moment. Is something like that possible?

    Basically I want to create an application that will allow me to monitor these other windows and take screenshots of them (just the window, not the whole screen) through a single application. To do this I need a list of running processes that have main windows. Can it be done?

    As a side note, I already know how to get information about running processes, by using System.Diagnost ics and making a Process array with Process.GetProc esses(), I just need to know how to access those process' windows.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You're going to have to use some Win32 API I think.
    Also, in order to get a screen shot, the window has to be visible.
    Which is to say if you have a window maximixed over another window, the background window won't be able to get a screenshot taken of it

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      I understand that, I'm sure I could send a request to make the window I want be on top of other windows.

      Could you help me out as to how I should use the Win32 API? It's something like:

      [DLLImport("Win3 2")]
      ...

      Something like that to get me started, right?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Maybe something like:
        [code=c#]
        [DllImport("user 32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern int GetWindowText(I ntPtr hWnd, StringBuilder lpString, int nMaxCount);

        public string GetText(IntPtr hWnd)
        {
        int length = 30;
        StringBuilder sb = new StringBuilder(l ength + 1);
        GetWindowText(h Wnd, sb, sb.Capacity);
        return sb.ToString();
        }

        [/code]

        And you can use the MainWindowHandl e property of a given Process

        Comment

        Working...