Jump to content



Photo

Traymenuex Udf. Add Icon Or Bmp To Trayitem


  • Please log in to reply
28 replies to this topic

#1 Uten

Uten

    stupid is as stupid does..

  • Active Members
  • PipPipPipPipPipPip
  • 1,987 posts

Posted 30 March 2006 - 01:53 AM

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.

Attached Files


Edited by Uten, 17 October 2007 - 11:21 AM.






#2 rakudave

rakudave

    Polymath

  • Active Members
  • PipPipPipPip
  • 245 posts

Posted 31 March 2006 - 11:43 AM

nice, i like it...

#3 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 24 August 2006 - 02:51 PM

The script doesn't work here. It quits immediately. Why?
iPod + Online calendars = iPodCALsync

#4 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 24 August 2006 - 03:20 PM

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.

AutoIt         
#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.


#5 Xenobiologist

Xenobiologist

    Xx Code~Mega xX

  • MVPs
  • 4,729 posts

Posted 24 August 2006 - 09:14 PM

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 *newYahtzee 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

#6 WTS

WTS

    Polymath

  • Active Members
  • PipPipPipPip
  • 247 posts

Posted 24 August 2006 - 10:03 PM

nice job..

are you still working on it uten?

#7 Uten

Uten

    stupid is as stupid does..

  • Active Members
  • PipPipPipPipPipPip
  • 1,987 posts

Posted 24 August 2006 - 10:39 PM

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 ...

#8 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 25 August 2006 - 08:42 AM

So I need to include the file? But how do I create a new menu item with icon then?
iPod + Online calendars = iPodCALsync

#9 Uten

Uten

    stupid is as stupid does..

  • Active Members
  • PipPipPipPipPipPip
  • 1,987 posts

Posted 25 August 2006 - 01:13 PM

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.

#10 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 26 August 2006 - 07:30 AM

Oh, I forgot to read that. Sorry... *shame*
iPod + Online calendars = iPodCALsync

#11 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 26 August 2006 - 07:40 AM

AutoIt         
(...) ; 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, 26 August 2006 - 07:59 AM.

iPod + Online calendars = iPodCALsync

#12 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 26 August 2006 - 08:06 AM

What's wrong here?
AutoIt         
(...) ; 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

#13 Uten

Uten

    stupid is as stupid does..

  • Active Members
  • PipPipPipPipPipPip
  • 1,987 posts

Posted 26 August 2006 - 07:42 PM

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

#14 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 27 August 2006 - 06:30 AM

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, 27 August 2006 - 06:38 AM.

iPod + Online calendars = iPodCALsync

#15 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 27 August 2006 - 06:39 AM

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

#16 dabus

dabus

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 405 posts

Posted 27 August 2006 - 11:52 AM

@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, 27 August 2006 - 11:54 AM.


#17 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 27 August 2006 - 12:23 PM

Ah... I see. I'm so stupid. :P
iPod + Online calendars = iPodCALsync

#18 Uten

Uten

    stupid is as stupid does..

  • Active Members
  • PipPipPipPipPipPip
  • 1,987 posts

Posted 27 August 2006 - 12:58 PM

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 :)

#19 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 28 August 2006 - 07:32 AM

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, 28 August 2006 - 07:49 AM.

iPod + Online calendars = iPodCALsync

#20 Pieter

Pieter

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 28 August 2006 - 07:50 AM

Done! (I mean the menu of course)

http://img219.imageshack.us/img219/6364/traykc0.png

Edited by Pieter, 28 August 2006 - 07:51 AM.

iPod + Online calendars = iPodCALsync




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users