WildByDesign Posted 6 hours ago Posted 6 hours ago GUISetIcon seems to have a bug with regard to DPI. When a windows application utilizes an icon, it is supposed to choose the icon size which is closest to the size needed by the system from the .ICO file. TraySetIcon does not seem to have this bug. I have created an example which shows the problem. The example creates a GUI with system DPI awareness and sets the same icon file with GUISetIcon and TraySetIcon. You will notice that the icon in the GUI is blurry and stretched, while the same icon in the system tray is sharp as expected. Example: (app.ico is attached to this message) #include <GUIConstantsEx.au3> ; System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 400, 400) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; set GUI icon GUISetIcon(@ScriptDir & "\app.ico") ; set tray icon TraySetIcon(@ScriptDir & '\app.ico') ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example On a side note, does anyone know of any WinAPI or DLL calls that we can use to load a GUI icon so that I can avoid this bug? app.ico
argumentum Posted 6 hours ago Posted 6 hours ago (edited) Yes, the tray icon looks better than the GUI caption's icon. Edited 5 hours ago by argumentum I broke something. Fixed. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted 5 hours ago Posted 5 hours ago tray looks better with just 64x64, let the OS / AutoIt do the resizing. au3.213458-guiseticon-dpi-bug.app_v2.ico And yes, @jpm should look at this. ( I don't know of a work around but there should be one on the _WinAPI_* side of things ) WildByDesign 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
WildByDesign Posted 5 hours ago Author Posted 5 hours ago Thanks for confirming and for tagging the right person to escalate the issue. I will have a look at the WinAPI functions and see if I can get something going there. argumentum 1
Solution argumentum Posted 4 hours ago Solution Posted 4 hours ago (edited) 1 hour ago, argumentum said: there should be one on the _WinAPI_* side of things expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WinAPIIcons.au3> ; _WinAPI_ExtractIcon #include <SendMessage.au3> ; _SendMessage ; System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Example() ; https://www.autoitscript.com/forum/topic/213458-guiseticon-dpi-bug/#comment-1549810 Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 400, 400) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; set GUI icon ;~ GUISetIcon(@ScriptDir & "\app.ico") _WinSetIcon($hGUI, @ScriptDir & "\app.ico") ; set tray icon TraySetIcon(@ScriptDir & '\app.ico') ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _WinSetIcon($hWnd, $sFile, $iIndex = 0, $bSmall = False) ; https://www.autoitscript.com/forum/topic/168698-changing-a-windows-icon/#findComment-1461109 Local $WM_SETICON = 128, $ICON_SMALL = 0, $ICON_BIG = 1, $hIcon = _WinAPI_ExtractIcon($sFile, $iIndex, $bSmall) If Not $hIcon Then Return SetError(1, 0, 1) ; https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-seticon _SendMessage($hWnd, $WM_SETICON, Int(Not $bSmall), $hIcon) _WinAPI_DestroyIcon($hIcon) EndFunc ;==>_WinSetIcon Google is your friend. Actually @Nine is vs this: Edit: #include <windows.h> // ... inside your code, e.g., after CreateWindow or in WM_CREATE handler ... HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON)); // Load your icon resource if (hIcon) { // Set the large icon (appears in Alt+Tab, etc.) SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); // Set the small icon (appears in the title bar) SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } Edited 4 hours ago by argumentum better ? WildByDesign 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
WildByDesign Posted 4 hours ago Author Posted 4 hours ago That is so much better. I’m just going by your screenshots right now because I won’t be able to test it until maybe an hour from now. I am always amazed at the versatility of AutoIt. So many ways to do just about anything. Or as I believe @Nine had wrote before , “different ways to skin a cat”. argumentum 1
WildByDesign Posted 1 hour ago Author Posted 1 hour ago This ended up being a perfect solution. Excellent. Thanks again, @argumentum
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