HeartWindow.cpp
上传用户:f12e50
上传日期:2007-01-04
资源大小:21k
文件大小:3k
源码类别:

其他小程序

开发平台:

Visual C++

  1. // HeartWindow.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "HeartWindow.h"
  5. #include "resource.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // HeartWindow
  13. HeartWindow::HeartWindow()
  14. {
  15. WNDCLASS wndcls;
  16. HINSTANCE hInst = AfxGetInstanceHandle();
  17. if(!(::GetClassInfo(hInst, HEARTWINDOW_CLASSNAME, &wndcls)))
  18. {
  19. // otherwise we need to register a new class
  20. wndcls.style = CS_NOCLOSE | CS_BYTEALIGNCLIENT;
  21. wndcls.lpfnWndProc = ::DefWindowProc;
  22. wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
  23. wndcls.hInstance = hInst;
  24. wndcls.hIcon = NULL;
  25. wndcls.hCursor = LoadCursor( hInst, IDC_ARROW );
  26. wndcls.hbrBackground = (HBRUSH)(COLOR_WINDOW); 
  27. wndcls.lpszMenuName = NULL;
  28. wndcls.lpszClassName = HEARTWINDOW_CLASSNAME;
  29. if (!AfxRegisterClass(&wndcls))
  30. AfxThrowResourceException();
  31. }
  32. height = width  = index = 0;
  33. m_hBitmap = NULL;
  34. }
  35. HeartWindow::~HeartWindow()
  36. {
  37. if (m_hBitmap) ::DeleteObject(m_hBitmap);
  38. }
  39. BEGIN_MESSAGE_MAP(HeartWindow, CWnd)
  40. //{{AFX_MSG_MAP(HeartWindow)
  41. ON_WM_PAINT()
  42. ON_WM_ERASEBKGND()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // HeartWindow message handlers
  47. BOOL HeartWindow::Create(const RECT& rect, HBITMAP hbmp) 
  48. {
  49. // TODO: Add your specialized code here and/or call the base class
  50. height = rect.bottom - rect.top + 1;
  51. width = rect.right - rect.left + 1;
  52. if (hbmp == NULL) {
  53. hbmp = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_DEFAULT));
  54. m_hBitmap = (HBITMAP)::CopyImage(hbmp, IMAGE_BITMAP, width, height, LR_COPYDELETEORG);
  55. } else m_hBitmap = (HBITMAP)::CopyImage(hbmp, IMAGE_BITMAP, width, height, 0);
  56. DWORD dwStyle = WS_VISIBLE| WS_POPUP |WS_DISABLED; 
  57. DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
  58. if (! CreateEx(dwExStyle, HEARTWINDOW_CLASSNAME, NULL, dwStyle, rect, NULL, NULL, NULL)) return FALSE; 
  59. OnPaint();
  60. CClientDC dc(this);
  61. CRgn rgn, r;
  62. rgn.CreateRectRgn(0,0,width,height);
  63. for (int i = 0; i < width; i++)
  64. for (int j = 0; j < height; j++)
  65. if (dc.GetPixel(i,j) == RGB(255,255,255)) {
  66. r.CreateRectRgn(i,j,i+1,j+1);
  67. rgn.CombineRgn(&rgn, &r, RGN_DIFF);
  68. r.DeleteObject();
  69. }
  70. if (!SetWindowRgn(HRGN(rgn),TRUE)) return FALSE;
  71. rgn.DeleteObject();
  72. return TRUE;
  73. }
  74. void HeartWindow::OnPaint() 
  75. {
  76. CPaintDC dc(this); // device context for painting
  77. // TODO: Add your message handler code here
  78. CDC dcCompatible;
  79. dcCompatible.CreateCompatibleDC(&dc);
  80. ::SelectObject(dcCompatible.m_hDC,m_hBitmap);
  81. dc.BitBlt(0,0,width,height,&dcCompatible,0,0,SRCCOPY);
  82. // Do not call CWnd::OnPaint() for painting messages
  83. }
  84. BOOL HeartWindow::OnEraseBkgnd(CDC* pDC) 
  85. {
  86. // TODO: Add your message handler code here and/or call default
  87. //return CWnd::OnEraseBkgnd(pDC);
  88. return TRUE;
  89. }