winforms - Capture client area of another program in C#? -


I have a list view that is populated with current application names:

  listView1. Items .Add (proc.MainWindowTitle);   

The code is in a bias statement. I have tried to use this code to get the code selected (name of the program) and take a screenshot of the client window of that program:

  public string selected program; [DllImport ("user32.dll", Charset = Charset Auto, Exact Spelling = True)] Public Static Extern IntPtr GetForegroundWindow (); [DllImport ("user32.dll")] Public static extern bool GetWindowRect (IntPtr hwnd, outside rectangle lpRect); Private Zero Button 2_Click (Object Sender, EventArgs E) {Process Process = Process =} GetProcesses (); Leading (various P in Processes) {Selected Program = List View 1. Selected Items. Toasting (); } Rectangular bond = new rectangle (); GetWindowRect (handle, out-bond); Bitmap BMP = new bitmap (bond width, bond high.); (Gfx.CopyFromScreen (Bond space, dot.aptee, Bond size) using (Var gfx = Graphics.FromImage (bmp)); PictureBox1.Image = bmp; Form 2 FM2 = New Form 2 (this); Frm2.Show (); Frm2.pictureBox1.Image = pictureBox1.Image; }   

What am I doing?

This will help if you say that it does not work in some parts of it.

I'm not sure that this is your problem, but I think you are overwriting your first one variable (selected program) only for the loop

  Process [] Process = Process.GetProcesses (); Leading (various P in Processes) {Selected Program = List View 1. Selected Items. Toasting (); }   

and then use the member variable instead of the handle for that process' Window GetWindowRect (Handle, Out Band);

You will need to call the window handles the process. Also, is there a multiple window for a process? Once you find that you are handling the right window for the process (should be Spy ++), you do not need to loop through all the windows for a specific process, which is EnumWindows and GetWindowThreadProcessID () Using a combination of () help in it), you are not working for yourself to be able to keep a better picture

Comments