DimWnd.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "stdafx.h"
  2. #include "DimWnd.h"
  3. BEGIN_MESSAGE_MAP(CDimWnd, CFrameWnd)
  4. ON_WM_ERASEBKGND()
  5. END_MESSAGE_MAP()
  6. CDimWnd::CDimWnd(CWnd *pParent)
  7. {
  8. // Don't do anything if the main frame doesn't appear to be there,
  9. // or if there is already dimming happening.
  10. if (pParent != NULL)
  11. {
  12. // Get the client area of the window to dim.
  13. CRect rc;
  14. pParent->GetWindowRect(&rc);
  15. // Create a layered window for transparency, with no caption/border.
  16. CreateEx(WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW, NULL, TEXT(""),
  17. WS_POPUP, rc.left, rc.top, rc.Width(), rc.Height(),
  18. pParent->GetSafeHwnd(), NULL);
  19. // Bring in front of main window.
  20. BringWindowToTop();
  21. // Apply 25% opacity
  22. SetLayeredWindowAttributes(RGB(0, 0, 0), 64, LWA_ALPHA);
  23. // Show the dimmer window
  24. ShowWindow(SW_SHOW);
  25. }
  26. }
  27. CDimWnd::~CDimWnd()
  28. {
  29. }
  30. BOOL CDimWnd::OnEraseBkgnd(CDC* pDC)
  31. {
  32. // Fill with black
  33. CBrush backBrush(RGB(0, 0, 0));
  34. CBrush* pOldBrush = pDC->SelectObject(&backBrush);
  35. CRect rect;
  36. pDC->GetClipBox(&rect); // Erase the area needed
  37. pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
  38. pDC->SelectObject(pOldBrush);
  39. return TRUE;
  40. }