Sign in to follow this  
Followers 0

Dynamically change window icon

7 posts in this topic

Posted

As some of you already know I have been working on a free tool that provides an easy to use interface for mounting/dismounting truecrypt volumes.

However I am stumped on how to get the window icon to change dynamically. Simply using GuiSetIcon() does not appear to change the icon on the taskbar in Windows 7.

If any gurus would like to help out or at least point me in the right direction I would be forever grateful. :)

Issue Tracker Entry

Share this post


Link to post
Share on other sites



Posted (edited)

The Author is Yashied (of course!) I tend not to use the Variable Naming Standard but I did just for you :) >> http://www.autoitscript.com/autoit3/udfs/UDF_Standards.htm

See Update >>

Edited by guinness

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks for the quick reply. This looks to be exactly what i needed. Im currently fixing a few other bugs in the app and will test this out very soon. If this works both you and Yanished will get a special place in the readme. :)

Edited by FuryCell

Share this post


Link to post
Share on other sites

Posted (edited)

It does just tested now :) I will update in a second with an Example (I have a couple of things to add to the previous Function) Edited by guinness

Share this post


Link to post
Share on other sites

Posted (edited)

The original Author was Yashied and I just modified it a little!

Function:

Func _GUISetIcon($hWnd, $sFilePath, $iName)
    If Not IsHWnd($hWnd) Then
        Local $iLabel = GUICtrlCreateLabel('', -99, -99, 1, 1)
        $hWnd = _WinAPI_GetParent(GUICtrlGetHandle($iLabel))
        If @error Then
            Return SetError(@error, 0 * GUICtrlDelete($iLabel), 0)
        EndIf
        GUICtrlDelete($iLabel)
    EndIf
    Local $hIcon = _WinAPI_LoadImage(_WinAPI_GetModuleHandle($sFilePath), $iName, 1, 32, 32, 0)
    Return _SendMessage($hWnd, $WM_SETICON, 1, $hIcon)
EndFunc   ;==>_GUISetIcon

Example use of Function.

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('_GUISetIcon()')
    GUISetState(@SW_SHOW, $hGUI)

    _GUISetIcon(-1, @SystemDir & 'shell32.dll', 25) ; Change Icon! - Uses -1 to get the last GUI Handle.
    Sleep(2000)

    _GUISetIcon($hGUI, @SystemDir & 'shell32.dll', 30) ; Change Icon! - Passing the GUI Handle to the Function.
    Sleep(2000)

    _GUISetIcon($hGUI, '', '') ; Reset Icon.

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example
Edited by guinness

Share this post


Link to post
Share on other sites

Posted

The original Author was Yashied and I just modified it a little!...

Thanks , this works perfect on Windows 7. I can't wait to integrate this in MTCrypt. :)

Share this post


Link to post
Share on other sites

Posted (edited)

I had some trouble with that function not accepting 48x icons. However I did find a somewhat kludgly solution. (Not really bad for my app though as the launcher I describe below has the added benefit of launching the appropriate version for 32/64 bit systems.)

First I used the built-in GUISetIcon() to change the main window icon. This seemed to work fine until I used a shortcut to launch the exe. To remedy this I created a very small and simple launcher using FreeBasic. FreeBasic has the advantage of creating ultra small exes in situations like this. Now when the program is started using the launcher the icon on the Window 7 TaskBar changes as expected.

ChDir(".\bin")
If Environ ("PROCESSOR_ARCHITEW6432")="AMD64" Then
	Run("mtcrypt64.exe")
Else
	Run("mtcrypt32.exe")
EndIf

As a side note FreeBasic is great companion for creating small things like this as you dont need another ~800kb uncompressed exe to bring along with your AutoIt executable(s). The learning curve was virtually non-existent and the docs on their wiki are excellent. It even creates dlls that can be used with dllcall. :)

FreeBasic HomePage

Edited by FuryCell

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