织梦CMS - 轻松建站从此开始!

罗索

当前位置: 主页>杂项技术>VC(MFC)>

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

jackyhwei 发布于 2010-12-01 09:50 点击:次 
用过QQ和MSN聊天工具的人都知道,只要好友上线,就会在托盘的位置处显示一个提示窗口,以是拉帘式的,或者是淡入淡出的形式出现;想想何不为自己的程式也加一个漂亮的提示窗口呢?
TAG:

本文相关源码:http://bbs.rosoo.net/forum.php?mod=viewthread&tid=1150

一、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中处理定时器消息,下面是处里定时器时用到的代码:

  1. CMsgWnd::CMsgWnd() 
  2. ... 
  3. SetTimer(ID_TIEMR_POP_WINDOW,20,NULL); 
  4. ... 
  5. void CMsgWnd::OnTimer(UINT nIDEvent) 
  6. static int nHeight=0; 
  7. int cy=GetSystemMetrics(SM_CYSCREEN); 
  8. int cx=GetSystemMetrics(SM_CXSCREEN); 
  9. RECT rect; 
  10. SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0); 
  11. int y=rect.bottom-rect.top; 
  12. int x=rect.right-rect.left; 
  13. x=x-WIN_WIDTH; 
  14. switch(nIDEvent) 
  15. case ID_TIMER_POP_WINDOW: 
  16. if(nHeight<=WIN_HEIGHT) 
  17. ++nHeight; 
  18. MoveWindow(x,y-nHeight,WIN_WIDTH,WIN_HEIGHT); 
  19. Invalidate(FALSE); 
  20. else 
  21. KillTimer(ID_TIMER_POP_WINDOW); 
  22. SetTimer(ID_TIMER_DISPLAY_DELAY,5000,NULL); 
  23. break
  24. case ID_TIMER_CLOSE_WINDOW: 
  25. if(nHeight>=0) 
  26. nHeight--; 
  27. MoveWindow(x,y-nHeight,WIN_WIDTH,nHeight); 
  28. else 
  29. KillTimer(ID_TIMER_CLOSE_WINDOW); 
  30. SendMessage(WM_CLOSE); 
  31. break
  32. case ID_TIMER_DISPLAY_DELAY: 
  33. KillTimer(ID_TIMER_DISPLAY_DELAY); 
  34. SetTimer(ID_TIMER_CLOSE_WINDOW,20,NULL); 
  35. break
  36. CWnd::OnTimer(nIDEvent); 
  37. }  

根据你设的定时器的长短来控制窗口的显示过程;

  1. BOOL AnimateWindow( 
  2. HWND hwnd, // handle to the window to animate 
  3. DWORD dwTime, // duration of animation 
  4. DWORD dwFlags // animation type 
  5. );  

二、QQ淡出淡出显示实现
其实用到一个API函数:AnimateWindow,下面是这个函数的一些说明:

上面的函数前两个参数一看就明白,不用说了,最后一个参数dwFlags设置动画窗口的样式:
各种标志说明:
标志 说明
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。

三、控制窗口显示的代码

  1. CMainFrame::OnCreate(…) 
  2. //... 
  3. AnimateWindow(GetSafeHwnd(),1000,AW_CENTER|AW_BLEND); 
  4. //… 
  5. }  

四、关闭的代码

  1. CMainFrame::OnClose(..) 
  2. AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER|AW_BLEND); 
  3. }  

其实AnimateWindow只是利用了windows本身的方法,如果您要更加有个性的窗口效果,那就得多做写些代码了,一分辛苦,一分收获吧

五、结束语

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

(秩名)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201012/10549.html]
本文出处:网络 作者:秩名
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容