1
0

wintheme.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "main.h"
  2. #include "./wintheme.h"
  3. typedef HRESULT(WINAPI *UXTHEME_SETWINDOWTHEME)(HWND /*hwnd*/, LPCWSTR /*pszSubAppName*/, LPCWSTR /*pszSubIdList*/);
  4. typedef BOOL (WINAPI *UXTHEME_ISAPPTHEMED)(void);
  5. typedef HRESULT (WINAPI *DWM_SETWINDOWATTRIBUTE)(HWND /*hwnd*/, DWORD /*dwAttribute*/, LPCVOID /*pvAttribute*/, DWORD /*cbAttribute*/);
  6. typedef HRESULT (WINAPI *DWM_ISCOMPOSITIONENABLED)(BOOL* /*pfEnabled*/);
  7. static DWM_SETWINDOWATTRIBUTE fnSetWindowAttribute = NULL;
  8. static DWM_ISCOMPOSITIONENABLED fnIsCompositionEnabled = NULL;
  9. static UXTHEME_SETWINDOWTHEME fnSetWindowTheme = NULL;
  10. static UXTHEME_ISAPPTHEMED fnIsAppThemed = NULL;
  11. static HMODULE hDwmModule = NULL;
  12. static HMODULE hUxThemeModule = NULL;
  13. static HRESULT loadDwmResult = E_LIBRARY_NOTLOADED;
  14. static HRESULT loadUxThemeResult = E_LIBRARY_NOTLOADED;
  15. HRESULT UxTheme_LoadLibrary(void)
  16. {
  17. if (E_LIBRARY_NOTLOADED == loadUxThemeResult)
  18. {
  19. hUxThemeModule = LoadLibraryW(L"uxtheme.dll");
  20. if (!hUxThemeModule) loadUxThemeResult = E_LIBRARY_LOADFAILED;
  21. else
  22. {
  23. fnSetWindowTheme = (UXTHEME_SETWINDOWTHEME)GetProcAddress(hUxThemeModule, "SetWindowTheme");
  24. fnIsAppThemed = (UXTHEME_ISAPPTHEMED)GetProcAddress(hUxThemeModule, "IsAppThemed");
  25. loadUxThemeResult = S_OK;
  26. }
  27. }
  28. return loadUxThemeResult;
  29. }
  30. HRESULT Dwm_LoadLibrary(void)
  31. {
  32. if (E_LIBRARY_NOTLOADED == loadDwmResult)
  33. {
  34. hDwmModule = LoadLibraryW(L"dwmapi.dll");
  35. if (!hDwmModule) loadDwmResult = E_LIBRARY_LOADFAILED;
  36. else
  37. {
  38. fnSetWindowAttribute = (DWM_SETWINDOWATTRIBUTE)GetProcAddress(hDwmModule, "DwmSetWindowAttribute");
  39. fnIsCompositionEnabled = (DWM_ISCOMPOSITIONENABLED)GetProcAddress(hDwmModule, "DwmIsCompositionEnabled");
  40. loadDwmResult = S_OK;
  41. }
  42. }
  43. return loadDwmResult;
  44. }
  45. HRESULT UxTheme_GetLoadResult(void)
  46. {
  47. return loadUxThemeResult;
  48. }
  49. HRESULT Dwm_GetLoadResult()
  50. {
  51. return loadDwmResult;
  52. }
  53. HRESULT SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList)
  54. {
  55. if (!hUxThemeModule) return loadUxThemeResult;
  56. if (!fnSetWindowTheme) return E_LIBRARY_BADFUNCTION;
  57. return fnSetWindowTheme(hwnd, pszSubAppName, pszSubIdList);
  58. }
  59. BOOL IsAppThemed(void)
  60. {
  61. if (!hUxThemeModule) return FALSE;
  62. if (!fnIsAppThemed) return FALSE;
  63. return fnIsAppThemed();
  64. }
  65. HRESULT DwmSetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute)
  66. {
  67. if (!hDwmModule) return loadDwmResult;
  68. if (!fnSetWindowAttribute) return E_LIBRARY_BADFUNCTION;
  69. return fnSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute);
  70. }
  71. HRESULT DwmIsCompositionEnabled(BOOL *pfEnabled)
  72. {
  73. if (!hDwmModule) return loadDwmResult;
  74. if (!fnIsCompositionEnabled) return E_LIBRARY_BADFUNCTION;
  75. return fnIsCompositionEnabled(pfEnabled);
  76. }