我有一个列表视图,其中填充了正在运行的应用程序名称:
listView1.Items.Add(proc.MainWindowTitle);
代码在 foreach 语句中。我尝试使用此代码获取所选项目(程序名称)并截取该程序的客户端窗口:
public string selectedProgram;
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, out Rectangle lpRect);
private void button2_Click(object sender, EventArgs e)
{
Process[] process = Process.GetProcesses();
foreach (var p in process)
{
selectedProgram = listView1.SelectedItems.ToString();
}
Rectangle bonds = new Rectangle();
GetWindowRect(Handle, out bonds);
Bitmap bmp = new Bitmap(bonds.Width, bonds.Height);
using (var gfx = Graphics.FromImage(bmp))
{
gfx.CopyFromScreen(bonds.Location, Point.Empty, bonds.Size);
pictureBox1.Image = bmp;
Form2 frm2 = new Form2(this);
frm2.Show();
frm2.pictureBox1.Image = pictureBox1.Image;
}
我究竟做错了什么?