Sign in to follow this  
Followers 0
Uten

Traymenuex Udf. Add Icon Or Bmp To Trayitem

29 posts in this topic

#1 ·  Posted (edited)

EDIT: Seems like @Holger has done some terrific work this year related to this subject. Go check it out..:)

This UDF demonstrates how to add icon or bmp to a TrayItem or TrayMenu.

It's not perfect in the sense that it has no smart way of extracting the default icon for any file. To get a handle to the default, or first, resource of type icon you need to provided a callback function to EnumResourceTypes and friends (or something like that). And at the moment I don't know how to do that in autoit. Maybe a plugin? Or maybe persuade the developers to add support for TrayMenus and items to GUICtrlSetImage?

The UDF contains sample code in _Main(). It is commented out, so you have to uncoment.

You might want to modify paths and icon or bitmap references.

TrayMenuEx.au3

Edited by Uten

Share this post


Link to post
Share on other sites



The script doesn't work here. It quits immediately. Why?


iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

The script doesn't work here. It quits immediately. Why?

It's suppose to be an Include file

try creating a script in the same folder you saved the TrayMenuEx.au3 in.

.i.e.

#include "TrayMenuEx.au3"

_Main()
Func _Main()
    Opt("TrayMenuMode", 1) ; Don't show the default tray context menu
    local $autoitIcons=@ProgramFilesDir & "\Autoit3\icons\"
    local $bmpPathName = @WindowsDir & "\Blue Lace 16.bmp" 
    local $IExplorerPath = @ProgramFilesDir & "\internet explorer\iexplorer.exe"
    local $TMControlIDs[8], $hImg[8]
    ; Create a menu structure
    $TMControlIDs[0] = TrayCreateMenu("Options")
    $TMControlIDs[1] = TrayCreateItem("Opt1",$TMControlIDs[0])
    $TMControlIDs[2] = TrayCreateItem("Opt2",$TMControlIDs[0])
    $TMControlIDs[3] = TrayCreateItem("")
    
    $TMControlIDs[4] = TrayCreateItem("Test1")
    $TMControlIDs[5] = TrayCreateItem("IExplorer")
    $TMControlIDs[6] = TrayCreateItem("")
    $TMControlIDs[7] = TrayCreateItem("Exit")
    ; Add some icons
    
    $hImg[0] = _IconExtractFromFile("shell32.dll", 15)  ; Computer icon in dll
    $hImg[1] = _LoadImage($autoitIcons & "filetype1.ico", $IMAGE_ICON)
    $hImg[2] = _LoadImage($autoitIcons & "filetype2.ico", $IMAGE_ICON)
    $hImg[4] = _IconExtractFromFile(@AutoItExe, 0) ; This does not work for all files (ex:firefox). Even if the item reference is correct
    $hImg[5] = _IconExtractFromFile($IExplorerPath, 32528)
    $hImg[7] = _LoadImage($bmpPathName, $IMAGE_BITMAP)
    
    _TrayMenuAddIcon($hImg[0], 0)                  ; CReate a submenu
    _TrayMenuAddIcon($hImg[1], 0,$TMControlIDs[0]) ; First item on the sub menu
    _TrayMenuAddIcon($hImg[2], 1,$TMControlIDs[0]) ; Second on sub menu
    ;_TrayMenuAddIcon($hImg[3], 1)                 ; Seperator, between submenu and root
    _TrayMenuAddIcon($hImg[4], 2)                  ; Test1, expect Autoit icon
    _TrayMenuAddIcon($hImg[5], 3)                 ; IExplorer
    ;_TrayMenuAddIcon($hImg[6], 4)                 ; Seperator
    _TrayMenuAddImage($hImg[7], 5)                  ; Exit, expect blue bmp
    
    TraySetState()
    ; We can destroy the icon references after it has been loaded by the TrayItem
    _IconDestroy($hImg) ;Destroys handel or array of handels

    local $msg, $TrayMsg
    While 1
        if TrayGetMsg()= $TMControlIDs[7] then Exit
        $msg = GUIGetMsg() 
        switch $msg 
            case $GUI_EVENT_CLOSE
                exit
            case Else
                If $msg = 0 Then
                    ;sleep(250)
                Else
                    if $debug then ConsoleWrite("MSG LOOP: $msg:=" & $msg & @LF)
                EndIf
        EndSwitch
        
    WEnd    
    
