My FAQ,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Visual C++ > WINDOWS窗口视图
制作 MSN、QQ 的消息提示窗口
作者:未知 时间:2005-07-20 14:13 出处:VC知识库 责编:MyFAQ
              摘要:制作 MSN、QQ 的消息提示窗口

制作 MSN、QQ 的消息提示窗口

作者:袁怀善

下载源代码

  用过QQ和MSN聊天工具的人都知道,只要好友上线,就会在托盘的位置处显示一个提示窗口,
可以是拉帘式的,或者是淡入淡出的形式出现;想想何不为自己的程式也加一个漂亮的提示窗口呢:)
说做就做。

一、MSN拉帘式窗口制作

分三部分:1、窗口的显示;2、窗口的停留;3、窗口的消失;
如果达到这样郊果,系统中要有三个定时器,进行分别控制。定义的定时器如下:

#define ID_TIMER_POP_WINDOW 1
#define ID_TIMER_DISPALY_DELAY 2 
#define ID_TIMER_CLOSE_WINDOW 3 

  从CWnd 继承一个窗口,当然也可以从CFrameWnd进行派生,这不是主要问题,关键是看你是怎么处理WM_PAINT,WM_MOUSEMOVE,WM_TIMER的消息。一般情况,我从OnPaint()中进行显示图片,在WM_TIMER中处理定时器消息,下面是处里定时器时用到的代码:

CMsgWnd::CMsgWnd()
{ 
	...
	SetTimer(ID_TIEMR_POP_WINDOW,20,NULL);
	...
} 

void CMsgWnd::OnTimer(UINT nIDEvent) 
{ 
	static int nHeight=0;
	int cy=GetSystemMetrics(SM_CYSCREEN);
	int cx=GetSystemMetrics(SM_CXSCREEN);
	RECT rect;
	SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
	int y=rect.bottom-rect.top;
	int x=rect.right-rect.left;
	x=x-WIN_WIDTH;
	
	switch(nIDEvent)
	{
	case ID_TIMER_POP_WINDOW:
		if(nHeight<=WIN_HEIGHT)
		{
			++nHeight; 
			MoveWindow(x,
				y-nHeight,
				WIN_WIDTH,
				WIN_HEIGHT);
			
			Invalidate(FALSE);
		}
		else
		{
			KillTimer(ID_TIMER_POP_WINDOW);
			SetTimer(ID_TIMER_DISPLAY_DELAY,5000,NULL);
		}
		break;
	case ID_TIMER_CLOSE_WINDOW:
		if(nHeight>=0)
		{
			nHeight--;
			MoveWindow(x,
				y-nHeight,
				WIN_WIDTH,
				nHeight);
		}
		else
		{
			KillTimer(ID_TIMER_CLOSE_WINDOW);
			SendMessage(WM_CLOSE);
		}
		break;
	case ID_TIMER_DISPLAY_DELAY:
		KillTimer(ID_TIMER_DISPLAY_DELAY);
		SetTimer(ID_TIMER_CLOSE_WINDOW,20,NULL);
		break;
	}
	
	CWnd::OnTimer(nIDEvent);
}            
根据你设的定时器的长短来控制窗口的显示过程;

二、QQ淡出淡出显示实现

  其实用到一个API函数:AnimateWindow,下面是这个函数的一些说明:
The AnimateWindow function enables you to produce special effects when showing or hiding windows.
There are two types of animation: roll animation and slide animation. 
BOOL AnimateWindow(
		 HWND hwnd, // handle to the window to animate
		 DWORD dwTime, // duration of animation
		 DWORD dwFlags // animation type
		 );
上面的函数前两个参数一看就明白,不用说了,最后一个参数dwFlags设置动画窗口的样式:
Specifies the type of animation. This parameter can be one or more of the following flags.

各种标志说明:

标志 说明
AW_SLIDE Uses slide animation. By default, roll animation is used.
This flag is ignored when used with the AW_CENTER flag.
AW_ACTIVATE Activates the window. Do not use this flag with AW_HIDE.
AW_BLEND Uses a fade effect. This flag can be used only if hwnd is a top-level window.
AW_HIDE Hides the window. By default, the window is shown.
AW_CENTER Makes the window appear to collapse inward if the AW_HIDE flag is used or expand outward
if the AW_HIDE flag is not used.
AW_HOR_POSITIVE Animate the window from left to right. This flag can be used with roll or slide animation.
It is ignored when used with the AW_CENTER flag.
AW_HOR_NEGATIVE Animate the window from right to left. This flag can be used with roll or slide animation.
It is ignored when used with the AW_CENTER flag.
AW_VER_POSITIVE Animate the window from top to bottom. This flag can be used with roll or slide animation.
It is ignored when used with the AW_CENTER flag.
AW_VER_NEGATIVE Animate the window from bottom to top. This flag can be used with roll or slide animation.
It is ignored when used with the AW_CENTER flag.

以上内容是从MSDN中摘录的,要淡入淡出的效果的话,用到AW_BELND。

三、控制窗口显示的代码

CMainFrame::OnCreate(…)
{
	//...
	AnimateWindow(GetSafeHwnd(),1000,AW_CENTER|AW_BLEND);
	//…
}      
四、 关闭的代码
CMainFrame::OnClose(..)
{
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER|AW_BLEND);
}      
  其实AnimateWindow只是利用了windows本身的方法,如果您要更加有个性的窗口效果,那就得多做写些代码了,一分辛苦,一分收获吧
就这写这么多吧,不明白的,一看源码,二查MSDN,三请教高手。

五、结束语

  其实就MSN的提示窗口来说,如果要从使用复杂一点的背景和效果,那么还有刷新屏幕的问题,应做到无闪刷新.由于时间苍促,不足之处必然有之,同时以上代码也参考了一部分以前 VCKBASE 技术文档,在此表示感谢!

如果有问题,欢迎交流!共同进步!

Sambios 2004.9.1
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 myfaq.com.cn All rights reserved. www.myfaq.com.cn 版权所有