Jump to content

No custom GUI icon in taskbar when au3 script is executed by "Run script" option


Go to solution Solved by argumentum,

Recommended Posts

Posted (edited)

According to this my old post with similar problem: different title on taskbar/gui

 

here is modification for different icon on taskbar/gui -> which works for me in all situations (Drag/Run/Scite...):

#NoTrayIcon
#include <GUIConstants.au3>
#include <Misc.au3>
#include <SendMessage.au3>

;~ Global Const $WM_SYSCOMMAND = 0x0112
;~ Global Const $SC_MINIMIZE = 0xF020
;~ Global Const $SC_RESTORE = 0xF120
;~ Global Const $WM_MOVE = 0x3
;~ Global Const $WM_SIZE = 0x05

$app = GUICreate("Application title", 1, 1,-1,-1,$WS_POPUP)
GUISetIcon(@ScriptDir & '\test1.ico')
GUISetState(@SW_SHOW, $app)
$gui = GUICreate("Form title", 300, 200, -1, -1, -1, -1, $app)
GUISetIcon(@ScriptDir & '\test2.ico')
GUISetState(@SW_SHOW, $gui)

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
GUIRegisterMsg($WM_MOVE, "WM_MOVE")

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    Switch $wParam
        Case $SC_MINIMIZE
            _SendMessage($app, $WM_SYSCOMMAND, $SC_MINIMIZE, 0)
            GUISetState(@SW_HIDE, $gui)
            Return 0
        Case $SC_RESTORE
            _SendMessage($app, $WM_SYSCOMMAND, $SC_RESTORE, 0)
            GUISetState(@SW_SHOW, $gui)
            Return 0
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func WM_MOVE($hWnd, $Msg, $wParam, $lParam)
;~  If $hWnd = $gui Then
        $pos = WinGetPos($gui)
        WinMove($app, '', $pos[0], $pos[1])
;~      WinMove($app, '', _LoWord($wParam), _HiWord($wParam))
;~  EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc

 

Edited by Zedna
Posted (edited)

Here is simplified version, which should work also on new AutoIt's versions (I use very old 3.2.12.1):

#NoTrayIcon
#include <GUIConstantsEx.au3>

$app = GUICreate("Application title", 1, 1,-1,-1,0x80000000) ; $WS_POPUP=0x80000000
GUISetIcon(@ScriptDir & '\test1.ico')
GUISetState(@SW_SHOW, $app)
$gui = GUICreate("Form title", 300, 200, -1, -1, -1, -1, $app)
GUISetIcon(@ScriptDir & '\test2.ico')
GUISetState(@SW_SHOW, $gui)

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

 

But this works for me also when running on my (Unzipped) AutoIt 3.3.14.5/3.3.16.1 ...

Edited by Zedna
Posted (edited)

not working

how do you have it installed?

is portable?   is in C:\Program Files (x86)\ ?

why is possible by drop in folder out of C:\Program Files (x86)\ ?

Edited by ioa747

I know that I know nothing

Posted (edited)

yesterday i installed it on c:\ , without result,  and I reinstalled it on C:\Program Files (x86)\ :(

Edited by ioa747

I know that I know nothing

Posted

@Nine can you enlighten us ?

I have this version
v3.3.16.1    19 September, 2022
https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.zip

if i run the script from shell with right click custom icon in taskbar not working
if i run the script from SciTE with f5 custom icon in taskbar not working
if i drop the script on C:\Program Files (x86)\AutoIt3\AutoIt3.exe custom icon in taskbar not working

if I copy  the AutoIt3 folder from C:\Program Files (x86)\AutoIt3  to C:\ , and  drop the script on AutoIt3.exe custom icon in taskbar is working

Is there a logical explanation?

I know that I know nothing

Posted (edited)

I have got standard instalation by installer 3.2.12.1 + full Scite4AutoIt3 (from that old time).

Newer versions on my computer are only unzipped AutoIt+Scite4AutoIt3.

On my machine it's OK with ALL versions in all scenarios.

I still don't know why it's OK on my machine and not on yours.

EDIT:

I have (completely) disabled UAC on all my computers, maybe try to disable it (temporarily) too ...

Edited by Zedna
Posted

Well, I have both too. And none is working correctly as you.  In fact, you are the only one that works.  So what does it tell you ? You are an MVP, question and answer is on your side to understand and tell us the reason.

Posted (edited)

On my Windows 10 system with AutoIt 3.3.16.1 installed, if I have the system taskbar setting 'Combine taskbar buttons' set to 'Always, hide labels', I get the generic AutoIt icon in the taskbar when running an uncompiled script. But if I change that setting to 'Never' or 'When taskbar is full', I see the custom icon.

image.png.b12d3e5905801229e8355930f9003118.png

 

image.png.07e1f162d308887db11bc2a458b241d0.png

Edited by TimRude
Posted

that is something. But what cracks me up is

if I copy  the AutoIt3 folder from C:\Program Files (x86)\AutoIt3  to C:\ , and  drop the script on AutoIt3.exe custom icon in taskbar is working

Is there a logical explanation?

I have come to the conclusion that something is going on in the windows registry, but I don't know what  :)

I know that I know nothing

Posted (edited)
24 minutes ago, argumentum said:

_WinAPI_SetCurrentProcessExplicitAppUserModelID() will fix that :)

