您的位置:首页 > 编程语言 > C#

C#实现类似MSN Messenger的弹出提示窗体

2006-12-03 00:47 363 查看
也许有的朋友最近有些疑惑,我的Blog叫Windows Mobile开发历险,为什么最近的文章都是win32下的,其实我最近写的东西是Windows Mobile/Windows xp结构的,所以对于win32的某些技术用得到,也有了些自己的心得体会。后来想了想,不能让这些东西白白流失,还是写下来吧。以便让自己记得长久,还能跟大家分享。
今天的文章,我主要介绍MSN Messenger弹出窗体的实现方法,MSN Messenger的弹出窗体就是再联系人登录或者发送新消息时候桌面右下角弹出的窗体。实现这样的窗体很简单,delphi中我写过这样的组件,不过因为号称商业机密的东西不便发表。C#就自由了,随便发布,哈哈!
其实实现这个弹出窗体只需调用windows API函数即可,AnimateWindow——我们都可以顾名思义了,哈哈!就是动态窗口!那么接下来我们只需知道如何调用该函数,如果定义该函数的参数,就可以了。下面我给出一个实例,并配上简单的注释,这样就能实现我们所要的功能了。如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace FormHintTest
{
public partial class FormHint : Form
{
public FormHint()
{
InitializeComponent();
// 根据系统当前分辨率确定Hint窗体的位置
int x = Screen.PrimaryScreen.WorkingArea.Width - this.Width - 1;
int y = Screen.PrimaryScreen.WorkingArea.Height - this.Height - 1;
this.Location = new Point(x, y);
}

public void Popup()
{
//在public函数中调用API函数实现动态效果
AnimateWindow(this.Handle, 200, (uint)AnimateWindowFlags.AW_SLIDE |
(uint)AnimateWindowFlags.AW_VER_NEGATIVE | (uint)AnimateWindowFlags.AW_ACTIVATE);
this.Show();
}

[DllImport("user32.dll")] //Invoke Windows API函数 AnimateWindow
public extern static bool AnimateWindow(IntPtr hwnd,uint dwTime,uint dwFlags);

public enum AnimateWindowFlags : uint //AnimateWindow的dwFlags参数定义
{
AW_HOR_POSITIVE = 0x00000001,
AW_HOR_NEGATIVE = 0x00000002,
AW_VER_POSITIVE = 0x00000004,
AW_VER_NEGATIVE = 0x00000008,
AW_CENTER = 0x00000010,
AW_HIDE = 0x00010000,
AW_ACTIVATE = 0x00020000,
AW_SLIDE = 0x00040000,
AW_BLEND = 0x00080000
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