Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Menu icons
#1
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
Code:
Select All      Help
SetThreadMenuIcons "1=10 3=1 4=2" "$qm$\il_qm.bmp" 1


Attached Files
.qml   Menu icons.qml (Size: 9.44 KB / Downloads: 899)
Reply
#2
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.
Reply
#3
For submenus, you need to set item id. PopupMenu does not set submenu item ids. Use ShowMenu.
Reply
#4
You can add icon handles to an imagelist and pass it to SetThreadMenuIcons.

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

int hi
hi=GetWindowIcon(win("Quick"))
ImageList_ReplaceIcon(il -1 hi)
DestroyIcon(hi)
hi=GetWindowIcon(win("Firefox"))
ImageList_ReplaceIcon(il -1 hi)
DestroyIcon(hi)

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

ShowMenu("100 a[]>101 b[]102 c[]<")
Reply
#5
Updated. Now draws custom checkboxes for checked items with icons.
Reply
#6
Small bug with submenu icon being misplaced:
Macro MenuPopup help
Code:
Select All      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.

;EXAMPLES

#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
Reply
#7
Thanks, now fixed.
Reply
#8
Sorry to kick this up.

Does SetThreadMenuIcons also work in compiled exe?

I have the following code:

Macro Macro4
Code:
Select All      Help
POINT p
int px(xm) py(ym)
p.x=px
p.y=py
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)?
Reply
#9
$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"
Reply
#10
AH! That explains it!!

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

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

Or:

Macro Macro2916
Code:
Select All      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
Reply
#14
This would combine with the single line of code suggested at the top?
Code:
Select All      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
Reply
#15
I think I am starting to understand. But now like so
Code:
Select All      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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)