[INCLUDE]
LoadResEx_Icon_Shared

[CODE]
Public Function LoadResEx_Icon(ByVal ResID As Long, Optional ByVal DesiredSize As Long = 32&) As Long
  Dim xLong1 As Long

  #If LoadResEx_SetThemeFile Then
    For xLong1 = LoadResex_Caps_WinDIcon To 0& Step -1&
      If IconIDIsUseable(xLong1, LoadResex_Caps_WinDIcon) Then
        LoadResEx_Icon = LoadImageA(LoadResEx_ThemeFile_hModule, ByVal (ResID + xLong1), 1&, DesiredSize, DesiredSize, 0&)
        If Not LoadResEx_Icon = 0& Then Exit Function
        End If
      Next
    #End If

  For xLong1 = LoadResex_Caps_WinDIcon To 0& Step -1&
    If IconIDIsUseable(xLong1, LoadResex_Caps_WinDIcon) Then
      LoadResEx_Icon = LoadImageA(App.hInstance, ByVal (ResID + xLong1), 1&, DesiredSize, DesiredSize, 0&)
      If Not LoadResEx_Icon = 0& Then Exit Function
      End If
    Next

  #If InIDE And LoadResEx_SetLanguageFile Then
    For xLong1 = LoadResex_Caps_WinDIcon To 0& Step -1&
      If IconIDIsUseable(xLong1, LoadResex_Caps_WinDIcon) Then
        LoadResEx_Icon = LoadImageA(LoadResEx_LanguageFile_hModule, ByVal (ResID + xLong1), 1&, DesiredSize, DesiredSize, 0&)
        If Not LoadResEx_Icon = 0& Then Exit Function
        End If
      Next
    #End If
  End Function