0
Process[] processlist = Process.GetProcesses();
List<string> names = new List<string>();

foreach (Process process in processlist)
{
    if (!String.IsNullOrEmpty(process.MainWindowTitle))
    {
        if (process.MainWindowTitle.Contains("GrAD"))
        {                       
            CaptureApplication(process.MainWindowTitle);
            break;
        }
    }
}

In the process.MainWindowTitle in the MainWindowTitles i see: GrADS 2.0.2.oga.2 This is fired from the external process Xming. Xming is a small server that connect to the internet and then show a console window and the GrADS 2.0.2.oga.2 is the title of the window but i can't find in any place this GrADS 2.0.2.oga.2 file exe file. I can see the Xming on tray icon but i tried in Task Manager can't find the GrADS 2.0.2.oga.2 exe file on my hard disk.

Task Manager

CaptureApplication(process.MainWindowTitle);

When CaptureApplication get the MainWindowTitle in this case GrADS 2.0.2.oga.2 it should capture the window and stick it add it to the pictureBox on form1. But it's not.

public void CaptureApplication(string _title)
{
    string _wndcls = "ConsoleWindowClass";
    STARTUPINFO si = new STARTUPINFO();
    PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
    CreateProcess(_title, null, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi);
    IntPtr _wndConsole = IntPtr.Zero;

    for (int i = 0; i < 30; i++)
    {
        _wndConsole = FindWindow(_wndcls, _title);
        if (_wndConsole == IntPtr.Zero)
        {
            System.Threading.Thread.Sleep(10);
            continue;
        }
        break; 
    }    

    IntPtr value = SetParent(_wndConsole, this.pictureBox1.Handle);
    int style = GetWindowLong(_wndConsole, -16);
    style &= -12582913;
    SetWindowLong(_wndConsole, -16, style);
    SendMessage(_wndConsole, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}

Maybe GrADS 2.0.2.oga.2 is not exe file not a process ? I can't figure out how to capture it.

GrADS 2.0.2.oga.2 screenshot

This window on the left i need to capture. Maybe the GrADS 2.0.2.oga.2 is not a self process ? It is showing on after the Xming is running.

Chaitanya
  • 5,203
  • 8
  • 36
  • 61
Haim Shabort
  • 57
  • 10
  • Wouldn't Xming be the process name, and in that case, also the MainWindowTitle? Then GrADS 2.0.2.oga.2 woudn't be an exe, just the child window title. – Tim Dec 30 '15 at 23:42
  • Tim might be but i want to capture the child window title the GrADS 2.0.2.oga.2 and not the Xming.exe if i try to cpature the Xming process.Name or MainWindowTitle it's not showing the GrADS 2.0.2.oga.2 in the pictureBox. I want to capture the GrADS 2.0.2.oga.2 – Haim Shabort Dec 30 '15 at 23:50
  • If it's a child window and you're trying to get the window handle, you may have to use this approach: http://stackoverflow.com/a/20276701/1432845 – Tim Dec 31 '15 at 00:09
  • You might want to read [Is it legal to have a cross-process parent/child or owner/owned window relationship?](https://blogs.msdn.microsoft.com/oldnewthing/20130412-00/?p=4683/) by Raymond Chen before going much further. "Yes, it is technically legal. It is also technically legal to juggle chainsaws. ... they become near-impossible to manage if one or both of the windows involved is unaware that it is participating in a cross-process window tree" – Damien_The_Unbeliever Dec 31 '15 at 07:15

0 Answers0