NotifyWnd.cpp
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. // NotifyWnd.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "NotifyWnd.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. #define ICON_OFFSET 2
  22. #define IDT_MOVE 1001
  23. #define IDT_WAIT 1002
  24. CNotifyWnd *CNotifyWnd::notifyWnd = NULL;
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CNotifyWnd
  27. CNotifyWnd::CNotifyWnd(HICON icon, const char *text, DWORD t)
  28. {
  29. if (notifyWnd)
  30. delete notifyWnd;
  31. notifyWnd = this;
  32. hIcon = icon;
  33. strText = text;
  34. clrBackground = GetSysColor(COLOR_INFOBK);
  35. clrText = GetSysColor(COLOR_INFOTEXT);
  36. wndWidth = 200;
  37. wndHeight = 50;
  38. waitTime = t;
  39. SystemParametersInfo(SPI_GETWORKAREA, 0, rcWorkArea, 0);
  40. CreateEx(WS_EX_TOOLWINDOW, AfxRegisterWndClass(0), NULL, WS_POPUP,
  41. rcWorkArea.right - wndWidth, rcWorkArea.bottom, wndWidth, 0,
  42. NULL, NULL);
  43. SetTimer(IDT_MOVE, 20, NULL);
  44. }
  45. CNotifyWnd::~CNotifyWnd()
  46. {
  47. notifyWnd = NULL;
  48. }
  49. BEGIN_MESSAGE_MAP(CNotifyWnd, CWnd)
  50. //{{AFX_MSG_MAP(CNotifyWnd)
  51. ON_WM_PAINT()
  52. ON_WM_TIMER()
  53. ON_WM_LBUTTONDOWN()
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CNotifyWnd message handlers
  58. void CNotifyWnd::PostNcDestroy() 
  59. {
  60. delete this;
  61. }
  62. void CNotifyWnd::OnPaint() 
  63. {
  64. CPaintDC dc(this); // device context for painting
  65. CPen pen(PS_SOLID, 1, clrText);
  66. CBrush br(clrBackground);
  67. CFont font;
  68. font.Attach((HFONT)GetStockObject(DEFAULT_GUI_FONT));
  69. CPen *penOld = dc.SelectObject(&pen);
  70. CBrush *brOld = dc.SelectObject(&br);
  71. CFont *fontOld = dc.SelectObject(&font);
  72. COLORREF oldTextColor = dc.SetTextColor(clrText);
  73. int oldBkMode = dc.SetBkMode(TRANSPARENT);
  74. CRect rc(0, 0, wndWidth, wndHeight);
  75. dc.Rectangle(rc);
  76. rc.InflateRect(-1, -1);
  77. dc.DrawIcon(ICON_OFFSET, (wndHeight - 32) / 2, hIcon);
  78. rc.left += 32 + (ICON_OFFSET << 1);
  79. dc.DrawText(strText, rc, DT_SINGLELINE | DT_VCENTER);
  80. dc.SetTextColor(oldTextColor);
  81. dc.SetBkMode(oldBkMode);
  82. dc.SelectObject(fontOld);
  83. dc.SelectObject(penOld);
  84. dc.SelectObject(brOld);
  85. // Do not call CWnd::OnPaint() for painting messages
  86. }
  87. void CNotifyWnd::OnTimer(UINT nIDEvent) 
  88. {
  89. if (nIDEvent == IDT_MOVE) {
  90. CRect rc;
  91. GetWindowRect(rc);
  92. rc.top -= 2;
  93. if (rc.top >= rcWorkArea.bottom - wndHeight)
  94. SetWindowPos(&wndTopMost,
  95. rc.left, rc.top, rc.Width(), rc.Height(), SWP_SHOWWINDOW);
  96. else {
  97. KillTimer(nIDEvent);
  98. if (waitTime)
  99. SetTimer(IDT_WAIT, waitTime, NULL);
  100. }
  101. } else if (nIDEvent == IDT_WAIT)
  102. DestroyWindow();
  103. else
  104. CWnd::OnTimer(nIDEvent);
  105. }
  106. void CNotifyWnd::OnLButtonDown(UINT nFlags, CPoint point) 
  107. {
  108. DestroyWindow();
  109. }