HeartWindow.cpp
资源名称:heart.zip [点击查看]
上传用户:f12e50
上传日期:2007-01-04
资源大小:21k
文件大小:3k
源码类别:
其他小程序
开发平台:
Visual C++
- // HeartWindow.cpp : implementation file
- //
- #include "stdafx.h"
- #include "HeartWindow.h"
- #include "resource.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // HeartWindow
- HeartWindow::HeartWindow()
- {
- WNDCLASS wndcls;
- HINSTANCE hInst = AfxGetInstanceHandle();
- if(!(::GetClassInfo(hInst, HEARTWINDOW_CLASSNAME, &wndcls)))
- {
- // otherwise we need to register a new class
- wndcls.style = CS_NOCLOSE | CS_BYTEALIGNCLIENT;
- wndcls.lpfnWndProc = ::DefWindowProc;
- wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
- wndcls.hInstance = hInst;
- wndcls.hIcon = NULL;
- wndcls.hCursor = LoadCursor( hInst, IDC_ARROW );
- wndcls.hbrBackground = (HBRUSH)(COLOR_WINDOW);
- wndcls.lpszMenuName = NULL;
- wndcls.lpszClassName = HEARTWINDOW_CLASSNAME;
- if (!AfxRegisterClass(&wndcls))
- AfxThrowResourceException();
- }
- height = width = index = 0;
- m_hBitmap = NULL;
- }
- HeartWindow::~HeartWindow()
- {
- if (m_hBitmap) ::DeleteObject(m_hBitmap);
- }
- BEGIN_MESSAGE_MAP(HeartWindow, CWnd)
- //{{AFX_MSG_MAP(HeartWindow)
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // HeartWindow message handlers
- BOOL HeartWindow::Create(const RECT& rect, HBITMAP hbmp)
- {
- // TODO: Add your specialized code here and/or call the base class
- height = rect.bottom - rect.top + 1;
- width = rect.right - rect.left + 1;
- if (hbmp == NULL) {
- hbmp = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_DEFAULT));
- m_hBitmap = (HBITMAP)::CopyImage(hbmp, IMAGE_BITMAP, width, height, LR_COPYDELETEORG);
- } else m_hBitmap = (HBITMAP)::CopyImage(hbmp, IMAGE_BITMAP, width, height, 0);
- DWORD dwStyle = WS_VISIBLE| WS_POPUP |WS_DISABLED;
- DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
- if (! CreateEx(dwExStyle, HEARTWINDOW_CLASSNAME, NULL, dwStyle, rect, NULL, NULL, NULL)) return FALSE;
- OnPaint();
- CClientDC dc(this);
- CRgn rgn, r;
- rgn.CreateRectRgn(0,0,width,height);
- for (int i = 0; i < width; i++)
- for (int j = 0; j < height; j++)
- if (dc.GetPixel(i,j) == RGB(255,255,255)) {
- r.CreateRectRgn(i,j,i+1,j+1);
- rgn.CombineRgn(&rgn, &r, RGN_DIFF);
- r.DeleteObject();
- }
- if (!SetWindowRgn(HRGN(rgn),TRUE)) return FALSE;
- rgn.DeleteObject();
- return TRUE;
- }
- void HeartWindow::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // TODO: Add your message handler code here
- CDC dcCompatible;
- dcCompatible.CreateCompatibleDC(&dc);
- ::SelectObject(dcCompatible.m_hDC,m_hBitmap);
- dc.BitBlt(0,0,width,height,&dcCompatible,0,0,SRCCOPY);
- // Do not call CWnd::OnPaint() for painting messages
- }
- BOOL HeartWindow::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- //return CWnd::OnEraseBkgnd(pDC);
- return TRUE;
- }