Page 1 of 1
menu.SetIcon too slow
Posted: 28 Jan 2021, 01:26
by quaritexa
My script creates several dozen menus with png icons. The total number of created icons is about 200. Creation of an icon (menu.SetIcon) in each menu item takes about 15 ms. As a result, the script starts in about 3 seconds. How can this process be accelerated?
Re: menu.SetIcon too slow
Posted: 28 Jan 2021, 12:01
by kczx3
Hmmmm. Well, I don't have that many diferent png files to use. Just using icons from a Dll doesn't seem to take nearly as long as you're reporting though. Maybe its the process of converting the png to an acceptable format to be used with a menu that takes a while. What if you populated the menu with the icons via threads using
SetTimer?
Code: Select all
mainMenu := menu.new()
cb := Func("cb")
time := A_TickCount
loop (300) {
name := "Menu #" . A_Index
mainMenu.add(name, cb)
mainMenu.setIcon(name, "Shell32.dll", A_Index)
}
msgbox("Started! - " (A_TickCount - time) / 1000)
mainMenu.show()
cb(*) {
tooltip("some random callback")
}
Re: menu.SetIcon too slow
Posted: 28 Jan 2021, 12:15
by kczx3
This is quite crude but demonstrates my thinking using threads.
Code: Select all
global menuReady := false
mainMenu := menu.new()
cb := Func("cb")
addItem := Func("addMenuItem").bind(mainMenu, 300, cb)
SetTimer(addItem, 1)
ToolTip("Script is executing!")
#HotIf menuReady
#F10::{
global mainMenu
mainMenu.show()
}
cb(*) {
tooltip("some random callback")
}
addMenuItem(gMenu, maxItems, cb) {
global menuReady
static currCount := 1
if (currCount == maxItems) {
SetTimer(, 0) ; we're done, mark timer for deletion
menuReady := true
ToolTip("Ready!")
return
}
name := "Menu #" . currCount
gMenu.add(name, cb)
gMenu.setIcon(name, "Shell32.dll", currCount)
currCount++
}