Menu icons

Functions, classes, components, etc. Only high quality content.

Menu icons

Postby Gintaras on Wed Sep 30, 2009 6:25 pm

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     ?
SetThreadMenuIcons "1=10 3=1 4=2" "$qm$\il_qm.bmp" 1

Attachments
Menu icons.qml
(9.44 KiB) Downloaded 875 times
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Menu icons

Postby canderoc on Thu Oct 01, 2009 8:00 pm

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.
canderoc
 
Posts: 81
Joined: Thu Jun 12, 2008 7:46 pm

Re: Menu icons

Postby Gintaras on Thu Oct 01, 2009 8:04 pm

For submenus, you need to set item id. PopupMenu does not set submenu item ids. Use ShowMenu.
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Menu icons

Postby Gintaras on Thu Oct 01, 2009 8:15 pm

You can add icon handles to an imagelist and pass it to SetThreadMenuIcons.

Macro Macro1275     ?
__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[]<")

Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Menu icons

Postby Gintaras on Fri Oct 02, 2009 9:59 am

Updated. Now draws custom checkboxes for checked items with icons.
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Menu icons

Postby canderoc on Fri Oct 02, 2009 4:39 pm

Small bug with submenu icon being misplaced:
Macro MenuPopup 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

canderoc
 
Posts: 81
Joined: Thu Jun 12, 2008 7:46 pm

Re: Menu icons

Postby Gintaras on Fri Oct 02, 2009 5:49 pm

Thanks, now fixed.
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Menu icons

Postby r0n on Wed Aug 07, 2013 4:00 pm

Sorry to kick this up.

Does SetThreadMenuIcons also work in compiled exe?

I have the following code:

Macro Macro4     ?
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)?
r0n
Active Member
 
Posts: 495
Joined: Tue Jul 24, 2012 5:47 am

Re: Menu icons

Postby Gintaras on Wed Aug 07, 2013 4:08 pm

$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"
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Menu icons

Postby r0n on Wed Aug 07, 2013 4:27 pm

AH! That explains it!!

Thanks!
r0n
Active Member
 
Posts: 495
Joined: Tue Jul 24, 2012 5:47 am

Re: Menu icons

Postby Gintaras on Wed Aug 07, 2013 4:27 pm

Can add to resources.
":1 $qm$\il_qm.bmp"
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Menu icons

Postby pctechtv on Sun Aug 20, 2017 3:55 am

Hi, I seem to understand the way to add images to the menus. But how do you tell the buttons to run a macro?
pctechtv
 
Posts: 18
Joined: Sat Nov 10, 2012 11:10 pm

Re: Menu icons

Postby Gintaras on Sun Aug 20, 2017 4:03 am

I usually use sel:

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



Or:

Macro Macro2916     ?
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

Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Menu icons

Postby pctechtv on Sun Aug 20, 2017 4:41 am

This would combine with the single line of code suggested at the top?
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
pctechtv
 
Posts: 18
Joined: Sat Nov 10, 2012 11:10 pm

Re: Menu icons

Postby pctechtv on Sun Aug 20, 2017 4:55 am

I think I am starting to understand. But now like so

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
pctechtv
 
Posts: 18
Joined: Sat Nov 10, 2012 11:10 pm


Return to QM Extensions

Who is online

Users browsing this forum: No registered users and 2 guests

cron