aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/General/gen_ml/mldwm.cpp
blob: 14cdd65f9742db89ba84a8066d73edf07b25cc27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "./mldwm.h"

typedef HRESULT (WINAPI *DWMSETWINDOWATTRIBUTE)(HWND /*hwnd*/, DWORD /*dwAttribute*/, LPCVOID /*pvAttribute*/, DWORD /*cbAttribute*/);
typedef HRESULT (WINAPI *DWMISCOMPOSITIONENABLED)(BOOL* /*pfEnabled*/);

static HMODULE hDwmModule = NULL;
static HRESULT loadResult = E_MLDWM_NOTLOADED;

static DWMSETWINDOWATTRIBUTE fnSetWindowAttribute = NULL;
static DWMISCOMPOSITIONENABLED fnIsCompositionEnabled = NULL;

HRESULT MlDwm_IsLoaded()
{
	return loadResult;
}

HRESULT MlDwm_LoadLibrary(void)
{
	if (E_MLDWM_NOTLOADED == loadResult)
	{
		hDwmModule = LoadLibraryW(L"dwmapi.dll");
		if (!hDwmModule) loadResult = E_MLDWM_LOADFAILED;
		else
		{
			fnSetWindowAttribute = (DWMSETWINDOWATTRIBUTE)GetProcAddress(hDwmModule, "DwmSetWindowAttribute");
			fnIsCompositionEnabled = (DWMISCOMPOSITIONENABLED)GetProcAddress(hDwmModule, "DwmIsCompositionEnabled");
			loadResult = S_OK;
		}
	}
	return loadResult;
}


HRESULT MlDwm_SetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute)
{
	if (!hDwmModule) return loadResult;
	if (!fnSetWindowAttribute) return E_MLDWM_BADFUNCTION;
	return fnSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute);
}

HRESULT MlDwm_IsCompositionEnabled(BOOL *pfEnabled)
{
	if (!hDwmModule) return loadResult;
	if (!fnIsCompositionEnabled) return E_MLDWM_BADFUNCTION;
	return fnIsCompositionEnabled(pfEnabled);
}