EnableExplicit

#ThemingAPI_Init = #True

Procedure ThemingAPI_Init()
  Global *IsThemeActive
  Global *IsAppThemed
  Global *OpenThemeData
  Global *IsThemeBackgroundPartiallyTransparent
  Global *DrawThemeBackground
  Global *DrawThemeParentBackground
  Global *CloseThemeData

  Define.i xLong1
  xLong1 = GetModuleHandle_(@"uxtheme.dll")
  If Not xLong1
    xLong1 = LoadLibrary_(@"uxtheme.dll")
    EndIf
  If xLong1
    *IsThemeActive = GetProcAddress(xLong1, "IsThemeActive")
    If *IsThemeActive
      *IsAppThemed = GetProcAddress(xLong1, "IsAppThemed")
      EndIf
    If *IsAppThemed
      *OpenThemeData = GetProcAddress(xLong1, "OpenThemeData")
      EndIf
    If *OpenThemeData
      *IsThemeBackgroundPartiallyTransparent = GetProcAddress(xLong1, "IsThemeBackgroundPartiallyTransparent")
      EndIf
    If *IsThemeBackgroundPartiallyTransparent
      *DrawThemeBackground = GetProcAddress(xLong1, "DrawThemeBackground")
      EndIf
    If *DrawThemeBackground
      *DrawThemeParentBackground = GetProcAddress(xLong1, "DrawThemeParentBackground")
      EndIf
    If *DrawThemeParentBackground
      *CloseThemeData = GetProcAddress(xLong1, "CloseThemeData")
      EndIf
    If Not *CloseThemeData
      *IsThemeActive = 0
      *IsAppThemed = 0
      *OpenThemeData = 0
      *IsThemeBackgroundPartiallyTransparent = 0
      *DrawThemeBackground = 0
      *DrawThemeParentBackground = 0
      ;*CloseThemeData = 0
      EndIf
    EndIf
  EndProcedure

Procedure.i IsThemeActive()
  Define.i xResult
  If *IsThemeActive
    xResult = CallFunctionFast(*IsThemeActive)
    EndIf
  ProcedureReturn xResult
  EndProcedure

Procedure.i IsAppThemed()
  Define.i xResult
  If *IsAppThemed
      xResult = CallFunctionFast(*IsAppThemed)
    EndIf
  ProcedureReturn xResult
  EndProcedure

Procedure.i OpenThemeData(hWnd.i, *pszClassList)
  Define.i xResult
  If *OpenThemeData
    xResult = CallFunctionFast(*OpenThemeData, hWnd, *pszClassList)
    EndIf
  ProcedureReturn xResult
  EndProcedure

Procedure.i IsThemeBackgroundPartiallyTransparent(hTheme.i, iPartId.i, iStateId.i)
  Define.i xResult
  If *IsThemeBackgroundPartiallyTransparent
    xResult = CallFunctionFast(*IsThemeBackgroundPartiallyTransparent, hTheme, iPartId, iStateId)
    EndIf
  ProcedureReturn xResult
  EndProcedure

Procedure DrawThemeBackground(hTheme.i, lhdc.i, iPartId.i, iStateId.i, *pRect, pClipRect.i)
  If *DrawThemeBackground
    CallFunctionFast(*DrawThemeBackground, hTheme, lhdc, iPartId, iStateId, *pRect, pClipRect)
    EndIf
  EndProcedure

Procedure DrawThemeParentBackground(hWnd.i, hdc.i, *prc)
  If *DrawThemeParentBackground
    CallFunctionFast(*DrawThemeParentBackground, hWnd, hdc, *prc)
    EndIf
  EndProcedure

Procedure CloseThemeData(hTheme.i)
  If *CloseThemeData
    CallFunctionFast(*CloseThemeData, hTheme)
    EndIf
  EndProcedure

; IDE Options = PureBasic 5.21 LTS (Windows - x64)
; CursorPosition = 48
; FirstLine = 44
; Folding = --
; EnableUnicode
; EnableXP