void TextRenderGdi::Lock() { CrashIf(hdcGfxLocked); Region r; Status st = gfx->GetClip(&r); // must call before GetHDC(), which locks gfx CrashIf(st != Ok); HRGN hrgn = r.GetHRGN(gfx); hdcGfxLocked = gfx->GetHDC(); SelectClipRgn(hdcGfxLocked, hrgn); DeleteObject(hrgn); SelectFont(hdcGfxLocked, currFont); ::SetTextColor(hdcGfxLocked, textColor.ToCOLORREF()); ::SetBkColor(hdcGfxLocked, textBgColor.ToCOLORREF()); }
bool LayeredWnd::EnableGlass(Gdiplus::Bitmap *mask) { if (mask == NULL) { return false; } /* Disable for Windows 8+ */ if (IsWindows8OrGreater()) { return false; } /* Disable for Windows XP */ if (IsWindowsXPOrGreater() == true && IsWindowsVistaOrGreater() == false) { return false; } _glassMask = mask; using namespace Gdiplus; ARGB searchArgb = 0xFF000000; unsigned int height = _glassMask->GetHeight(); unsigned int width = _glassMask->GetWidth(); Region glassRegion; glassRegion.MakeEmpty(); bool match = false; /* One row of pixels is scanned at a time, so the height is 1. */ Rect rec(0, 0, 0, 1); for (unsigned int y = 0; y < height; ++y) { for (unsigned int x = 0; x < width; ++x) { Color pixelColor; _glassMask->GetPixel(x, y, &pixelColor); ARGB pixelArgb = pixelColor.GetValue(); if (searchArgb == pixelArgb && (x + 1 != width)) { if (match) { continue; } match = true; rec.X = x; rec.Y = y; } else if (match) { /* Reached the end of a matching line */ match = false; rec.Width = x - rec.X; glassRegion.Union(rec); } } } DWM_BLURBEHIND blurBehind = { 0 }; blurBehind.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; blurBehind.fEnable = TRUE; Graphics g(_glassMask); blurBehind.hRgnBlur = glassRegion.GetHRGN(&g); HRESULT hr = DwmEnableBlurBehindWindow(Window::Handle(), &blurBehind); return SUCCEEDED(hr); }