Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 of 2
http://stackoverow.com/questions/29038024/drawing-a-w...
help
_WIN32_WINNT 0x0600
#include
#include
#include
#include
#include
<assert.h>
<stdio.h>
<windows.h>
<gdiplus.h>
<dwmapi.h>
2 of 2
http://stackoverow.com/questions/29038024/drawing-a-w...
szWindowClass,
"Transparent Window",
WS_OVERLAPPED | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
NULL, NULL, hInstance, NULL);
Gdiplus::Bitmap *m_pImage = Gdiplus::Bitmap::FromFile(L"sample.png", FALSE);
Gdiplus::Color bg(0,0,0,0);
m_pImage->GetHBITMAP(bg, &hBitmap);
assert(hBitmap);
DWM_BLURBEHIND blurBehind = { 0 };
blurBehind.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
blurBehind.hRgnBlur = CreateRectRgn(0, 0, -1, -1);
blurBehind.fEnable = TRUE;
blurBehind.fTransitionOnMaximized = FALSE;
DwmEnableBlurBehindWindow(hWnd, &blurBehind);
DeleteObject(blurBehind.hRgnBlur);
ShowWindow(hWnd, SW_SHOW);
// Main message loop
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
Is this really broken? How can I fix my code? Is this a Windows bug/limitation?
Is there another way to achieve my goal of drawing a bitmap with alpha into a window with a border?
Update: I did some tests using Direct2D and Direct3D to fill the client area with the bitmaps, but they mis-rendered in the same way.
windows
winapi
edited Aug 14 '15 at 3:10
jturney
1,304
20
1 Answer
The DWM doesn't do blurring any more (this feature was deemed too power hungry and was
removed in Windows 8), so I'd guess that it's not properly compositing the background area of
your window any more - and therefore you aren't getting the "automatic" alpha effect it was
giving you in Windows 7.
This is kind of an unusual way to draw transparent windows to be honest. Using
UpdateLayeredWindow is the "official" way and would have the benefit of working on Windows 8
as well as Windows 7.
answered Mar 13 '15 at 20:24
Jonathan Potter
26.2k
21
44
Maybe I'm missing something, but I think that windows drawn with UpdateLayeredWindow don't get given a
frame, which makes it a bit of a non-starter for my purposes, unless there is some way around that...
jturney Mar 13 '15 at 20:30
@jturney Note that in Windows 8 you can use the WS_EX_LAYERED style on a child window, so you could
probably do this with two code paths, using your existing method for Windows 7 and earlier. Are you sure
though that you can't do it in Windows 7? (I've never actually tried enabling any of the border styles in the
window when I've done that in the past) Jonathan Potter Mar 13 '15 at 20:31