Jump to content

Strange tray item icon colors


Recommended Posts

Hi,

I have found a code example how to set tray item icons:

.

Under Windows Vista & 7 this works pretty well. Under Windows XP the colors looks somehow ugly (please see attachment).

Here's the (modified) code example:

#include-once

#include <Constants.au3>
#include ".WinAPIExWinAPIEx.au3"

Opt("TrayMenuMode", 1)

Global $aTrayItems[3]

$aTrayItems[0] = TrayCreateItem("Test1")
$aTrayItems[1] = TrayCreateItem("Test2")
     TrayItemSetState(-1, $TRAY_DISABLE)
     TrayCreateItem("")
$aTrayItems[2] = TrayCreateItem("Exit")

_TrayItemSetIcon(0, @SystemDir & "shell32.dll", 43)
_TrayItemSetIcon(1, @SystemDir & "shell32.dll", 44)

TraySetState()

While 1
If GUIGetMsg() = -3 Then
  Exit
EndIf
If TrayGetMsg() = $aTrayItems[2] Then
  Exit
EndIf
Sleep(10)
WEnd

; [http://msdn.microsoft.com/en-us/library/windows/desktop/ms647998(VS.85).aspx],
; [http://msdn.microsoft.com/en-us/library/windows/desktop/ms648052(VS.85).aspx],
; [http://msdn.microsoft.com/en-us/library/windows/desktop/ms648070(VS.85).aspx],
; [http://www.autoitscript.com/forum/topic/139826-tray-menu-icons-without-substitute-gui/].
Func _TrayItemSetIcon($iItemIndex, $sIcon, $iIconIndex = 0, $iIconWidth = 16, $iIconHeight = 16, $iMenuIndex = 0)
Local $iReturn = 0
If FileExists($sIcon) = 1 Then
  Local $hIcon = _WinAPI_ShellExtractIcon($sIcon, $iIconIndex, $iIconWidth, $iIconHeight)
  If Not @error Then
   $hIcon = _WinAPI_Create32BitHBITMAP($hIcon, True, True)
   If Not @error Then
    Local $tIconInfo = DllStructCreate("int; dword; dword; ptr; ptr")
    If Not @error Then
     Local $aIconInfo = DllCall("user32.dll", "long", "GetIconInfo", "ptr", $hIcon, "ptr", DllStructGetPtr($tIconInfo))
     If Not @error Then
      Local $hBitmap = $hIcon
      Switch ($aIconInfo[0] <> 0)
       Case True
        $hBitmap = DllStructGetData($tIconInfo, 5)
        If Not @error Then
         ContinueCase
        Else ; Error.
         SetError(6, 0)
        EndIf
       Case Else
        DllCall("user32.dll", "int", "SetMenuItemBitmaps", "hwnd", TrayItemGetHandle($iMenuIndex), "int", $iItemIndex, "int", 0x00000400, "hwnd", $hBitmap, "hwnd", $hBitmap)
        If Not @error Then
         $iReturn = 1
        Else ; Error.
         SetError(7, 0)
        EndIf
      EndSwitch
     Else ; Error.
      SetError(5, 0)
     EndIf
    Else ; Error.
     SetError(4, 0)
    EndIf
    $tIconInfo = 0 ; ???
   Else ; Error.
    SetError(3, 0)
   EndIf
  Else ; Error.
   SetError(2, 0)
  EndIf
Else ; Error.
  SetError(1, 0)
EndIf
Return $iReturn
EndFunc   ;==>_TrayItemSetIcon

I tried out "everything" I know but I cannot solve it on my own.

Please, could anyone help me to improve this?

Greets,

-supersonic.

post-34380-0-18020700-1338292347_thumb.j

Edited by supersonic
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...