Sign in to follow this  
Followers 0
this-is-me

Problem with _WinAPI_AddIconOverlay and small icons

7 posts in this topic

I am trying to add an overlay to a small icon. I am wanting to add the UAC overlay to the bottom right of the icon as seen in the below example:

post-1277-0-63877700-1393022655_thumb.jp

However, with the code I have, I get this result:

post-1277-0-17181000-1393022668_thumb.jp

My (basic) example code:

#include <GuiMenu.au3>
#include <WinAPIGdi.au3>
#include <WinAPIRes.au3>

#NoTrayIcon
Opt('TrayMenuMode', 3)

Local $hMenu = TrayItemGetHandle(0)
Local $Options = TrayCreateItem('Command Prompt Here (Administrator)')
TrayCreateItem('')
Local $Exit = TrayCreateItem('Exit')

Local $hIconCmd = _WinAPI_ExtractIcon("cmd.exe", 0, True)
Local $hIconUAC = _WinAPI_ExtractIcon("imageres.dll", 1, True)
Local $hNewIcon = _WinAPI_AddIconOverlay($hIconCmd, $hIconUAC)

_GUICtrlMenu_SetItemBmp($hMenu, 0, _WinAPI_Create32BitHBITMAP($hNewIcon, 1, 1))

TraySetState()

TrayTip("Information", "Check out tray menu", 30)


Do
Until TrayGetMsg() = $Exit

Is this a bug in _WinAPI_AddIconOverlay or is it a problem with the way I am calling the function?


Who else would I be?

Share this post


Link to post
Share on other sites

This is not a bug in _WinAPI_AddIconOverlay. _WinAPI_AddIconOverlay can only add an existing overlay icon to an icon. E.g. icon #154 in imageres.dll as is used in the example in the help file. It does not create new (small) overlay icons. You can see the icons in imageres.dll here.

As far as I know this UAC shield overlay icon is handled different than other overlay icons. E.g. it's not included in imageres.dll as the other. This also means that you can't use _WinAPI_AddIconOverlay to add this overlay icon.

A workaround is to replace an existing overlay icon in the system image list with your own overlay icon. Or replace an existing overlay icon in imageres.dll with your own.

Share this post


Link to post
Share on other sites

Thanks for the detailed explanation. I understand completely now, and will go about making the UAC icon into an overlay myself. Thanks again for your help.


Who else would I be?

Share this post


Link to post
Share on other sites

For anyone else who would like to use it, I have created a UAC overlay icon that can be used.
UACOverlay.ico


Who else would I be?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this line instead using your icon file:

Local $hIconUAC = _WinAPI_LoadImage(0, @ScriptDir & "\UACOverlay.ico", $IMAGE_ICON, 0, 0, $LR_LOADFROMFILE)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

UEZ, Is _WinAPI_LoadImage generally preferred over _WinAPI_ExtractIcon when the file is an icon only? If so, why?

EDIT: Nevermind, I see that it has to do with the size of an icon on a menu, in general. _WinAPI_LoadImage would allow a person to respect the user's choice for icon size in menus, am I correct?

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

Well, there a lot of ways to extract/load an icon from different sources. Some of the functions have different purposes than others.

I personally prefer to use GDI+ rather than GDI.

_WinAPI_LoadImage() is more flexible than _WinAPI_ExtractIcon() loading graphic files but important is the result.

 

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0