Yep, it sure does! Now I get the custom icon in the taskbar no matter what 'Combine taskbar buttons' setting I use.

#NoTrayIcon
#include <GUIConstants.au3>
#include <WinAPICom.au3>
#include <WinAPIShellEx.au3>

_WinAPI_SetCurrentProcessExplicitAppUserModelID(_WinAPI_CreateGUID()) ; ensure a unique ID

GUICreate("My Custom GUI", 300, 200)
GUISetIcon(@SystemDir & "\shell32.dll", 239)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by TimRude
  • 1 year later...
Posted (edited)

Hi just to let you know, I'm at my bro's home on a Win11 x64 laptop, with AutoIt portable 3.3.16.1 unzipped on a USB device, extracted from the 17.208 Kb zip file found on the download page : "AutoIt– Self Extracting Archive (for those who don’t like/want an installer)(includes x86 and x64 components and Aut2Exe and AutoItX)"

Now I run Scite.exe from the USB device, then open this .au3 script in Scite and run it with F5 (Go) 

GUICreate("Custom icon in Taskbar & Systray", 400, 300)
GUISetIcon(@ScriptDir & '\script.ico') ; ok
TraySetIcon(@ScriptDir & '\script.ico') ; ok

GUISetState()

Do
Until GuiGetMsg() = -3 ; $GUI_EVENT_CLOSE (-3)

43.jpg.ec5d1a9bda56ca05975602e667127383.jpg

As you can see, the external icon is correctly shown in the 3 places, even when the script is an .au3 file :
In the GUI itself
In Taskbar
In SysTray

I did this test because some posters were surprised why it worked on Zedna's computer but not on their computer.
Hope it helps

Edit: the icon appears also correctly when I press Alt+Tab to switch between tasks.

Edited by pixelsearch
Posted

@pixelsearch the issue was solved by @argumentum  with the following

On 2/16/2023 at 7:37 AM, argumentum said:

_WinAPI_SetCurrentProcessExplicitAppUserModelID() will fix that :)

However, let's do a recap.

on my computer: Windows 10 Pro   Version    22H2
with AutoIt Version: 3.3.16.1 installed 
 

  • 1) if I run the script below

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#NoTrayIcon
#include <GUIConstants.au3>
#include <WinAPIShellEx.au3>

;~ _WinAPI_SetCurrentProcessExplicitAppUserModelID(_WinAPI_CreateGUID()) ; ensure a unique ID
GUICreate("My Custom GUI", 300, 200)
GUISetIcon(@ScriptDir & '\test1.ico') ; ok
TraySetIcon(@ScriptDir & '\test1.ico') ; ok
GUISetState(@SW_SHOW)

Do
Until GuiGetMsg() = -3 ; $GUI_EVENT_CLOSE (-3)
  • the display is

LKXco.png

 

  • 2) if I run the script below

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#NoTrayIcon
#include <GUIConstants.au3>
#include <WinAPIShellEx.au3>

_WinAPI_SetCurrentProcessExplicitAppUserModelID(_WinAPI_CreateGUID()) ; ensure a unique ID
GUICreate("My Custom GUI", 300, 200)
GUISetIcon(@ScriptDir & '\test1.ico') ; ok
TraySetIcon(@ScriptDir & '\test1.ico') ; ok
GUISetState(@SW_SHOW)

