abberration Posted October 21, 2020 Share Posted October 21, 2020 (edited) Hi, everyone! I have been trying to get #AutoIt3Wrapper_Res_Icon_Add to work for over an hour and so far unsuccessfully. I tried the example script from the docs section of this website. The example script does not work for me, either. The icons are in the correct location on my computer. Does the script below work for you guys/gals? ; Add icons to the file resource table ; As no resource names are specified, they will be set automatically to 201+ #AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\au3.ico #AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\au3script_v10.ico #AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\au3script_v9.ico #AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\filetype-blank.ico #include <ButtonConstants.au3> ; Create the GUI $hGUI = GUICreate("Demo icon resources") $cButton = GUICtrlCreateButton("", 10, 10, 40, 40, $BS_ICON) $cLabel = GUICtrlCreateLabel("", 70, 25, 200, 20) GUISetState(@SW_SHOW, $hGUI) ; Now run through the added icons in the resource table For $x = 201 To 204 ; Change the tray icon $rc1 = TraySetIcon(@ScriptFullPath, $x) ; Change the icon in the button $rc2 = GUICtrlSetImage($cButton, @ScriptFullPath, $x) GUICtrlSetData($cLabel, "Icon Name: " & $x) TrayTip("Added icon: " & $x, "TraySetIcon rc: " & $rc1 & @CRLF & "GUICtrlSetImage rc: " & $rc2, 3) ; Allow time for icon to be seen Sleep(5000) Next ; Delete the GUI GUIDelete($hGUI) On my test project (not the above code), I used reshacker and saw the icon I want to use is icon group 201. Setting the image to 201 did not work. Then, I set the name to exit.ico with the wrapper and now it does not have 201 in reshacker, now it uses the name EXIT.ICO instead. So, I used the following, which also did not work: GUICtrlSetImage($MenuItemExit, @ScriptFullPath, "EXIT.ICO") By the way, this is for a menu item. Perhaps I need to use something other than GuiCtrlSetImage? Thanks for any advice! Simplified version of my script: #AutoIt3Wrapper_Res_Icon_Add=Y:\Exit.ico, exit.ico #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 379, 202) $MenuItem1 = GUICtrlCreateMenu("File") $MenuItemExit = GUICtrlCreateMenuItem("Exit", $MenuItem1) GUICtrlSetImage($MenuItemExit, @ScriptFullPath, "EXIT.ICO") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited October 21, 2020 by abberration Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
TheXman Posted October 21, 2020 Share Posted October 21, 2020 (edited) Specifically, the second to last post. The function referenced in the post is now in the WinAPIGdi.au3 UDF which is in the AutoIt Include folder. Edited October 21, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Zedna Posted October 22, 2020 Share Posted October 22, 2020 (edited) As about using icons from resources, look here Edited October 22, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
abberration Posted October 22, 2020 Author Share Posted October 22, 2020 (edited) TheXman and Zedna, thank you for your suggestions. I have been playing with the ideas, but have run into a couple problems. TheXman's suggestion uses _WinAPI_Create32BitHBITMAP() that requires the handle of the source icon. I do not know how to get the handle of a wrapper added icon. Zedna's suggestion seems to use _GUIImageList_Create and _GUIImageList_AddIcon, which I have successfully used before in the past, but that was with a ListView. I decided to try using the Base64 encoder to hard code the icon into the script. I have used this before in the past with a .png, but for this project, I don't see anything like (fictional -> _GuiCtrlMenu_SetItemIcon) to set the icon and I could not find a way to do it. I really do appreciate the feedback, but I found a simpler solution. If I cannot get a self-contained code solution, I have created a .dll with the icons (thanks, @Tlem in the French AutoIt forum! So awesome... Link) and can use ModernMenuRaw.au3 to apply them. I will continue researching ways to incorporate icons without external files, but if I cannot figure it out, the following code is working for me and is a good solution. I don't like having a lot of stray files and this reduces them to only 2 extra ones. Thanks again for everyone's help. If NOT FileExists(@ScriptDir & "\ModernMenuRaw.au3") Then ; This file must exist on compile but not on execute. FileInstall("Y:\DL\AutoIt Projects\Easy Mp3\menu\ModernMenuRaw.au3", "ModernMenuRaw.au3") EndIf #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ModernMenuRaw.au3> $Form1 = GUICreate("Form1", 379, 202) $MenuItem1 = GUICtrlCreateMenu("File") $MenuItemExit = _GUICtrlCreateODMenuItem("Exit", $MenuItem1, "resources.dll", -3) ; If resources.dll does not exist, no errors - just no icons. GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edit: In the past, I have successfully incorporated a huge UDF into a script without having to do a #include, and if I have to, I will do that with ModernMenuRaw.au3 - and if I do so, I will definitely give 100% credit to Holger for the code. I will also give credit to anyone else that contributes code or functionality that helps my project. Edited October 22, 2020 by abberration Added recognition to Holger for his GUI/Tray Menu UDF and pledge to do the same for anyone else who contributes to my project's success. Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
TheXman Posted October 23, 2020 Share Posted October 23, 2020 (edited) On 10/22/2020 at 5:52 PM, abberration said: TheXman's suggestion uses _WinAPI_Create32BitHBITMAP() that requires the handle of the source icon. I do not know how to get the handle of a wrapper added icon. The compiled example below does not use any external ico files. They're all embedded in the the executable's resource data, like your original example. You will notice that the example is almost exactly like the one I referred you to. The only difference is that I refer to the embedded icons by their resource IDs in the exe's resource data. Note: You will most likely need to change the path of the AutoIt ico files and recompile the example. You MUST compile the example to see the embedded icons, you will not see the ico images by running the script in the IDE. expandcollapse popup;NOTE: To see the embedded icons, the script MUST BE COMPILED. #NoTrayIcon #AutoIt3Wrapper_Res_Icon_Add="C:\AutoIt3\Icons\MyAutoIt3_Red.ico" ;resource id will be -201 #AutoIt3Wrapper_Res_Icon_Add="C:\AutoIt3\Icons\MyAutoIt3_Blue.ico" ;resource id will be -202 #AutoIt3Wrapper_Res_Icon_Add="C:\AutoIt3\Icons\MyAutoIt3_Green.ico" ;resource id will be -203 #include <GUIMenu.au3> #include <Constants.au3> #include <WinAPIGdi.au3> #include <WinAPIShellEx.au3> #include <WinAPISys.au3> Opt('TrayMenuMode', 3) example() Func example() ;Build tray menu Local $hMenu = TrayItemGetHandle(0) Local $iRed = TrayCreateItem('Red Item') Local $iBlue = TrayCreateItem('Blue Item') Local $iGreen = TrayCreateItem('Green Item') TrayCreateItem('') Local $idExit = TrayCreateItem('Exit') ;Assign ico images to the tray menu items _GUICtrlMenu_SetItemBmp($hMenu, 0, _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@ScriptFullPath, -201, 16, 16), 1, 1)) _GUICtrlMenu_SetItemBmp($hMenu, 1, _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@ScriptFullPath, -202, 16, 16), 1, 1)) _GUICtrlMenu_SetItemBmp($hMenu, 2, _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@ScriptFullPath, -203, 16, 16), 1, 1)) TraySetState() Do Until TrayGetMsg() = $idExit EndFunc On 10/22/2020 at 5:52 PM, abberration said: I will also give credit to anyone else that contributes code or functionality that helps my project. For the record, there's no need to give me any credit for helping you with your project. If you do, I'm okay with it, but it is not something that I seek. I don't help other to get any sort of credit or "likes". When I help others it is because I choose to and because helping others helps me. All I look for is a simple "thank you". Edited February 1, 2021 by TheXman abberration 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
abberration Posted October 23, 2020 Author Share Posted October 23, 2020 TheXman, Thank you for the code. _WinAPI_ShellExtractIcon was the missing link that I couldn't figure out. I also discovered something else that might help others in the future... If I right-click the script and go to "Compile Script", it does not show the icons. I had to use "Compile with Options", which has the Res Add Files tab. I tried a lot of stuff these past couple days and a lot of my testing wasn't using Compile with Options. I wonder if any of my attempt failed because of that. Now that I'm on the right path, I will look at incorporating this again. As for giving credit, I just like to do so because it shows appreciation for the help you and others give. I understand not desiring it, I am the same way. On another note, the last code I posted was for others looking for solutions in the future. I have seen many posts where the person had the exact problem I was having and their last post was simply "nevermind, I found a solution". I don't like to do that. I will try to always post my solution. Thanks again for your help. Great code, I will add it to my own personal snippets folder. Cheers! 🥂 Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
TheXman Posted October 23, 2020 Share Posted October 23, 2020 You're welcome! I'm glad that you were able to get it all sorted out. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now