add transparent window support for Windows Vista and up

This commit is contained in:
Christopher Pelloux 2016-02-23 23:40:22 -05:00
parent 95b4c2c17f
commit 5796b966bf
4 changed files with 28 additions and 0 deletions

View File

@ -314,6 +314,7 @@ int main(int argc, char *argv[])
glfwWindowHint(GLFW_DEPTH_BITS, 16); glfwWindowHint(GLFW_DEPTH_BITS, 16);
glfwWindowHint(GLFW_ALPHA_BITS, 8); glfwWindowHint(GLFW_ALPHA_BITS, 8);
glfwWindowHint(GLFW_TRANSPARENT, GLFW_TRUE); glfwWindowHint(GLFW_TRANSPARENT, GLFW_TRUE);
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
window = glfwCreateWindow( 300, 300, "Gears", NULL, NULL ); window = glfwCreateWindow( 300, 300, "Gears", NULL, NULL );
if (!window) if (!window)

View File

@ -97,6 +97,8 @@ static GLFWbool loadLibraries(void)
GetProcAddress(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled"); GetProcAddress(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled");
_glfw.win32.dwmapi.DwmFlush = (DWMFLUSH_T) _glfw.win32.dwmapi.DwmFlush = (DWMFLUSH_T)
GetProcAddress(_glfw.win32.dwmapi.instance, "DwmFlush"); GetProcAddress(_glfw.win32.dwmapi.instance, "DwmFlush");
_glfw.win32.dwmapi.DwmEnableBlurBehindWindow = (DWMENABLEBLURBEHINDWINDOW_T)
GetProcAddress(_glfw.win32.dwmapi.instance, "DwmEnableBlurBehindWindow");
} }
_glfw.win32.shcore.instance = LoadLibraryA("shcore.dll"); _glfw.win32.shcore.instance = LoadLibraryA("shcore.dll");

View File

@ -120,21 +120,32 @@ typedef enum PROCESS_DPI_AWARENESS
} PROCESS_DPI_AWARENESS; } PROCESS_DPI_AWARENESS;
#endif /*DPI_ENUMS_DECLARED*/ #endif /*DPI_ENUMS_DECLARED*/
typedef struct _DWM_BLURBEHIND
{
DWORD dwFlags;
BOOL fEnable;
HRGN hRgnBlur;
BOOL fTransitionOnMaximized;
} DWM_BLURBEHIND, *PDWM_BLURBEHIND;
// winmm.dll function pointer typedefs // winmm.dll function pointer typedefs
typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T)(UINT,LPJOYCAPS,UINT); typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T)(UINT,LPJOYCAPS,UINT);
typedef MMRESULT (WINAPI * JOYGETPOS_T)(UINT,LPJOYINFO); typedef MMRESULT (WINAPI * JOYGETPOS_T)(UINT,LPJOYINFO);
typedef MMRESULT (WINAPI * JOYGETPOSEX_T)(UINT,LPJOYINFOEX); typedef MMRESULT (WINAPI * JOYGETPOSEX_T)(UINT,LPJOYINFOEX);
typedef DWORD (WINAPI * TIMEGETTIME_T)(void); typedef DWORD (WINAPI * TIMEGETTIME_T)(void);
typedef HRESULT(WINAPI * DWMENABLEBLURBEHINDWINDOW_T)(HWND, const DWM_BLURBEHIND*);
#define _glfw_joyGetDevCaps _glfw.win32.winmm.joyGetDevCaps #define _glfw_joyGetDevCaps _glfw.win32.winmm.joyGetDevCaps
#define _glfw_joyGetPos _glfw.win32.winmm.joyGetPos #define _glfw_joyGetPos _glfw.win32.winmm.joyGetPos
#define _glfw_joyGetPosEx _glfw.win32.winmm.joyGetPosEx #define _glfw_joyGetPosEx _glfw.win32.winmm.joyGetPosEx
#define _glfw_timeGetTime _glfw.win32.winmm.timeGetTime #define _glfw_timeGetTime _glfw.win32.winmm.timeGetTime
#define _glfw_DwmEnableBlurBehindWindow _glfw.win32.dwmapi.DwmEnableBlurBehindWindow
// user32.dll function pointer typedefs // user32.dll function pointer typedefs
typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void); typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void);
typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT); typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT);
#define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware #define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware
#define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx #define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx
#define _glfw_DwmEnableBlurBehindWindow _glfw.win32.dwmapi.DwmEnableBlurBehindWindow
// dwmapi.dll function pointer typedefs // dwmapi.dll function pointer typedefs
typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*); typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*);
@ -237,6 +248,7 @@ typedef struct _GLFWlibraryWin32
HINSTANCE instance; HINSTANCE instance;
DWMISCOMPOSITIONENABLED_T DwmIsCompositionEnabled; DWMISCOMPOSITIONENABLED_T DwmIsCompositionEnabled;
DWMFLUSH_T DwmFlush; DWMFLUSH_T DwmFlush;
DWMENABLEBLURBEHINDWINDOW_T DwmEnableBlurBehindWindow;
} dwmapi; } dwmapi;
// shcore.dll // shcore.dll

View File

@ -732,6 +732,19 @@ static int createWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig)
window->win32.numer = GLFW_DONT_CARE; window->win32.numer = GLFW_DONT_CARE;
window->win32.denom = GLFW_DONT_CARE; window->win32.denom = GLFW_DONT_CARE;
// Accelerated transparent windows
// It currently doesn't support decorated windows.
// If decorated is required we just return an opaque window.
// Since DwmEnableBlurBehindWindow is supported since Vista,
// previous versions will simply get an opaque window.
if (!window->decorated && _glfw_DwmEnableBlurBehindWindow && window->transparent) {
DWM_BLURBEHIND bb = { 0 };
bb.dwFlags = 3; // DWM_BB_ENABLE | DWM_BB_BLURREGION
bb.hRgnBlur = CreateRectRgn(0, 0, -1, -1); // an invalid hRgnBlur makes the the window transparent
bb.fEnable = TRUE;
_glfw_DwmEnableBlurBehindWindow(window->win32.handle, &bb);
}
return GLFW_TRUE; return GLFW_TRUE;
} }