打开QQ的时候,QQ新闻弹出窗体在屏幕的右下角就会慢慢升起一个小窗口,占用的地方不大,可以起到提示的作用。下面就让我们来看看,怎样用系统API来轻松实现这个功能。 
API原型函数: 
bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags); 
从字面的意思来看,这个函数名为"活动的窗口",事实上也如此,通过这个函数,可以使我们的窗体动作丰富起来,要在c#中使用winApi首先引入命名空间: 

view plaincopy to clipboardprint? 
//引入命名空间    
using System.Runtime.InteropServices;   
//API原型   
[DllImport("user32.dll")]   
private static extern bool AnimateWindow(IntPtr hwnd, int dateTime, int dwFlags);//hwnd窗口句柄.dateTime:动画时长.dwFlags:动画类型组合  
        //引入命名空间 
        using System.Runtime.InteropServices; 
        //API原型 
        [DllImport("user32.dll")] 
        private static extern bool AnimateWindow(IntPtr hwnd, int dateTime, int dwFlags);//hwnd窗口句柄.dateTime:动画时长.dwFlags:动画类型组合 

下面是dwFlags的各种动画标志: 

view plaincopy to clipboardprint? 
int AW_ACTIVE = 0x20000; //激活窗口,在使用了AW_HIDE标志后不要使用这个标志   
int AW_HIDE = 0x10000;//隐藏窗口   
int AW_BLEND = 0x80000;// 使用淡入淡出效果   
int AW_SLIDE = 0x40000;//使用滑动类型动画效果,默认为滚动动画类型,当使用AW_CENTER标志时,这个标志就被忽略   
int AW_CENTER = 0x0010;//若使用了AW_HIDE标志,则使窗口向内重叠;否则向外扩展   
int AW_HOR_POSITIVE = 0x0001;//自左向右显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志   
int AW_HOR_NEGATIVE = 0x0002;//自右向左显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志   
int AW_VER_POSITIVE = 0x0004;//自顶向下显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志   
int AW_VER_NEGATIVE = 0x0008;//自下向上显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志  
        int AW_ACTIVE = 0x20000; //激活窗口,在使用了AW_HIDE标志后不要使用这个标志 
        int AW_HIDE = 0x10000;//隐藏窗口 
        int AW_BLEND = 0x80000;// 使用淡入淡出效果 
        int AW_SLIDE = 0x40000;//使用滑动类型动画效果,默认为滚动动画类型,当使用AW_CENTER标志时,这个标志就被忽略 
        int AW_CENTER = 0x0010;//若使用了AW_HIDE标志,则使窗口向内重叠;否则向外扩展 
        int AW_HOR_POSITIVE = 0x0001;//自左向右显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志 
        int AW_HOR_NEGATIVE = 0x0002;//自右向左显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志 
        int AW_VER_POSITIVE = 0x0004;//自顶向下显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志 
        int AW_VER_NEGATIVE = 0x0008;//自下向上显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志 


申明变量保存窗体显示的坐标: 

view plaincopy to clipboardprint? 
private int currentX;//横坐标      
private int currentY;//纵坐标      
private int screenHeight;//屏幕高度      
private int screenWidth;//屏幕宽度    
       private int currentX;//横坐标   
        private int currentY;//纵坐标   
        private int screenHeight;//屏幕高度   
        private int screenWidth;//屏幕宽度 
   

load事件中执行动画: 

view plaincopy to clipboardprint? 
Rectangle rect = Screen.PrimaryScreen.WorkingArea;   
screenHeight = rect.Height;   
screenWidth = rect.Width;   
currentX = screenWidth - this.Width;   
currentY = screenHeight - this.Height;   
this.Location = new System.Drawing.Point(currentX, currentY);   
  
AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_VER_NEGATIVE);  
            Rectangle rect = Screen.PrimaryScreen.WorkingArea; 
            screenHeight = rect.Height; 
            screenWidth = rect.Width; 
            currentX = screenWidth - this.Width; 
            currentY = screenHeight - this.Height; 
            this.Location = new System.Drawing.Point(currentX, currentY); 

            AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_VER_NEGATIVE); 

试试吧! 

posted on 2014-06-27 17:21  GC2013  阅读(1727)  评论(0编辑  收藏  举报