Do
Until GuiGetMsg() = -3 ; $GUI_EVENT_CLOSE (-3)
  • the display is

iweTL.png

 

However, as I mentioned above,
if I copy AutoIt3.exe along with the Include folder to @ScriptDir
and drag script1 onto AutoIt3.exe, then the display result is like 2

 

conclusion?
 

Also, something else that impressed me is that if I pin AutoIt3.exe to the start menu and right-click,
it also shows me image files.
Clipboard_12.png

 

Please, every comment is appreciated!
Thank you very much  :)

 

I know that I know nothing

Posted

Something like that, you mean?

#NoTrayIcon
#include <GUIConstants.au3>
#include <WinAPIShellEx.au3>

_WinAPI_SetCurrentProcessExplicitAppUserModelID(StringTrimRight(@ScriptName, 3) & "_v1.0")
GUICreate("My Custom GUI", 300, 200)
GUISetIcon(@ScriptDir & '\test1.ico') ; ok
TraySetIcon(@ScriptDir & '\test1.ico') ; ok
GUISetState(@SW_SHOW)

Do
Until GuiGetMsg() = -3 ; $GUI_EVENT_CLOSE (-3)

 

I know that I know nothing

Posted (edited)

   image.png.4cc2e7376e00661ac0ea038db1d97b2e.png   image.png.d72a87516a48aec30c379d52ec13480d.png

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#NoTrayIcon ; either way, upto the coder
#include <GUIConstants.au3>
#include <WinAPIShellEx.au3> ; for _WinAPI_SetCurrentProcessExplicitAppUserModelID($sAppID)
#include <WinAPIProc.au3> ;    for _WinAPI_GetCurrentProcessExplicitAppUserModelID()
;~ #include <WinAPICom.au3> ;  for _WinAPI_CreateGUID()


;~ Global Const $_g__ProcessExplicitAppUserModelID = "{E2971A53-037D-4811-B3E3-FE79C2586831}" ; created with _WinAPI_CreateGUID()
;~ _WinAPI_SetCurrentProcessExplicitAppUserModelID($_g__ProcessExplicitAppUserModelID) ; ensure a unique product ID
; or
Global Const $VERSION = "0.1.2.3" ; @ScriptFullPath would be better than @ScriptName ? ( depending on how the script works )
_WinAPI_SetCurrentProcessExplicitAppUserModelID(StringRight(StringTrimRight(@ScriptFullPath, 3) & $VERSION, 127))  ; ensure a unique product ID [and maybe unique for version too]


; max length of "SetCurrentProcessExplicitAppUserModelID" is 127 char.
ConsoleWrite(' CurrentProcessExplicitAppUserModelID:' & @CRLF & _
        '         StringLen = ' & StringLen(_WinAPI_GetCurrentProcessExplicitAppUserModelID()) & @CRLF & _
        '              AppID >' & _WinAPI_GetCurrentProcessExplicitAppUserModelID() & '< ' & @CRLF & _
        '  @error,@extended = ' & @error & ',' & @extended & @CRLF & @CRLF)


main()
Func main()
    Local $sIcon = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1)) & "Icons\MyAutoIt3_Red.ico"
    Local $hGUI = GUICreate("My Custom GUI", 300, 200)
    GUISetIcon($sIcon) ; ok
    TraySetIcon($sIcon) ; ok
    Local $idBttn1 = GUICtrlCreateButton("MsgBox without parent", 5, 5, 200, 25)
    Local $idBttn2 = GUICtrlCreateButton("MsgBox with parent", 5, 35, 200, 25)
    GUISetState(@SW_SHOW)

    While "meh" ; it is very important to have fun while coding, for me anyway
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idBttn1
                MsgBox(0, "title", "Bttn 1" & @LF & @LF & "w/o parent", 60)
                Do ; the msgbox is smaller than the gui and GuiGetMsg gets queued,
                Until Not GUIGetMsg() ; therefore this avoids closing the gui unwillingly.

            Case $idBttn2 ; hence is better to provide the parent if present.
                MsgBox(0, "title", "Bttn 2" & @LF & @LF & "with parent", 60, $hGUI)

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>main

Yes @ioa747. I too felt that it needed a better presentation than just a phrase. :lol:
That's why I posted this.
I tend to tell people to "put code where you mouth is". I was failing my own demands 😁

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...