C#调用Windows的API实现窗体动画
短信预约 -IT技能 免费直播动态提醒
在VF、VB、PB的应用中,有些无法通过语言工具本身来完成的或者做得不理想的功能,我们会考虑通过Windows的API来完成。
在那个年代,熟悉API是一个编程者的基本功。那个时候网络信息也不发达,很多资料只能考购买书籍或者自己摸索来获取,每次掌握一个新的API应用内心里都有点小激动。
Powerbuilder数据功能强大,但是界面功能尤其是动画功能比较弱,通过调用Windows的API实现窗体动画比较容易。
声明API调用:
function boolean AnimateWindow ( long hwnd, long dwtime, long dwflags ) library "user32"
声明常量:
constant long AW_HOR_POSITIVE = 1
constant long AW_HOR_NEGATIVE = 2
constant long AW_VER_POSITIVE = 4
constant long AW_VER_NEGATIVE = 8
constant long AW_CENTER = 16
constant long AW_HIDE = 65526
constant long AW_ACTIVATE = 131072
conDAT* ? ?stant long AW_SLIDE = 262144
constant long AW_BLEND = 524288
在窗体的open事件中调用:
long ll_handle
ll_handle = Handle ( This )
Randomize ( 0 )
Choose Case rand ( 6 )
Case 1
AnimateWindow ( ll_handle, 1000, AW_SLIDE + AW_VER_POSITIVE + AW_ACTIVATE )
Case 2
AnimateWindow ( ll_handle, 1000, AW_SLIDE + AW_VER_NEGATIVE+ AW_ACTIVATE )
Case 3
AnimateWindow ( ll_handle, 1000, AW_SLIDE + AW_HOR_POSITIVE + AW_ACTIVATE )
Case 4
AnimateWindow ( ll_handle, 1000, AW_SLIDE + AW_HOR_NEGATIVE + AW_ACTIVATE )
Case 6,5
AnimateWindow ( ll_handle, 1000, AW_SLIDE + AW_CENTER + AW_ACTIVATE )
End Choose
在C#中调用Windows的API来实现动画也一样容易。
引用:
using System.Runtime.InteropServices;
定义常量:
public const Int32 AW_HOR_POSITIVE = 0x00000001;
public const Int32 AW_HOR_NEGATIVE = 0x00000002;
public const Int32 AW_VER_POSITIVE = 0x00000004;
public const Int32 AW_VER_NEGATIVE = 0x00000008;
public const Int32 AW_CENTER = 0x00000010;
public const Int32 AW_HIDE = 0x00010000;
public const Int32 AW_ACTIVATE = 0x00020000;
public const Int32 AW_SLIDE = 0x00040000;
public const Int32 AW_BLEND = 0x00080000;
定义调用:
[DllImportAttribute("user32.dll")]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags);
调用:
private void Form1_Load(object sender, EventArgs e)
{
//this.FormBorderStyle =0 ;
Random rand = new Random();
long LL = rand.Next(1,6);
label1.Text = "动画演示:"+LL.ToString();
switch (LL)
{
case 1:
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_VER_POSITIVE + AW_ACTIVATE);
break;
case 2:
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_VER_NEGATIVE + AW_ACTIVATE);
break;
case 3:
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_HOR_POSITIVE + AW_ACTIVATE);
break;
case 4:
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_HOR_NEGATIVE + AW_ACTIVATE);
break;
case 5:
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_CENTER + AW_ACTIVATE);
break;
case 6:
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_CENTER + AW_ACTIVATE);
break;
}
}
效果图
到此这篇关于C#调用Windows的API实现窗体动画的文章就介绍到这了,更多相关C# API实现窗体动画内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341