Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Menu icons
Adds icons to all menus in current thread.
Works with menu bar menus, popup menus (ShowMenu), and with system menu.

Need only single line of code, like this:

Macro Menu icons test
Copy      Help
SetThreadMenuIcons "1=10 3=1 4=2" "$qm$\il_qm.bmp" 1

Attached Files
.qml   Menu icons.qml (Size: 9.44 KB / Downloads: 1,235)
This is wonderful, thanks!
It's working well so far, except unable to set icons for submenu items (i.e. items that open submenus).
Another thing: if an item is "checked", sometimes the checkmark can be seen underneath the menu icon.
Also, would like to be able to use icon handles so that GetWindowIcon can be used.
Thanks again.
For submenus, you need to set item id. PopupMenu does not set submenu item ids. Use ShowMenu.
You can add icon handles to an imagelist and pass it to SetThreadMenuIcons.

Macro Macro1275
Copy      Help
__ImageList- il
;il.Load("bmp file created with qm imagelist editor")
il=ImageList_Create(16 16 ILC_MASK|ILC_COLOR32 0 8)

int hi
ImageList_ReplaceIcon(il -1 hi)
ImageList_ReplaceIcon(il -1 hi)

SetThreadMenuIcons "100=0 101=0 102=1" +il 2

ShowMenu("100 a[]>101 b[]102 c[]<")
Updated. Now draws custom checkboxes for checked items with icons.
Small bug with submenu icon being misplaced:
Macro MenuPopup help
Copy      Help
;Creates and shows a popup menu.
;Also has functions to disable, check items, etc.
;A MenuPopup variable also can be used as menu handle with Windows API menu functions.


#compile "__MenuPopup"

str s=
;1 Text (1 is item id; Text is label)
;2 Use - line for separator
;>3 Submenu
;,15 Tabs at the beginning are ignored
;,16 Tab in the middle    right-aligns text
;25 Use | line for vertical break
;>30 Another submenu (with id)
;,31 &Ampersand (&&) underlines the character
;,-32 (separator with id)
;,Menu item id is optional
__ImageList- il=ImageList_Create(16 16 ILC_MASK|ILC_COLOR32 0 8)
_i=GetWindowIcon(win("Quick")); ImageList_ReplaceIcon(il -1 _i); DestroyIcon(_i)
_i=GetWindowIcon(win("Firefox")); ImageList_ReplaceIcon(il -1 _i); DestroyIcon(_i)
SetThreadMenuIcons "1=0 2=1 30=0" +il 2

MenuPopup x.AddItems(s)
int i=x.Show
out i
Thanks, now fixed.
Sorry to kick this up.

Does SetThreadMenuIcons also work in compiled exe?

I have the following code:

Macro Macro4
Copy      Help
int px(xm) py(ym)
SetThreadMenuIcons "2=1" "$qm$\il_qm.bmp" 1
int i=ShowMenu("1 A[]2 B" 0 p)
out i

(I got part of the above code from other topic)

At mouse pointer location a menu pops-up and the "B" item shows an Icon when I run this from QM.
But the compiled version doesn't show an icon.

Is there something that must be set in the 'make exe' dialog window?
Or must I hardcode the path to the iconfile somwhere in the above code (Helpfile > Make exe > Resources)?
$qm$ in Macro.exe is folder of Macro.exe, not of qm.exe where the file is.

Can add to resources.
":1 $qm$\il_qm.bmp"
AH! That explains it!!

Can add to resources.
":1 $qm$\il_qm.bmp"
Hi, I seem to understand the way to add images to the menus. But how do you tell the buttons to run a macro?
I usually use sel:

Macro Macro2916
Copy      Help
int i=ShowMenu("1 macro1[]2 macro2")
sel i
,case 0 ret
,case 1 out "macro1"
,case 2 out "macro2"


Macro Macro2916
Copy      Help
str m=
;1 macro1
;2 macro2

int i=ShowMenu(m)
if(i=0) ret
str s.getl(m i-1); s.gett(s 1)
mac s
This would combine with the single line of code suggested at the top?
Copy      Help
SetThreadMenuIcons "1=2 2=11 "$qm$\il_qm.bmp" 1

int i=ShowMenu("1 macro1[]2 macro2")
sel i
,case 0 ret
,case 1 out "macro1"
,case 2 out "macro2"
When I put my macro name in place of macro1 or macro2 all I get is text in output window. I am expecting it run the macro? Thanks
I think I am starting to understand. But now like so
Copy      Help
SetThreadMenuIcons "1=2 2=11" "$qm$\il_qm.bmp" 1

int i=ShowMenu("1 Notepad++[]2 Camtasia2")
sel i
,case 0 ret
,case 1 mac "Notepad++"
,case 2 mac "Camtasia2"
I get a warning this should not run from macro. Do I need to turn it into a function? Thanks
... Update! Turning into function works great. Does this garbage collect on its own or is there somethings to be careful of? Thanks

Forum Jump:

Users browsing this thread: 1 Guest(s)