Jump to content

_GUIImageList_AddIcon, TraySetIcon


Recommended Posts

I got part of this code out of the forum (did about 20 searches and could not get any results) and modified it so that the icons would be loaded as part of the program, but I am only getting 0.ico to work; why?

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt("TrayAutoPause", 0)
Global Const $VK_NUMLOCK = 0x90
Global Const $VK_SCROLL = 0x91
Global Const $VK_CAPITAL = 0x14

Global $Apps="KeyState 1.1"
Global $hImage, $keystate
main()
Func main()
; Add icons
$hImage = _GUIImageList_Create(32, 32)
_GUIImageList_AddIcon($hImage, @ScriptDir & "0.ico")
_GUIImageList_AddIcon($hImage, @ScriptDir & "1.ico")
_GUIImageList_AddIcon($hImage, @ScriptDir & "2.ico")
_GUIImageList_AddIcon($hImage, @ScriptDir & "3.ico")

While 1
    toggleKeys()
    sleep(100)
WEnd
EndFunc

Func toggleKeys()
$keystate=0

If GetCapsLock() <>0 Then
$keystate= $keystate  + 1
EndIf

If getNumLock() <> 0 then
$keystate= $keystate  + 2
EndIf

Select
Case $keystate = 1
  TraySetIcon($hImage, 0)
Case $keystate = 2
  TraySetIcon($hImage, 1)
Case $keystate = 3
  TraySetIcon($hImage, 2)
Case $keystate = 4
  TraySetIcon($hImage, 3)
Case Else
  TraySetIcon("0.ico")
EndSelect
EndFunc

;Code from gafrost ==> http://www.autoitscript.com/forum/index.php?showtopic=12056
Func GetCapsLock()
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_CAPITAL)
    Return $ret[0]
EndFunc

Func GetNumLock()
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_NUMLOCK)
    Return $ret[0]
EndFunc
Link to post
Share on other sites

Add an index for each icon : _GUIImageList_AddIcon($hImage, @ScriptDir & "0.ico", 0 )

This is what I have:

$hImage = _GUIImageList_Create(32, 32)
_GUIImageList_AddIcon($hImage, @ScriptDir & "0.ico", 0)
_GUIImageList_AddIcon($hImage, @ScriptDir & "1.ico", 1)
_GUIImageList_AddIcon($hImage, @ScriptDir & "2.ico", 2)
_GUIImageList_AddIcon($hImage, @ScriptDir & "3.ico", 3)

I looked at "@Error" to check to see if the icons are loading, but I haven't figured out how to use it.

Link to post
Share on other sites

For me it works

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Global $hGui, $listview, $hImage
Global $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

$hGui = GUICreate("ImageList AddIcon", 400, 300)
$listview = _GUICtrlListView_Create($hGui, "", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
GUISetState()

$hImage = _GUIImageList_Create(32, 32)
_GUIImageList_AddIcon($hImage, @ScriptDir & "0.ico", 0 )
_GUIImageList_AddIcon($hImage, @ScriptDir & "1.ico", 0)
_GUIImageList_AddIcon($hImage, @ScriptDir & "2.ico", 0)
_GUIImageList_AddIcon($hImage, @ScriptDir & "3.ico", 0)

_GUICtrlListView_SetImageList($listview, $hImage, 1)
_GUICtrlListView_AddColumn($listview, "Column 1", 120)
_GUICtrlListView_AddItem($listview, "Row 1: Col 1", 0)
_GUICtrlListView_AddItem($listview, "Row 2: Col 1", 1)
_GUICtrlListView_AddItem($listview, "Row 3: Col 1", 2)
_GUICtrlListView_AddItem($listview, "Row 4: Col 1", 3)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

Yes, and it works. How do I get from the "list" to the "tray"? :)

Something like this ?

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Global $hGui, $listview, $hImage, $_indexOld
Global $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

$hGui = GUICreate("ImageList AddIcon", 400, 300)
$listview = _GUICtrlListView_Create($hGui, "", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
GUISetState()

$hImage = _GUIImageList_Create(32, 32)
_GUIImageList_AddIcon($hImage, @ScriptDir & "0.ico", 0 )
_GUIImageList_AddIcon($hImage, @ScriptDir & "1.ico", 0)
_GUIImageList_AddIcon($hImage, @ScriptDir & "2.ico", 0)
_GUIImageList_AddIcon($hImage, @ScriptDir & "3.ico", 0)

_GUICtrlListView_SetImageList($listview, $hImage, 1)
_GUICtrlListView_AddColumn($listview, "Column 1", 120)
_GUICtrlListView_AddItem($listview, "Row 1: Col 1", 0)
_GUICtrlListView_AddItem($listview, "Row 2: Col 1", 1)
_GUICtrlListView_AddItem($listview, "Row 3: Col 1", 2)
_GUICtrlListView_AddItem($listview, "Row 4: Col 1", 3)

Do
$_index = _GUICtrlListView_GetSelectedIndices($ListView)
if $_index <> $_indexOld Then
ConsoleWrite ( "$_index : " & $_index & @Crlf )
TraySetIcon ( @ScriptDir & "" & $_index & ".ico", 0)
$_indexOld= $_index
EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

wakillon, I tried it and it loaded the SciTE icon into the tray which is what I have been getting. This is what I don't understand, when I use the "external" icon, everything is fine, but when I try to load them in the program, it fails; they seem to display everywhere but in the tray - frustrating.

Link to post
Share on other sites

wakillon, I tried it and it loaded the SciTE icon into the tray which is what I have been getting. This is what I don't understand, when I use the "external" icon, everything is fine, but when I try to load them in the program, it fails; they seem to display everywhere but in the tray - frustrating.

How do you load them in the program ?

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

it's a bit confuse !

when you said load them to the program, it's for integrate them to your executable or only "read" an external executable icon ?

Let be back up: I want to load the icons and compile them into the executable.

I think I may have misunderstood the hellp file and I know that in most situations the binary file must be loaded - if this is true, is there a post somewhere that I can follow? The other issue I will run into is how to get the icon out of the binary (if this is how it works) without the header info. Like I said, I am in virgin territory.

Link to post
Share on other sites

Let be back up: I want to load the icons and compile them into the executable.

I think I may have misunderstood the hellp file and I know that in most situations the binary file must be loaded - if this is true, is there a post somewhere that I can follow? The other issue I will run into is how to get the icon out of the binary (if this is how it works) without the header info. Like I said, I am in virgin territory.

Ok, so why not use fileinstall ?

FileInstall ( 'C:0.ico', @ScriptDir & '0.ico' )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

Ok, so why not use fileinstall ?

FileInstall ( 'C:0.ico', @ScriptDir & '0.ico' )

Does this not copy the icon from one location to another as a file rather than insert it into the program? I am trying to prevent the icon from being altered. I noticed in AHK they use "join" with a binary to accomplish this. Edited by delray
Link to post
Share on other sites

Why not have a look at this >> http://www.autoitscript.com/autoit3/scite/docs/AutoIt3Wrapper.htm and the section labelled Adding Extra Ico's to the program resources. So instead of using 0.ico you use -5 or -6 depending on the state etc...

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...