程序需要对屏幕进行测试,依次使屏幕显示红 绿 青的颜色,如何处理呢?
另外我照高手指点用 Process.start("ssmyst.scr");启动了屏幕保护程序,但希望通过计时器
到一定时间后结束屏保,怎么做呢?

解决方案 »

  1.   

    参考下面代码,几个问题都有了:[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    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();
    }
      

  2.   

    第二个问题好解决:
    定义一个timer控件,和一个button1(启动process.start(ssmyst.scr))控件,timer开始,然后在timer的tick事件中,process.kill("进程")就行了,原理,一看,自己试一下就行了
      

  3.   

    少了一个定义: 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;
    }
    }