////for class CBitmapSK
CBitmapSK::CBitmapSK()
{
}
CBitmapSK::~CBitmapSK()
{
}
BOOL CBitmapSK::LoadBitmapEx(LPCTSTR lpszFileName)
{
DeleteObject();
ASSERT(m_hObject==NULL);
HBITMAP hBitmap = NULL;
hBitmap = (HBITMAP)::LoadImage(0, lpszFileName, IMAGE_BITMAP, 0, 0, 0);
if(hBitmap == NULL) return FALSE;
return CBitmap::Attach(hBitmap);
}
BOOL CBitmapSK::LoadBitmapEx(LPCTSTR lpszResourceName, UINT nIDResource)
{
DeleteObject();
ASSERT(m_hObject==NULL);
if (lpszResourceName != NULL)
{
return CBitmap::LoadBitmap(lpszResourceName);
}
if (nIDResource != 0)
{
return CBitmap::LoadBitmap(nIDResource);
}
return FALSE;
}
BOOL CBitmapSK::Draw(CDC *pDC, LPRECT lprDes)
{
ASSERT(pDC!=NULL);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *bmp = dc.SelectObject(this);
pDC->BitBlt(lprDes->left, lprDes->top,
lprDes->right - lprDes->left, lprDes->bottom - lprDes->top,
&dc, 0, 0, SRCCOPY);
dc.SelectObject(bmp);
dc.DeleteDC();
bmp = NULL;
return TRUE;
}
BOOL CBitmapSK::Draw(CDC *pDC, LPRECT lprDes, COLORREF crTrans, BOOL isTrans)
{
ASSERT(pDC!=NULL);
if (!isTrans)
{
return Draw(pDC, lprDes);
}
else
{
return TransparentBitBlt(pDC->GetSafeHdc(),
lprDes->left,lprDes->top,Width(),Height(),
(HBITMAP)this->GetSafeHandle(),0,0,crTrans,NULL);
}
}
BOOL CBitmapSK::Draw( CDC *pDC, int x, int y, LPRECT lprSrc)
{
ASSERT(pDC!=NULL);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *pOldbmp = dc.SelectObject(this);
if (lprSrc != NULL)
{
//Copies a bitmap from the source device context to this current device context
pDC->BitBlt(x, y, lprSrc->right - lprSrc->left, lprSrc->bottom - lprSrc->top,
&dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
else
{
pDC->BitBlt(x, y, Width(), Height(), &dc, 0, 0, SRCCOPY);
}
dc.SelectObject(pOldbmp);
dc.DeleteDC();
pOldbmp = NULL;
return TRUE;
}
BOOL CBitmapSK::Draw( CDC *pDC, int x, int y, LPRECT lprSrc, COLORREF crTrans, BOOL isTrans)
{
ASSERT(pDC!=NULL);
if (!isTrans)
{
return Draw(pDC, x, y, lprSrc);
}
else
{
return TransparentBitBlt(pDC->GetSafeHdc(), x, y, lprSrc->right - lprSrc->left, lprSrc->bottom - lprSrc->top,
(HBITMAP)this->GetSafeHandle(), lprSrc->left, lprSrc->top, crTrans, NULL );
}
}
BOOL CBitmapSK::Fill(CDC *pDC, LPRECT lprDes, LPRECT lprSrc)
{
ASSERT(pDC!=NULL);
int widthDes, widthSrc, heightDes, heightSrc;
widthDes = abs(lprDes->right - lprDes->left);
widthSrc = abs(lprSrc->right - lprSrc->left);
heightDes = abs(lprDes->bottom - lprDes->top);
heightSrc = abs(lprSrc->bottom - lprSrc->top);
int paddingx, paddingy, i, j;
paddingx = int(widthDes / widthSrc);
paddingy = int(heightDes / heightSrc);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *pOldbmp = dc.SelectObject(this);
if (widthDes <= widthSrc)
{
if (heightDes <= heightSrc)
{
Draw(pDC, lprDes);
}
else
{
for (i=1; i<paddingy; i++)
{
pDC->BitBlt(lprDes->left, lprDes->top + heightSrc*(i-1), widthDes, heightSrc,&dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
pDC->BitBlt(lprDes->left,lprDes->top + heightSrc*(i-1), widthDes, heightDes - heightSrc*(i-1), &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
}
else
{
if (heightDes <= heightSrc)
{
for (i=1; i<paddingx; i++)
{
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top, widthSrc, heightDes, &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top, widthDes - widthSrc*(i-1), heightDes, &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
else
{
for (j=1; j<=paddingy; j++)
{
for (i=1; i<=paddingx; i++)
{
pDC->BitBlt(lprDes->left + widthSrc*(i-1),lprDes->top + heightSrc*(j-1), widthSrc, heightSrc, &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top + heightSrc*(j-1),widthDes - widthSrc*(i-1), heightSrc, &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
}
for (i=1; i<=paddingx; i++)
{
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top + heightSrc*(j-1), widthSrc, heightDes - heightSrc*(j-1), &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top + heightSrc*(j-1), widthDes - widthSrc*(i-1),
heightDes - heightSrc*(j-1), &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
dc.SelectObject(pOldbmp);
dc.DeleteDC();
pOldbmp = NULL;
return TRUE;
}
BOOL CBitmapSK::TransparentDraw(CDC * pDC, int x, int y, COLORREF crTrans)
{
ASSERT(pDC!=NULL);
return TransparentBitBlt(pDC->GetSafeHdc(), x, y, Width(), Height(), (HBITMAP)this->GetSafeHandle(),
0, 0, crTrans, NULL );
}
BOOL CBitmapSK::StretchDraw(CDC *pDC, LPRECT lprDes, LPRECT lprSrc)
{
ASSERT(pDC!=NULL);
if(lprDes == NULL) return FALSE;
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *pOldbmp = dc.SelectObject(this);
//SetStretchBltMode(pDC->GetSafeHdc(), COLORONCOLOR);
if(!lprSrc)
{
pDC->StretchBlt(lprDes->left, lprDes->top, lprDes->right, lprDes->bottom, &dc, 0, 0, Width(), Height(), SRCCOPY);
}
else
{
pDC->StretchBlt(lprDes->left, lprDes->top, lprDes->right - lprDes->left, lprDes->bottom - lprDes->top,
&dc, lprSrc->left, lprSrc->top, lprSrc->right - lprSrc->left, lprSrc->bottom - lprSrc->top,SRCCOPY);
}
dc.SelectObject(pOldbmp);
dc.DeleteDC();
pOldbmp = NULL;
return TRUE;
}
BOOL CBitmapSK::StretchDraw(CDC *pDC, LPRECT lprSrc)
{
ASSERT(pDC!=NULL);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *pOldbmp = dc.SelectObject(this);
pDC->StretchBlt(lprSrc->left, lprSrc->top, lprSrc->right, lprSrc->bottom, &dc,
0, 0, Width(), Height(), SRCCOPY);
dc.SelectObject(pOldbmp);
dc.DeleteDC();
pOldbmp = NULL;
return TRUE;
}
使用这个类实现了对话筐的换肤,测试还行。
暂时还没发现ce下的换肤第三方控件,见过最好的也就是那个CCeButton了,还是在EVC3.0下开发的。。。