1
0

mldwm.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "./mldwm.h"
  2. typedef HRESULT (WINAPI *DWMSETWINDOWATTRIBUTE)(HWND /*hwnd*/, DWORD /*dwAttribute*/, LPCVOID /*pvAttribute*/, DWORD /*cbAttribute*/);
  3. typedef HRESULT (WINAPI *DWMISCOMPOSITIONENABLED)(BOOL* /*pfEnabled*/);
  4. static HMODULE hDwmModule = NULL;
  5. static HRESULT loadResult = E_MLDWM_NOTLOADED;
  6. static DWMSETWINDOWATTRIBUTE fnSetWindowAttribute = NULL;
  7. static DWMISCOMPOSITIONENABLED fnIsCompositionEnabled = NULL;
  8. HRESULT MlDwm_IsLoaded()
  9. {
  10. return loadResult;
  11. }
  12. HRESULT MlDwm_LoadLibrary(void)
  13. {
  14. if (E_MLDWM_NOTLOADED == loadResult)
  15. {
  16. hDwmModule = LoadLibraryW(L"dwmapi.dll");
  17. if (!hDwmModule) loadResult = E_MLDWM_LOADFAILED;
  18. else
  19. {
  20. fnSetWindowAttribute = (DWMSETWINDOWATTRIBUTE)GetProcAddress(hDwmModule, "DwmSetWindowAttribute");
  21. fnIsCompositionEnabled = (DWMISCOMPOSITIONENABLED)GetProcAddress(hDwmModule, "DwmIsCompositionEnabled");
  22. loadResult = S_OK;
  23. }
  24. }
  25. return loadResult;
  26. }
  27. HRESULT MlDwm_SetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute)
  28. {
  29. if (!hDwmModule) return loadResult;
  30. if (!fnSetWindowAttribute) return E_MLDWM_BADFUNCTION;
  31. return fnSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute);
  32. }
  33. HRESULT MlDwm_IsCompositionEnabled(BOOL *pfEnabled)
  34. {
  35. if (!hDwmModule) return loadResult;
  36. if (!fnIsCompositionEnabled) return E_MLDWM_BADFUNCTION;
  37. return fnIsCompositionEnabled(pfEnabled);
  38. }