我有一个基于FormView的SDI程序,我在FormView上面加载了一张BMP图片,图片的背景色也是和windows一样的灰色,在我的机器上显示的效果是FormView的颜色和图片的背景色一样的,融和比较好,可是在另一台机器上FormView的灰色和图片的背景色有深浅度的差别,看起来像补丁:(
能不能设置FormView的颜色呢?我可以得到图片的RGB,把FormView的颜色设置和图片相同?怎么做呢?
能不能设置FormView的颜色呢?我可以得到图片的RGB,把FormView的颜色设置和图片相同?怎么做呢?
TransparentBlt
The TransparentBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.BOOL TransparentBlt(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int hHeightDest, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
UINT crTransparent // color to make transparent
);
Parameters
hdcDest
[in] Handle to the destination device context.
nXOriginDest
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nYOriginDest
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nWidthDest
[in] Specifies the width, in logical units, of the destination rectangle.
hHeightDest
[in] Handle to the height, in logical units, of the destination rectangle.
hdcSrc
[in] Handle to the source device context.
nXOriginSrc
[in] Specifies the x-coordinate, in logical units, of the source rectangle.
nYOriginSrc
[in] Specifies the y-coordinate, in logical units, of the source rectangle.
nWidthSrc
[in] Specifies the width, in logical units, of the source rectangle.
nHeightSrc
[in] Specifies the height, in logical units, of the source rectangle.
crTransparent
[in] The RGB color in the source bitmap to treat as transparent.
Return Values
If the function succeeds, the return value is TRUE.If the function fails, the return value is FALSE. Windows NT/ 2000: To get extended error information, call GetLastError. Res
The TransparentBlt function supports all formats of source bitmaps. However, for 32 bpp bitmaps, it just copies the alpha value over. Use AlphaBlend to specify 32 bits-per-pixel bitmaps with transparency. If the source and destination rectangles are not the same size, the source bitmap is stretched to match the destination rectangle. When the SetStretchBltMode function is used, the iStretchMode modes of BLACKONWHITE and WHITEONBLACK are converted to COLORONCOLOR for the TransparentBlt function. The destination device context specifies the transformation type for the destination coordinates. The source device context specifies the transformation type for the source coordinates. TransparentBlt does not mirror a bitmap if either the width or height, of either the source or destination, is negative. Windows 98/Windows 2000: When used in a multimonitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail.Requirements
Windows NT/2000: Requires Windows 2000 or later.
Windows 95/98: Requires Windows 98 or later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Included as a resource in Msimg32.dll.
BOOL C**View::OnEraseBkgnd(CDC* pDC)
{
// 设置所要求背景色的刷子
CBrush backBrush(RGB(255, 128, 128));
// 保存旧刷子
CBrush* pOldBrush = pDC->SelectObject(&backBrush);
CRect rect;
pDC->GetClipBox(&rect); // 擦除所需的区域
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(pOldBrush);
return TRUE;
}
为什么得到的结果是0,0,0,0呢?应该得到那个区域呀?
再解释一下呀
CView->GetWindowRect(&rect);
pDC->GetClipBox(&rect); // 擦除所需的区域