打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用VC 制作MSN、QQ 的消息提示窗口

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

jackyhwei 发布于 2010-12-01 09:50 点击:306次
用过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 技术文档,在此表示感谢!


如果您对此文章有任何疑问,欢迎到流媒体开发论坛提问。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
vc msn 信息提示
iOS 一张启动图
activity的切换时候无动画
内存DC
绘制半透明位图
VC图片的半透明处理
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服