// Draw part of the DIB on a DC. BOOL PLWinBmpEx::DrawExtract( HDC dc, POINT pntDest, RECT rcSrc ) { // Compute destination rectangle RECT rcDst; rcDst.left = pntDest.x; rcDst.top = pntDest.y; rcDst.right = pntDest.x + abs(rcSrc.right - rcSrc.left); rcDst.bottom = pntDest.y + abs(rcSrc.bottom - rcSrc.top ); return DrawEx( dc, &rcDst, &rcSrc ); }
// Draw DIB on DC. void PLWinBmpEx::Draw( HDC dc, int x, int y, DWORD ) { // Compute destination rectangle RECT rcDst; rcDst.left = x; rcDst.top = y; rcDst.right = x + GetWidth(); rcDst.bottom = y + GetHeight(); (void) DrawEx( dc, &rcDst ); }
// Draws the bitmap on the given device context. // Scales the bitmap so w is the width and h the height. void PLWinBmpEx::StretchDraw( HDC hDC, int x, int y, int w, int h, DWORD ) { // Compute rectangles RECT rcSrc, rcDst; rcSrc.left = 0; rcSrc.top = 0; rcSrc.right = GetWidth(); rcSrc.bottom = GetHeight(); rcDst.left = x; rcDst.top = y; rcDst.right = x + w; rcDst.bottom = y + h; (void) DrawEx( hDC, &rcDst, &rcSrc ); }
// Play with the elastic bitmap... void PLWinBmpEx::StretchDraw( HDC dc, int x, int y, double Factor, DWORD ) { // Compute rectangles RECT rcSrc, rcDst; rcSrc.left = 0; rcSrc.top = 0; rcSrc.right = GetWidth(); rcSrc.bottom = GetHeight(); rcDst.left = x; rcDst.top = y; rcDst.right = x + int(Factor * GetWidth() ); rcDst.bottom = y + int(Factor * GetHeight()); (void) DrawEx( dc, &rcDst, &rcSrc ); }
BOOL CDirectControl::MouseEvent(UINT msg, int nX,int nY) { BOOL bRet=FALSE; if (msg==WM_MOUSELEAVE) { if (Down || Over) { Over=FALSE; Down=FALSE; DrawEx(); } return bRet; } if (nX>=x && nY>=y) { if (nX<=nHeight+x && nY<=nHeight+y) { bRet=TRUE; if(!Over && msg==WM_MOUSEMOVE){ Over=TRUE; DrawEx(); }else if(!Down && msg==WM_LBUTTONDOWN){ Over=TRUE; Down=TRUE; DrawEx(); }else if(Down && msg==WM_LBUTTONUP){ Over=TRUE; Down=FALSE; DrawEx(); OnClick(); } return bRet; } } if(Down && msg==WM_LBUTTONUP){ Over=FALSE; Down=FALSE; DrawEx(); return bRet; } if(!Down && Over && msg==WM_MOUSEMOVE){ Over=FALSE; DrawEx(); } return bRet; }