EndFunc ;==>_Main

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Hi,

looks not 100% done, but very nice.

Good work! & thanks 4 sharing!

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

nice job..

are you still working on it uten?

Share this post


Link to post
Share on other sites

Hi,

Sorry to tell you all that this project has not had any focus since it was released :nuke:

As @th.meger pointed out it is not 100% finished. It lacks the ability to esilly add icons and bmp's from dll's and executables if I recall right (sometimes it works sometimes it don't depending on the file).

If I feel the urge to get icons (from binary files) in my tray menu again I might pick it up again. If anyone of you feel the urge :P and have some ideas for improvements I'll be more than happy to update the file in first post.

Happy coding ...

Share this post


Link to post
Share on other sites

So I need to include the file? But how do I create a new menu item with icon then?


iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

So I need to include the file? But how do I create a new menu item with icon then?

HI @Pieter

Did you trye the sample provided in the file? It is commented out. It was also provided in this thread by @gafrost

As you can see from the coed you first create a menu structure and then add bmp or icon references to selected items in the menu structure. I think the comments in the code should speak for them selfs but if anyone have suggestions for improvements I'm all ears.

Share this post


Link to post
Share on other sites

Oh, I forgot to read that. Sorry... *shame*


iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

(...)

; Include files
#include <GuiConstants.au3>
#include <TrayMenuEx.au3>

; Set idle icon
TraySetIcon("images/idle.ico")

Opt("TrayMenuMode",1)
TraySetToolTip("USBsyncer v" & $version)

local $traymenu[8], $hImg[8]

; Create right-click menu
$traymenu[0]        = TrayCreateItem("Synchronize now")
$traymenu[1]        = TrayCreateItem("Configure drive")
$traymenu[2]        = TrayCreateItem("")
$traymenu[3]        = TrayCreateItem("USBsyncer Homepage")

; Only display updater if it was installed
If FileExists("USBupdater.exe") Or FileExists("USBupdater.au3") Then
    $traymenu[4]        = TrayCreateItem("Check for updates")
Else
    $traymenu[4]    = "just a regular stinkin' string"
EndIf

; Continue creating right-click menu
$traymenu[5]        = TrayCreateItem("")
$traymenu[6]        = TrayCreateItem("About USBsyncer")
$traymenu[7]        = TrayCreateItem("Exit")

; Add icons
$hImg[0] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[1] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[2] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[3] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[4] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[5] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[6] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[7] = _LoadImage("images\idle.ico", $IMAGE_ICON)

TraySetState()

(...)
Did I forget something?

Edit: found it...

Edited by Pieter

iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

What's wrong here?

(...)

; Include files
#include <GuiConstants.au3>
#include <TrayMenuEx.au3>

; Set idle icon
TraySetIcon("images/idle.ico")

Opt("TrayMenuMode",1)
TraySetToolTip("USBsyncer v" & $version)

local $traymenu[8], $hImg[8]

; Create right-click menu
$traymenu[0]        = TrayCreateItem("Synchronize now")
$traymenu[1]        = TrayCreateItem("Configure drive")
$traymenu[2]        = TrayCreateItem("")
$traymenu[3]        = TrayCreateItem("USBsyncer Homepage")

; Only display updater if it was installed
If FileExists("USBupdater.exe") Or FileExists("USBupdater.au3") Then
    $traymenu[4]        = TrayCreateItem("Check for updates")
Else
    $traymenu[4]    = "just a regular stinkin' string"
EndIf

; Continue creating right-click menu
$traymenu[5]        = TrayCreateItem("")
$traymenu[6]        = TrayCreateItem("About USBsyncer")
$traymenu[7]        = TrayCreateItem("Exit")

; Add icons
$hImg[0] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[1] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[2] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[3] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[4] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[5] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[6] = _LoadImage("images\idle.ico", $IMAGE_ICON)
$hImg[7] = _LoadImage("images\idle.ico", $IMAGE_ICON)

; Assign them
_TrayMenuAddImage($hImg[0], 0)
_TrayMenuAddImage($hImg[1], 1)
_TrayMenuAddImage($hImg[2], 2)
_TrayMenuAddImage($hImg[3], 3)
_TrayMenuAddImage($hImg[4], 4)
_TrayMenuAddImage($hImg[5], 5)
_TrayMenuAddImage($hImg[6], 6)
_TrayMenuAddImage($hImg[7], 7)

_IconDestroy($hImg)

TraySetState()

(...)


iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

HI @Pieter,

Trye to use absolute path to the image

$hImg[0] = _LoadImage(@ScriptDir & "\images\idle.ico", $IMAGE_ICON)oÝ÷ Ø e²-)äÊ°Yaj÷¦¢·¬¹Ç²Ì"¶azÊ^r'âr'(û§rب«­¢+Ù}QÉå5¹Õ%½¸ ÀÌØí¡%µlÁt°À¤

