Re: CSpinButtonCtrl, CTabCtrl transparent oder im Edelstahllook ?
- From: "Karsten Schulz" <kahnpost@xxxxxxxxxx>
- Date: Tue, 11 Dec 2007 10:37:37 +0100
Hi,
einen Transparent Blit, kann mit der GDI nur über umwegen erreichen,
das geht so:
TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight,int stretchx, int stretchy, HBITMAP hBitmap, int nXSrc, int
nYSrc,
COLORREF colorTransparent, HPALETTE hPal )
{
CDC dc, memDC, maskDC, tempDC;
dc.Attach( hdcDest );
maskDC.CreateCompatibleDC(&dc);
CBitmap maskBitmap;
//add these to store return of SelectObject() calls
CBitmap* pOldMemBmp = NULL;
CBitmap* pOldMaskBmp = NULL;
HBITMAP hOldTempBmp = NULL;
memDC.CreateCompatibleDC(&dc);
tempDC.CreateCompatibleDC(&dc);
CBitmap bmpImage;
bmpImage.CreateCompatibleBitmap( &dc, nWidth, nHeight );
pOldMemBmp = memDC.SelectObject( &bmpImage );
// Select and realize the palette
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && hPal )
{
::SelectPalette( dc, hPal, FALSE );
dc.RealizePalette();
::SelectPalette( memDC, hPal, FALSE );
}
hOldTempBmp = (HBITMAP) ::SelectObject( tempDC.m_hDC, hBitmap );
memDC.BitBlt( 0,0,nWidth, nHeight, &tempDC, nXSrc, nYSrc, SRCCOPY );
//memDC.StretchBlt(0,0,nWidth, nHeight, &tempDC, nXSrc, nYSrc, stretchx,
stretchy,SRCCOPY );
// Create monochrome bitmap for the mask
maskBitmap.CreateBitmap( nWidth, nHeight, 1, 1, NULL );
pOldMaskBmp = maskDC.SelectObject( &maskBitmap );
memDC.SetBkColor( colorTransparent );
// Create the mask from the memory DC
maskDC.BitBlt( 0, 0, nWidth, nHeight, &memDC, 0, 0, SRCCOPY );
//maskDC.StretchBlt( 0,0, nWidth, nHeight, &memDC, 0,0, stretchx,
stretchy,SRCCOPY );
// Set the background in memDC to black. Using SRCPAINT with black
// and any other color results in the other color, thus making
// black the transparent color
memDC.SetBkColor(RGB(0,0,0));
memDC.SetTextColor(RGB(255,255,255));
memDC.BitBlt(0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
//memDC.StretchBlt( 0,0, nWidth, nHeight, &maskDC, 0,0, stretchx,
stretchy,SRCAND );
// Set the foreground to black. See comment above.
dc.SetBkColor(RGB(255,255,255));
dc.SetTextColor(RGB(0,0,0));
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
//dc.StretchBlt( nXDest, nYDest, nWidth, nHeight, &maskDC, 0,0,
stretchx, stretchy,SRCAND );
// Combine the foreground with the background
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &memDC, 0, 0, SRCPAINT);
//dc.StretchBlt(nXDest, nYDest, nWidth, nHeight, &memDC, 0,0, stretchx,
stretchy,SRCPAINT );
if (hOldTempBmp)
::SelectObject( tempDC.m_hDC, hOldTempBmp);
if (pOldMaskBmp)
maskDC.SelectObject( pOldMaskBmp );
if (pOldMemBmp)
memDC.SelectObject( pOldMemBmp );
dc.Detach();
}
Ich tätige derartige Operationen im Speicher
das kann so aussehen,
Kopiert ein Rechteck von QuallAdress nach ZielAdress ohne transparez zu
beachten
void CDraw::BltMap(DWORD soff,DWORD doff,DWORD width,WORD height)
{
__asm
{
mov ebx, this
mov edi, [ebx]CDraw.m_pTmp
mov ebx, [ebx]CDraw.m_Width
add edi, doff
mov esi, soff
mov edx, width
mov ax, height
add ebx, edx
shl ebx, 2
lp1: mov ecx,edx
rep movsd
sub edi,ebx
sub esi,ebx
dec ax
jnz short lp1
}
}
Kopiert ein Rechteck von QuallAdress nach ZielAdress , kopiert nicht farben
die r,g,b enthalten
void CDraw::BltColMap(DWORD soff,DWORD doff,DWORD width,WORD height,BYTE
r,BYTE g, BYTE b)
{
__asm
{
mov ebx, this
mov edi, [ebx]CDraw.m_pTmp;
mov edx, [ebx]CDraw.m_Width
add edi,doff
mov esi,soff
add edx,width
shl edx,2
xor ebx,ebx
mov bx,height
mainloop:
mov ecx,width
nextpt:
lodsd
//------------------------------ Begin
RGB --------------------------------------
red:
ror eax,0
cmp al,r
je processred
green:
ror eax,8
cmp al,g
je processgreen
blue:
ror eax,8
cmp al,b
je processblue
//--------------------------------------End
RGB -----------------------------------
ror eax,16
jmp putpix
//---- RGB
processor--------------------------------------------------------------
processred:
rol eax,0
jmp nextstep
processgreen:
rol eax,8
jmp nextstep
processblue:
rol eax,16
//---- END RGB
processor-----------------------------------------------------------
nextstep:
add edi,4
jmp next
putpix:
stosd
next:
dec ecx
jnz nextpt
sub esi,edx
sub edi,edx
dec bx
jnz mainloop
}
}
"Michael Andreas" <MichaelAndreas@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb im
Newsbeitrag news:43307470-63BE-4350-94AD-3A7A73D1F1B7@xxxxxxxxxxxxxxxx
Hi,
könnt Ihr mir einen Tipp geben, wie ich dir Objekte
CSpinButtonCtrl, CTabCtrl transparent oder im Edelstahllook
darstellen kann?
Danke Michael
.
- Prev by Date: Re: Umstieg von 2005 auf 2008 - Probleme
- Next by Date: Re: SHGetFileInfo
- Previous by thread: SHGetFileInfo
- Next by thread: Post a paste message
- Index(es):