[INCLUDE]
IsHighColor
SendMessage

[CODE]
#If Shell_NotifyIcon Then
Public Sub LoadResEx_WindowIcon_MultiColor(ByVal hWnd As Long, ByVal ResID As Long, Optional ByVal ptrTrayToUpdate As Long)
#Else
Public Sub LoadResEx_WindowIcon_MultiColor(ByVal hWnd As Long, ByVal ResID As Long)
#End If
  Dim Old1 As Long
  Dim Old2 As Long
  #If Shell_NotifyIcon Then
    Dim Old3 As Long
    Dim xType1 As NOTIFYICONDATA
    #End If
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  #If LoadResEx_SetThemeFile Or (InIDE And LoadResEx_SetLanguageFile) Then
    Dim hModule As Long
    #End If
  '4th!
  
  Old1 = SendMessage(hWnd, &H80&, 0&, 0&)
  Old2 = SendMessage(hWnd, &H80&, 1&, 0&)
  #If Shell_NotifyIcon Then
    If Not ptrTrayToUpdate = 0& Then
      Call RtlMoveMemory(xType1, ByVal ptrTrayToUpdate, 24&)
      Old3 = xType1.hIcon
      End If
    #End If
  If Not ResID = -1& Then
    #If LoadResEx_SetThemeFile Then
      #If (InIDE And LoadResEx_SetLanguageFile) Then
        If LoadResEx_ThemeFile_hModule = App.hInstance Then
          hModule = LoadResEx_LanguageFile_hModule
          Else
          hModule = LoadResEx_ThemeFile_hModule
          End If
        #Else
        hModule = LoadResEx_ThemeFile_hModule
        #End If
      #ElseIf (InIDE And LoadResEx_SetLanguageFile) Then
      hModule = LoadResEx_LanguageFile_hModule
      #End If
ReLoop:
    For xLong1 = -Clng(IsHighColor) To 0& Step -1&
      #If LoadResEx_SetThemeFile Or (InIDE And LoadResEx_SetLanguageFile) Then
        xLong2 = LoadImageA(hModule, ByVal (ResID + xLong1), 1&, 16&, 16&, 0&)
        xLong3 = LoadImageA(hModule, ByVal (ResID + xLong1 + 15), 1&, 32&, 32&, 0&)
        #Else
        xLong2 = LoadImageA(App.hInstance, ByVal (ResID + xLong1), 1&, 16&, 16&, 0&)
        xLong3 = LoadImageA(App.hInstance, ByVal (ResID + xLong1 + 15), 1&, 32&, 32&, 0&)
        #End If
      If xLong2 = 0& Then
        If Not xLong3 = 0& Then xLong2 = xLong3: GoTo UpdateMain
        Else
        If xLong3 = 0& Then xLong3 = xLong2
UpdateMain:
        Call SendMessage(hWnd, &H80&, 0&, xLong2)
        Call SendMessage(hWnd, &H80&, 1&, xLong3)
          
        'If Not (Old1 = 0&) Then Call DestroyIcon(Old1)
        'If Not (Old2 = Old1 Or Old2 = 0&) Then Call DestroyIcon(Old2)
          
        #If Shell_NotifyIcon Then
          If Not ptrTrayToUpdate = 0& Then
            If xLong1 = 0 Or IsHighTrayColor Then
              GoTo RealUpdateTrayPre
              Else
              #If LoadResEx_SetThemeFile Or (InIDE And LoadResEx_SetLanguageFile) Then
                xLong3 = LoadImageA(hModule, ByVal ResID, 1&, 16&, 16&, 0&)
                #Else
                xLong3 = LoadImageA(App.hInstance, ByVal ResID, 1&, 16&, 16&, 0&)
                #End If
              If Not xLong3 = 0& Then GoTo RealUpdateTray
RealUpdateTrayPre:
              xLong3 = xLong2
RealUpdateTray:
              xType1.hIcon = xLong3
              Call RtlMoveMemory(ByVal ptrTrayToUpdate, xType1, 24&)
              If Not xType1.Reserved_cbsize = 0& Then Call Shell_NotifyIconEx(1&, ptrTrayToUpdate)
              End If
            End If
          'AndClearTray
          #End If
        GoTo FoundIcon
        End If
      Next

    #If LoadResEx_SetThemeFile Then
      If Not hModule = App.hInstance Then
        #If (InIDE And LoadResEx_SetLanguageFile) Then
          If hModule = LoadResEx_ThemeFile_hModule And Not hModule = LoadResEx_LanguageFile_hModule Then
            hModule = LoadResEx_LanguageFile_hModule
            GoTo ReLoop
            End If
          #End If
        hModule = App.hInstance
        GoTo ReLoop
        End If
      #ElseIf (InIDE And LoadResEx_SetLanguageFile) Then
      If Not hModule = App.hInstance Then
        hModule = App.hInstance
        GoTo ReLoop
        End If
      #End If
    End If

FoundIcon:
  If Not (Old1 = 0&) Then Call DestroyIcon(Old1)
  If Not (Old2 = Old1 Or Old2 = 0&) Then Call DestroyIcon(Old2)
  #If Shell_NotifyIcon Then
    'AndClearTray:
    If Not (Old3 = Old1 Or Old3 = 0&) Then Call DestroyIcon(Old3)
    #End If
  End Sub
