ZDS Posted March 26, 2015 Posted March 26, 2015 (edited) Bonjour, Hello, My name is Glass Joe ! [FYI, I'm under Windows 7 Pro & Windows 8.1 Family Edition] I based my code on the WinSetIcon function brought to me by Mikell on the french AutoIt forum ( here is the [link] ). This is the example code I used (with the _WinAPI_LoadImage function in order to force the icon size) : #include <WinAPI.au3> ShellExecute(StringRegExpReplace(@AutoItExe, '(.+)\\[^\\]+', "$1") & "\AutoIt.chm") Do Sleep(10) Until WinExists("AutoIt Help") $handle = WinGetHandle("AutoIt Help") WinSetIcon($handle, @ScriptDir&"\Icone.ico") Func WinSetIcon($hwnd, $file) Local $icon = _WinAPI_LoadImage(0, $file, $IMAGE_ICON, 32, 32, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION)) If Not $icon Then Return False _SendMessage($handle, 0x0080, 1, $icon) ; $WM_SETICON = 0x0080 Sleep(200) ; [[Fix]] _WinAPI_DestroyIcon($icon) EndFunc And this is the screenshot concerning my problem :http://www.autoitscript.fr/forum/download/file.php?id=3612&mode=view As you can see, the icon I created has several sizes : 48x48, 32x32 and 16x16. All my taskbar icons are 32x32, but when the code above is executed, the icon is pixellated. The one in the upperleft corner of the window is correct, but it's the one is the taskbar that matters to me. Could you help me please !? Thanks in advance for your help, and see you soon ! PS: When using a single-sized icon 48/32/16, I've got the same result : pixellated. PS2: The green arrow icon in Mikell's example is also pixellated on each computer I used. Attachment: The icon used with this sample code EDIT: Problem solved, see the line [[Fix]] in the code Icone.ico Edited April 2, 2015 by ZDS
willichan Posted March 26, 2015 Posted March 26, 2015 (edited) When viewed at a normal 100% view, I don't see any pixelation. I only see pixelation when zooming in. That is to be expected. Your screenshot appears to be the same. Am I missing what the problem is? Edited March 26, 2015 by willichan My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash
ZDS Posted March 26, 2015 Author Posted March 26, 2015 (edited) I think you missed the problem : The icon in the taskbar at the bottom of the screen is pixellated (but when I create a GUI with GUICreate and GUISetIcon, there is not pixellisation; only when I set a new icon on a not-AutoIt window). Please zoom in to see properly the icon issue : Edited March 26, 2015 by ZDS
Chimaera Posted March 27, 2015 Posted March 27, 2015 Have you tried making it at 128x128 ? A lot of windows icons have that size, then when its reduced by the screen it may hold its quality better? Just a guess If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices()
ZDS Posted March 27, 2015 Author Posted March 27, 2015 (edited) Yes I did (even with 256x256), the icon is set like a 16x16 in the taskbar anyway. Edited March 27, 2015 by ZDS
MyEarth Posted March 27, 2015 Posted March 27, 2015 (edited) Next time search before post there is another thread with a possible solution and the same subject: Edited March 27, 2015 by MyEarth
ZDS Posted April 1, 2015 Author Posted April 1, 2015 (edited) @MyEarth : Next time, try to read what I took the trouble to write ^^ I searched, and my code is based on the very same code from Mikell (the one in your link, see the first line of the code ; Author: Mikell ). Also, this example in your link has the same result : pixellated Please, is there anyone with an idea of where the problem is? Edited April 1, 2015 by ZDS
willichan Posted April 1, 2015 Posted April 1, 2015 (edited) It looks like you are specifying that the image resource shoudl be 32x32. What happens if you changeLocal $icon = _WinAPI_LoadImage(0, $file, $IMAGE_ICON, 32, 32, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION))toLocal $icon = _WinAPI_LoadImage(0, $file, $IMAGE_ICON, 0, 0, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION))---edit---You also need to set the small icon image as well. Try this#include <WinAPI.au3> ShellExecute(StringRegExpReplace(@AutoItExe, '(.+)\\[^\\]+', "$1") & "\AutoIt.chm") Do Sleep(10) Until WinExists("AutoIt Help") $handle = WinGetHandle("AutoIt Help") WinSetIcon($handle, @ScriptDir&"\Icone.ico") Func WinSetIcon($hwnd, $file) Local $icon = _WinAPI_LoadImage(0, $file, $IMAGE_ICON, 0, 0, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION)) If Not $icon Then Return False _SendMessage($hwnd, 0x0080, 0, $icon) ; $WM_SETICON = 0x0080, $ICON_SMALL = 0 _SendMessage($hwnd, 0x0080, 1, $icon) ; $WM_SETICON = 0x0080, $ICON_BIG = 1 _WinAPI_DestroyIcon($icon) EndFuncNo more pixelation on my end. Edited April 1, 2015 by willichan My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash
jguinch Posted April 1, 2015 Posted April 1, 2015 (edited) Salut ZDS ! Try with adding Sleep(200) before _WinAPI_DestroyIcon() Edited April 1, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
jguinch Posted April 1, 2015 Posted April 1, 2015 @willichan : your code works, but sometimes the icon is applied to the window only, not to the taskbar. Strange... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
willichan Posted April 1, 2015 Posted April 1, 2015 @willichan : your code works, but sometimes the icon is applied to the window only, not to the taskbar. Strange... It is still Mikell's code. I just changed the image resource sizes to zero to use the .ICO file's specs, and added the second _SendMessage() call. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash
ZDS Posted April 2, 2015 Author Posted April 2, 2015 @jguinch : You are awesome ! I just had (in my example code) to wait before calling _WinAPI_DestroyIcon($icon) ! Adding the Sleep(200) is enough to fix the problem Thanks for all ! Problem solved
ViciousXUSMC Posted April 2, 2015 Posted April 2, 2015 Ahh neat idea changing the icon, I am using the (fixed) version of ZDS code but it is only changing the window icon not the taskbar icon.
jguinch Posted April 2, 2015 Posted April 2, 2015 @ViciousXUSMC : try with willichan's code in #8 and add a Sleep(100) (or more than 100) between the 2 _SendMessage lines . Maybe you can add $LR_SHARED is _WinAPI_LoadImage and then delete _WinAPI_DestroyIcon line (see remarks in https://msdn.microsoft.com/en-us/library/windows/desktop/ms648063%28v=vs.85%29.aspx) Some GPI/WinApi gurus could confirm... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
ViciousXUSMC Posted April 2, 2015 Posted April 2, 2015 @ViciousXUSMC : try with willichan's code in #8 and add a Sleep(100) (or more than 100) between the 2 _SendMessage lines . Maybe you can add $LR_SHARED is _WinAPI_LoadImage and then delete _WinAPI_DestroyIcon line (see remarks in https://msdn.microsoft.com/en-us/library/windows/desktop/ms648063%28v=vs.85%29.aspx) Some GPI/WinApi gurus could confirm... Seems to work if I open notepad with Autoit but if I already have Notepad Open and only want to change the icon it does not work. I experienced the same with the original script opening Autoit Help it was working and most likely because Autoit is opening it. So This works: #include <WinAPI.au3> ShellExecute("notepad.exe") Do Sleep(10) Until WinExists("Untitled - Notepad") $handle = WinGetHandle("Untitled - Notepad") WinSetIcon($handle, @ScriptDir&"\Icone.ico") Func WinSetIcon($hwnd, $file) Local $icon = _WinAPI_LoadImage(0, $file, $IMAGE_ICON, 0, 0, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION)) If Not $icon Then Return False _SendMessage($hwnd, 0x0080, 0, $icon) ; $WM_SETICON = 0x0080, $ICON_SMALL = 0 sleep(200) _SendMessage($hwnd, 0x0080, 1, $icon) ; $WM_SETICON = 0x0080, $ICON_BIG = 1 _WinAPI_DestroyIcon($icon) EndFunc But if I open Notepad and then run this, it only changes the window icon. #include <WinAPI.au3> $handle = WinGetHandle("Untitled - Notepad") WinSetIcon($handle, @ScriptDir&"\Icone.ico") Func WinSetIcon($hwnd, $file) Local $icon = _WinAPI_LoadImage(0, $file, $IMAGE_ICON, 0, 0, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION)) If Not $icon Then Return False _SendMessage($hwnd, 0x0080, 0, $icon) ; $WM_SETICON = 0x0080, $ICON_SMALL = 0 sleep(200) _SendMessage($hwnd, 0x0080, 1, $icon) ; $WM_SETICON = 0x0080, $ICON_BIG = 1 _WinAPI_DestroyIcon($icon) EndFunc
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