Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Menu Icons v2


  • Please log in to reply
138 replies to this topic
nitrix
  • Guests
  • Last active:
  • Joined: --
Fantastic !

i tried something similar, but i must have forgotten something

thanks you so much lexikos, you made my day ;)

Alekoz
  • Members
  • 161 posts
  • Last active: Feb 17 2010 06:15 PM
  • Joined: 17 Jun 2007
this is nice
works great on my scripts with Standard Tray menu
but does it work with NoStandard menus?...and if yes how...im not that advanced at ahk so i need a little help :D
Signature oO

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

this is nice
works great on my scripts with Standard Tray menu
but does it work with NoStandard menus?...and if yes how...im not that advanced at ahk so i need a little help :D

:? :?: It works the same way... If you are referring to the test script (with icons in the tray menu) you may have to change the item numbers.

  • Guests
  • Last active:
  • Joined: --
Very good, thanks, but a little slow for my PC ( P4 1,5Ghz) and a menu with 33 items with their icons.
1st run: 9sec, 2nd run: 4+ sec)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

MI_ExtractIcon(Filename, IconNumber, IconSize)
{
; LoadImage is not used..
; ..with exe/dll files because:
; it only works with modules loaded by the current process,
; it needs the resource ordinal (which is not the same as an icon index), and
; ..with ico files because:
; it can only load the first icon (of size %IconSize%) from an .ico file.


Txh for this. I had troubles to resize exe and dll icons to other dimesnions then 16 and 32.
Posted Image

Nahusa
  • Guests
  • Last active:
  • Joined: --
Is it possible to make this work with a standard menu bar on a window? For example:

Menu, FileMenu, Add, Open, MenuHandler
Menu, FileMenu, Add, Exit, MenuHandler
Menu, MenuBar , Add, File, :FileMenu
Gui, Menu, MenuBar

Gui, Show, w100 h50
Return

MenuHandler:
{
    
}
Return

GuiEscape:
GuiClose:
{
    ExitApp
}
Return

I'd like the Open and Exit entries to have custom icons. I'm not sure if it's possible because of the requirement to use MI_ShowMenu(). Any thoughts?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
No. Icons are not supported on the menu bar, even on Vista, which does not require MI_ShowMenu(). You could try using a toolbar instead. There are a couple toolbar examples in this thread; look for "ToolbarWindow32".

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
lexikos probably didn't understand you.

You can do it. If not directly then using some workarounds...

Workaround: You can create main menu which main items launch normal menu's with icons. You then just need to position them right.
Posted Image

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Sorry, Nahusa. I didn't pay attention to the code in your post, since someone recently (today!) posted a very similar question. (Submenus of the menu bar may have icons, but not the menu bar itself.)

Workaround: You can create main menu which main items launch normal menu's with icons.

Another workaround would be to avoid owner-drawing. The only draw-back is that standard menu item bitmaps don't support transparency (except on Vista.) "Transparency" can be faked, but it doesn't look right when the item is selected. (See the "FakeAlphaTest" screenshot in my first post.)

Since the draw-backs aren't so bad, perhaps I'll write a function for it when I get time.

Edit: I added a new function (unrelated to the above workaround):

MI_EnableOwnerDrawnMenus( [ hwnd ] )
Sub-classes a window to owner-draw menu icons. This allows the menu to be shown by means other than MI_ShowMenu(). If hwnd is omitted, the function operates on the script's main window, allowing menus shown with Menu,..,Show (as well as the main window's own menus) to be owner-drawn.
Note:
[*:3hr9ea95]This function should be called only once for any given window.
[*:3hr9ea95]'hwnd' must belong to the current process. (This may not apply on Win9x.)
[*:3hr9ea95]If used on the script's main window, it breaks the "Pause Script" menu item (in either menu.)[/list]MI_SetMenuStyle() now accepts a menu name or handle. I had been using a menu name in the example script, even though it accepted only a handle. :roll:

The "fake transparency" method still has one major benefit: it works for menus external to the current process. Eventually I'll add a function for it...

Nahusa
  • Guests
  • Last active:
  • Joined: --
I appreciate the help but I'm still having trouble making it work. Should it be as simple as this?:

MI_EnableOwnerDrawnMenus() ; No hwnd specified, use script's hwnd.

Menu, FileMenu, Add, Open, MenuHandler
  MI_SetMenuItemIcon("FileMenu", 1, "shell32.dll", 4, 16)
Menu, FileMenu, Add, Exit, MenuHandler
  MI_SetMenuItemIcon("FileMenu", 2, "shell32.dll", 1, 16)

MI_SetMenuStyle("FileMenu", 0x4000000)

Menu, MenuBar , Add, File, :FileMenu
Gui, Menu, MenuBar

Gui, Show, w100 h50

Return

MenuHandler:
{
    
}
Return

GuiEscape:
GuiClose:
{
    ExitApp
}
Return


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
You need to pass the owner of the menus. In this case, the Gui.
Gui, +LastFound
MI_EnableOwnerDrawnMenus(WinExist())


Nahusa
  • Guests
  • Last active:
  • Joined: --
Ah, I was confused by the comment in lexikos' function:

if (hwnd="") {  ; Use the script's main window if hwnd was omitted.

I thought this would pass the needed hwnd automatically but, after doing some debugging, I see that the hwnd's differ. Thanks for the clarification.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
To further clarify, the main window is the window that you get when you double-click the tray icon, or use ListLines, ListVars, etc. All menus shown with Menu,..,Show are owned by the script's main window.

A menu bar and any menus it shows are owned by whichever window contains it.

Owner-draw messages are sent only to the owner of the menu.

cooler99
  • Guests
  • Last active:
  • Joined: --
Beautiful and Great!!!

Is it possible to have tooltips for each menu item "On Mouse Over"?

heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008
This is totally awesome. very handy.
since it supports .icl file there's no pain anymore to pack icons into .exe or .dll
cause every (include free) icon tools supports to make icon library (.icl)
i've added it to Function list in the Wiki.
hope this function come official soon.
Many Thanks Lexikos.

ps. btw what ItemClick label in the example stands for ?
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com