这段代码是我参考网上的vc代码翻译成c#,然后我再桌面上画了一个实心的红色矩形,可以参考一下
-
C# code
-
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApplication13 { public partial class Form1 : Form { [DllImport("User32.dll ", EntryPoint = "FindWindow")] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("User32.dll ")] static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string strname); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { IntPtr P = FindWindow("Progman", "Program Manager"); P = FindWindowEx(P, IntPtr.Zero, "SHELLDLL_DefView", null); P = FindWindowEx(P, IntPtr.Zero, "SysListView32", null); Graphics G = Graphics.FromHwnd(P); G.FillRectangle(new SolidBrush(Color.Red), new Rectangle(new Point(100, 100), new Size(500, 500))); G.Dispose(); } } }