STDMETHOD(Draw)(DWORD dwAspect, LONG, void*, DVTARGETDEVICE*, HDC, HDC hdc, LPCRECTL pRectBounds, LPCRECTL /* pRectWBounds */, BOOL (__stdcall *)(ULONG_PTR), ULONG_PTR) { if (dwAspect != DVASPECT_CONTENT) return DV_E_DVASPECT; if (pRectBounds == NULL) return E_INVALIDARG; LoadSmiley(); if (m_img == NULL) return E_FAIL; m_sizeExtent.cx = pRectBounds->right - pRectBounds->left; m_sizeExtent.cy = pRectBounds->bottom - pRectBounds->top; m_rectExt = m_sizeExtent; switch (m_animtype) { case animDrctRichEd: { m_rectExt.cy = pRectBounds->bottom - m_rectOrig.y; RECT frc = { 0, 0, m_sizeExtent.cx - 1, m_sizeExtent.cy - 1 }; HBITMAP hBmp = CreateCompatibleBitmap(hdc, frc.right, frc.bottom); HDC hdcMem = CreateCompatibleDC(hdc); HANDLE hOld = SelectObject(hdcMem, hBmp); HBRUSH hbr = CreateSolidBrush(m_bkg); FillRect(hdcMem, &frc, hbr); DeleteObject(hbr); m_img->DrawInternal(hdcMem, 0, 0, frc.right, frc.bottom); BitBlt(hdc, pRectBounds->left, pRectBounds->top, frc.right, frc.bottom, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hOld); DeleteObject(hBmp); DeleteDC(hdcMem); } GetDrawingProp(); break; case animHpp: m_orect = *(LPRECT)pRectBounds; default: m_img->DrawInternal(hdc, pRectBounds->left, pRectBounds->top, m_sizeExtent.cx - 1, m_sizeExtent.cy - 1); break; } m_allowAni = true; m_visible = true; return S_OK; }
void DoDirectDraw(HDC hdc) { HBITMAP hBmp = CreateCompatibleBitmap(hdc, m_rectExt.cx, m_rectExt.cy); HDC hdcMem = CreateCompatibleDC(hdc); HANDLE hOld = SelectObject(hdcMem, hBmp); RECT rc; rc.left = m_rectExt.cx - m_sizeExtent.cx; rc.top = m_rectExt.cy - m_sizeExtent.cy; rc.right = rc.left + m_sizeExtent.cx; rc.bottom = rc.top + m_sizeExtent.cy; HBRUSH hbr = CreateSolidBrush(m_bkg); RECT frc = { 0, 0, m_rectExt.cx, m_rectExt.cy }; FillRect(hdcMem, &frc, hbr); DeleteObject(hbr); m_img->DrawInternal(hdcMem, rc.left, rc.top, m_sizeExtent.cx - 1, m_sizeExtent.cy - 1); if (m_richFlags & REO_SELECTED) { HBRUSH hbr = CreateSolidBrush(m_bkg ^ 0xFFFFFF); FrameRect(hdcMem, &rc, hbr); DeleteObject(hbr); } if (m_richFlags & REO_INVERTEDSELECT) InvertRect(hdcMem, &rc); BitBlt(hdc, m_rectOrig.x, m_rectOrig.y, m_rectExt.cx, m_rectExt.cy, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hOld); DeleteObject(hBmp); DeleteDC(hdcMem); }