少了一个定义: public class RECT { public int left; public int top; public int right; public int bottom; public RECT() { } public RECT(int left, int top, int right, int bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } }
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool RedrawWindow(IntPtr hwnd, RECT rcUpdate, IntPtr hrgnUpdate, int flags);private void button1_Click(object sender, EventArgs e)
{
IntPtr desk = GetDesktopWindow();
IntPtr deskDC = GetDCEx(desk, IntPtr.Zero, 0x403);
Graphics g = Graphics.FromHdc(deskDC); using (SolidBrush brush = new SolidBrush(Color.Red))
{
g.FillRectangle(brush, Screen.FromHandle(this.Handle).Bounds);
}
System.Threading.Thread.Sleep(500);
using (SolidBrush brush = new SolidBrush(Color.Green))
{
g.FillRectangle(brush, Screen.FromHandle(this.Handle).Bounds);
}
System.Threading.Thread.Sleep(500);
using (SolidBrush brush = new SolidBrush(Color.Blue))
{
g.FillRectangle(brush, Screen.FromHandle(this.Handle).Bounds);
}
RedrawWindow(GetDesktopWindow(), null, IntPtr.Zero, 0x85); Process p = new Process();
p.StartInfo.FileName = "ssmyst.scr";
p.Start();
System.Threading.Thread.Sleep(500);
p.CloseMainWindow();
}
定义一个timer控件,和一个button1(启动process.start(ssmyst.scr))控件,timer开始,然后在timer的tick事件中,process.kill("进程")就行了,原理,一看,自己试一下就行了
{
public int left;
public int top;
public int right;
public int bottom;
public RECT()
{
}
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}