ReactOS 0.4.15-dev-8119-g4fb2fdb
dimmedwindow.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS msgina.dll
4 * FILE: dll/win32/msgina/dimmedwindow.cpp
5 * PURPOSE: Implementation of ShellDimScreen
6 * PROGRAMMER: Mark Jansen
7 */
8
9#define COM_NO_WINDOWS_H
10#include "msgina.h"
11#include <wingdi.h>
12#include <atlbase.h>
13#include <atlcom.h>
14#include <pseh/pseh2.h>
15
16CComModule gModule;
17
18// Please note: The INIT_TIMER is a workaround because ReactOS does not redraw the desktop in time,
19// so the start menu is still visible on the dimmed screen.
20#define INIT_TIMER_ID 0x112233
21#define FADE_TIMER_ID 0x12345
22
24 public CComObjectRootEx<CComMultiThreadModelNoCS>,
26{
27private:
36 int m_step;
37
39
40public:
42 : m_hwnd(NULL)
43 , m_hdc(NULL)
46 , m_width(0)
47 , m_height(0)
48 , m_bytes(NULL)
49 , m_step(0)
50 {
51 WNDCLASSEXW wndclass = {sizeof(wndclass)};
52 wndclass.lpfnWndProc = WndProc;
53 wndclass.hInstance = hDllInstance;
54 wndclass.hCursor = LoadCursor(0, IDC_ARROW);
55 wndclass.lpszClassName = L"DimmedWindowClass";
56
57 if (!RegisterClassExW(&wndclass))
58 return;
59
62
63 memset(&m_bi, 0, sizeof(m_bi));
64 m_bi.bmiHeader.biSize = sizeof(m_bi);
71 m_bytes = new UCHAR[m_width * 4 * m_height];
72
75
77 L"DimmedWindowClass",
78 NULL,
80 x, y,
82 NULL, NULL,
84 (LPVOID)this);
85 }
86
88 {
89 if (m_hwnd)
91 UnregisterClassW(L"DimmedWindowClass", hDllInstance);
92 if (m_oldbitmap)
94 if (m_hbitmap)
96 if (m_hdc)
98 if (m_bytes)
99 delete[] m_bytes;
100 }
101
102 // This is needed so that we do not capture the start menu while it's closing.
104 {
105 MSG msg;
106
108 {
109 while (::PeekMessage(&msg, m_hwnd, 0, 0, PM_REMOVE))
110 {
113
115 break;
116 }
117 }
118 }
119
120 void Init()
121 {
122 Capture();
123
127
129 }
130
131 void Capture()
132 {
133 HWND desktopWnd = GetDesktopWindow();
134 HDC desktopDC = GetDC(desktopWnd);
135
136 m_hdc = CreateCompatibleDC(desktopDC);
137
140 BitBlt(m_hdc, 0, 0, m_width, m_height, desktopDC, 0, 0, SRCCOPY);
141
142 ReleaseDC(desktopWnd, desktopDC);
143 }
144
145 bool Step()
146 {
147 // Stop after 10 steps
148 if (m_step++ > 10 || !m_bytes)
149 return false;
150
152 if (lines)
153 {
154 for (int xh = 0; xh < m_height; ++xh)
155 {
156 int h = m_width * 4 * xh;
157 for (int w = 0; w < m_width; ++w)
158 {
159 UCHAR b = m_bytes[(h + w * 4) + 0];
160 UCHAR g = m_bytes[(h + w * 4) + 1];
161 UCHAR r = m_bytes[(h + w * 4) + 2];
162
163 // Standard formula to convert a color.
164 int gray = (r * 30 + g * 59 + b * 11) / 100;
165 if (gray < 0)
166 gray = 0;
167
168 // Do not fade too fast.
169 r = (r*2 + gray) / 3;
170 g = (g*2 + gray) / 3;
171 b = (b*2 + gray) / 3;
172
173 m_bytes[(h + w * 4) + 0] = b;
174 m_bytes[(h + w * 4) + 1] = g;
175 m_bytes[(h + w * 4) + 2] = r;
176 }
177 }
179 }
180 return true;
181 }
182
183 void Blt(HDC hdc)
184 {
185 BitBlt(hdc, 0, 0, m_width, m_height, m_hdc, 0, 0, SRCCOPY);
186 }
187
189 {
190 return m_hwnd;
191 }
192
193
197
198};
199
200
202{
203 switch (uMsg)
204 {
205 case WM_NCCREATE:
206 {
207 LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
208 CDimmedWindow* info = static_cast<CDimmedWindow*>(lpcs->lpCreateParams);
211 break;
212 }
213
214 case WM_PAINT:
215 {
217 if (info)
218 {
219 PAINTSTRUCT ps;
220 BeginPaint(hWnd, &ps);
221 info->Blt(ps.hdc);
222 EndPaint(hWnd, &ps);
223 }
224 return 0;
225 }
226
227 case WM_TIMER:
228 {
229 if (wParam == INIT_TIMER_ID)
230 {
233 info->Init();
234 }
235 else if (wParam == FADE_TIMER_ID)
236 {
238 if (info && info->Step())
240 else
242 }
243 return 0;
244 }
245
246 default:
247 break;
248 }
249
250 return DefWindowProc(hWnd, uMsg, wParam, lParam);
251}
252
253
254extern "C"
256ShellDimScreen(void** pUnknown, HWND* hWindow)
257{
258 CComObject<CDimmedWindow> *pWindow;
259 HRESULT hr = CComObject<CDimmedWindow>::CreateInstance(&pWindow);
260 ULONG refcount;
261
262 pWindow->WaitForInit();
263
264 if (!IsWindow(pWindow->Wnd()))
265 {
266 refcount = pWindow->AddRef();
267 while (refcount)
268 refcount = pWindow->Release();
269
270 return E_FAIL;
271 }
272
274 {
276 *hWindow = pWindow->Wnd();
277 hr = S_OK;
278 }
280 {
282 refcount = pWindow->AddRef();
283 while (refcount)
284 refcount = pWindow->Release();
285 }
287
288 return hr;
289}
tShellDimScreen ShellDimScreen
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
const GUID IID_IUnknown
BITMAPINFO m_bi
static LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
HBITMAP m_hbitmap
HGDIOBJ m_oldbitmap
void Blt(HDC hdc)
static HINSTANCE hDllInstance
Definition: clb.c:30
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
#define INIT_TIMER_ID
#define FADE_TIMER_ID
CComModule gModule
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
#define BI_RGB
Definition: precomp.h:56
_In_ PUNKNOWN pUnknown
Definition: drmk.h:76
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
pKey DeleteObject()
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean g
Definition: glext.h:6204
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define END_COM_MAP()
Definition: atlcom.h:592
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define WS_POPUP
Definition: pedump.c:616
#define WS_EX_TOPMOST
Definition: pedump.c:647
long LONG
Definition: pedump.c:60
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define DefWindowProc
Definition: ros2win.h:31
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
LPCWSTR lpszClassName
Definition: winuser.h:3226
WNDPROC lpfnWndProc
Definition: winuser.h:3218
HCURSOR hCursor
Definition: winuser.h:3223
HINSTANCE hInstance
Definition: winuser.h:3221
USHORT biBitCount
Definition: precomp.h:46
ULONG biCompression
Definition: precomp.h:47
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
LPVOID lpCreateParams
Definition: winuser.h:2940
#define GWLP_USERDATA
Definition: treelist.c:63
eMaj lines
Definition: tritemp.h:206
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
uint32_t ULONG
Definition: typedefs.h:59
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define DIB_RGB_COLORS
Definition: wingdi.h:367
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
int WINAPI SetDIBits(_In_opt_ HDC, _In_ HBITMAP, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCCOPY
Definition: wingdi.h:333
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
#define WM_PAINT
Definition: winuser.h:1620
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define SM_CYVIRTUALSCREEN
Definition: winuser.h:1039
#define GetWindowLongPtrW
Definition: winuser.h:4829
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define IDC_ARROW
Definition: winuser.h:687
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_NCCREATE
Definition: winuser.h:1683
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:656
#define SM_CXVIRTUALSCREEN
Definition: winuser.h:1038
#define WM_TIMER
Definition: winuser.h:1742
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define PM_REMOVE
Definition: winuser.h:1196
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define LoadCursor
Definition: winuser.h:5812
#define PeekMessage
Definition: winuser.h:5830
HDC WINAPI GetDC(_In_opt_ HWND)
#define SW_SHOW
Definition: winuser.h:775
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
#define DispatchMessage
Definition: winuser.h:5765
#define SM_XVIRTUALSCREEN
Definition: winuser.h:1036
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SetWindowLongPtrW
Definition: winuser.h:5346
BOOL WINAPI IsWindowVisible(_In_ HWND)
BOOL WINAPI DestroyWindow(_In_ HWND)
int WINAPI GetSystemMetrics(_In_ int)
#define SM_YVIRTUALSCREEN
Definition: winuser.h:1037
unsigned char UCHAR
Definition: xmlstorage.h:181