Archive for September 9th, 2008
- In: MFC
- Leave a Comment
void CEMCHotButton::DisabledBlt (HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc) { ASSERT (hdcDest && hBitmap); ASSERT (nWidth > 0 && nHeight > 0); // Create a generic DC for all BitBlts HDC hDC = CreateCompatibleDC (hdcDest); ASSERT (hDC); if (hDC) { // Create a DC for the monochrome DIB section HDC bwDC = CreateCompatibleDC(hDC); ASSERT (bwDC); if (bwDC) { // Create the monochrome DIB section with a black and white palette struct { BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[2]; } RGBBWBITMAPINFO = { { // a BITMAPINFOHEADER sizeof(BITMAPINFOHEADER), // biSize nWidth, // biWidth; nHeight, // biHeight; 1, // biPlanes; 1, // biBitCount BI_RGB, // biCompression; 0, // biSizeImage; 0, // biXPelsPerMeter; 0, // biYPelsPerMeter; 0, // biClrUsed; 0 // biClrImportant; }, { { 0×00, 0×00, 0×00, 0×00 }, { 0xFF, 0xFF, 0xFF, 0×00 } } }; void* pbitsBW; HBITMAP hBitmapBW = CreateDIBSection (bwDC, (LPBITMAPINFO) &RGBBWBITMAPINFO, DIB_RGB_COLORS, &pbitsBW, NULL, 0); ASSERT (hBitmapBW); if (hBitmapBW) { // Attach the monochrome DIB section and the bitmap to the DCs SelectObject (bwDC, hBitmapBW); SelectObject (hDC, hBitmap); // BitBlt the bitmap into the monochrome DIB section BitBlt (bwDC, 0, 0, nWidth, nHeight, hDC, nXSrc, nYSrc, SRCCOPY); // Paint the destination rectangle in gray FillRect (hdcDest, CRect (nXDest, nYDest, nXDest + nWidth, nYDest + nHeight), GetSysColorBrush (COLOR_3DFACE)); // BitBlt the black bits in the monochrome bitmap into COLOR_3DHILIGHT bits in the destination DC // The magic ROP comes from the Charles Petzold’s book HBRUSH hb = CreateSolidBrush (GetSysColor (COLOR_3DHILIGHT)); HBRUSH oldBrush = (HBRUSH) SelectObject (hdcDest, hb); BitBlt (hdcDest, nXDest + 1, nYDest + 1, nWidth, nHeight, bwDC, 0, 0, 0xB8074A); // BitBlt the black bits in the monochrome bitmap into COLOR_3DSHADOW bits in the destination DC hb = CreateSolidBrush (GetSysColor (COLOR_3DSHADOW)); DeleteObject (SelectObject(hdcDest, hb)); BitBlt (hdcDest, nXDest, nYDest, nWidth, nHeight, bwDC, 0, 0, 0xB8074A); DeleteObject (SelectObject (hdcDest, oldBrush)); DeleteObject (hBitmapBW); } VERIFY (DeleteDC (bwDC)); } VERIFY (DeleteDC(hDC)); } }
Tags: Disabled Bitmap, Disabled BMP
- In: MFC
- Leave a Comment
void CEMCHotButton::DrawGradientRect (CDC *pDC, CRect r, COLORREF cLeft, COLORREF cRight, BOOL bVertical) { CRect stepR; // rectangle for color’s band COLORREF color; // color for the bands float fStep; if(bVertical) { fStep = ((float)r.Height())/255.0f; } else { fStep = ((float)r.Width())/255.0f; // width of color’s band } for (int iOnBand = 0; iOnBand < 255; iOnBand++) { // set current band if(bVertical) { SetRect(&stepR, r.left, r.top+(int)(iOnBand * fStep), r.right, r.top+(int)((iOnBand+1)* fStep)); } else { SetRect(&stepR, r.left+(int)(iOnBand * fStep), r.top, r.left+(int)((iOnBand+1)* fStep), r.bottom); } // set current color color = RGB((GetRValue(cRight)-GetRValue(cLeft))*((float)iOnBand)/255.0f+GetRValue(cLeft), (GetGValue(cRight)-GetGValue(cLeft))*((float)iOnBand)/255.0f+GetGValue(cLeft), (GetBValue(cRight)-GetBValue(cLeft))*((float)iOnBand)/255.0f+GetBValue(cLeft)); // fill current band pDC->FillSolidRect(stepR,color); } }
Tags: Gradient