DimWnd.cpp 1.3 KB

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