Sign in to follow this  
Followers 0
supersonic

_TrayItemSetIcon() - 'Wrong' icon background color under 2003 / XP ???

1 post in this topic

#1 ·  Posted (edited)

Hi,

I've found a great way to set icons for tray items:

.

Unfortunately a 'wrong' icon background color is displayed under XP / 2003 (see attachment).

Here's what I have so far:

#include-once

#include <Constants.au3>
; <...>
#include ".\WinAPIEx\WinAPIEx.au3"

AutoItSetOption("MustDeclareVars", 1) ; Opt()
AutoItSetOption("TrayMenuMode", 1) ; Opt()

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
ExitLoop
EndIf
If TrayGetMsg() = $aTrayItems[2] Then
ExitLoop
EndIf
Sleep(10)
WEnd

Exit

; [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

In order to run the code you need Yashied's WinAPIEx UDF ( ).

Greets,

-supersonic.

post-34380-0-32536100-1340872346_thumb.j

Edited by supersonic

Share this post


Link to post
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
Sign in to follow this  
Followers 0