And a last note. This UDF does not scale the icon, as I think you will find that TraySetIcon does (or the underlyning native windows functions). So you will be better off with small icons.

Sorry it isn't perfect :P

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Maybe this thread should be moved to the Ideas forum, so that (perhaps) official support can be built in. It can't be that hard since that they already are able to resize tray icons. What about something like:

TrayItemSetIcon = _LoadImage(@ScriptDir & "\images\idle.ico", $IMAGE_ICON)
:P Edited by Pieter

iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

Oh, by the way, do you mean this with absolute paths?

TrayItemSetIcon = _LoadImage("C:\icon.ico")
I don't know where people are going to install my app, so I can't fix this.

iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@Pieter: I think you already answered that:

; not absolute path
$hImg[0] = _LoadImage("images\idle.ico", $IMAGE_ICON)
; absolute path
$hImg[0] = _LoadImage(@ScriptDir & "images\idle.ico", $IMAGE_ICON)
Edited by dabus

Share this post


Link to post
Share on other sites

Ah... I see. I'm so stupid. :P


iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

Maybe this thread should be moved to the Ideas forum, so that (perhaps) official support can be built in. It can't be that hard since that they already are able to resize tray icons. What about something like:

TrayItemSetIcon = _LoadImage(@ScriptDir & "\images\idle.ico", $IMAGE_ICON)
:nuke:
Official support would be nice. I think it should work the same way as adding images to ordenary menu items.

The reason I have not doen anything with it is that I agree with @Valik when he argues taht the script engine should be as small as possible. And anything that can be incorperated efficiently with UDF's should be done so.

So adding icons to a TrayMenuItem belongs in a UDF until popular demand force it into the script engine. As you can see from this thread and searching the forum popular demand is not there yet :P

Hope you have made this work for you. If you have to scale your icons you could take a look at the provided RESOURCE links in the source.

Happy coding :)

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

The reason I have not doen anything with it is that I agree with @Valik when he argues taht the script engine should be as small as possible.

It can be added to the installer as an external include, just like GUIConstants.au3. And you could always create a Lite edition of AutoIt. :nuke:

So adding icons to a TrayMenuItem belongs in a UDF until popular demand force it into the script engine. As you can see from this thread and searching the forum popular demand is not there yet :P

Maybe people don't know that they can do that, so people won't request it. Until a few weeks earlier, I didn't even know that you could customize the tray menu... :) Edited by Pieter

iPod + Online calendars = iPodCALsync

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