1.怎样闪烁一个窗体在任务栏上的标题区?
2.如何像QQ那样实现窗体的自动隐藏?当鼠标移过去又能显示。

解决方案 »

  1.   

    使用如下的方法就可以闪动窗体标题栏图标了:
    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern int FlashWindow(IntPtr hWnd);
    protected override void OnClick(EventArgs e)
    {
    base.OnClick(e);
    FlashWindow(this.Handle);
    }
    自动隐藏,可以判断窗体所在区域上是否包含鼠标坐标,如果不包含则把窗体移到最近的屏幕的一边,然后留出一个5个像素左右的小边,以便当鼠标再次位于其上的时候还原窗体位置。可以先得到指定窗体的大小区域的Rectangle,然后使用Rectangle.Contain来判断鼠标是否位于其上:
    [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern bool GetClientRect(IntPtr hWnd, [In, Out] COMRECT rect);
     
    [StructLayout(LayoutKind.Sequential)]
    public class COMRECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
        public COMRECT()
        {
        }
        public COMRECT(int left, int top, int right, int bottom)
        {
            this.left = left;
            this.top = top;
            this.right = right;
            this.bottom = bottom;
        }

      

  2.   

    hbxtlhx:
    第一问:
    我用了你的方法,建了一个Form1,上面一个button1。单击按钮后调用FlashWindow(),出现以下异常:
        对 PInvoke 函数“WindowsApplication1!WindowsApplication1.Form1::FlashWindow”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。
        望求解决。
      

  3.   

    不太清楚你那里为什么会出问题,我的测试环境是WindowXP sp2 VS2005我的运行正常。
      

  4.   

    我的测试环境也是WindowXP VS2005
      

  5.   

    我已经解决了:  
    [DllImport("user32.dll")]
      public static extern bool FlashWindow(
       IntPtr hWnd,     // handle to window
       bool bInvert   // flash status
       );
    ----------------------------------   
    FlashWindow(handle,true);//闪烁感谢hbxtlhx
      

  6.   

    这个上面有
    http://hi.baidu.com/hhh3h