Jump to content

Changing a window's icon.


Recommended Posts

Hi,

I'd like to know if it's possible to change the icon of window other then my own created one.

For example - notepad's icon into some other icon.

Thanks in advance,

SK.

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

You will need to change it a little bit >> but since you have 500+ posts I guess you're not looking for a ready made solution.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

doesn't seem to work on anything other then AU3 GUIS... I want to change other applications window's icon... like notepad's...
 
trying this:

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


HotKeySet("+!t", "ChangeWindowTitle")


Global $CurrentActiveWindow, $PreviousActiveWindow


While 1
Sleep(1000)
CheckTitles()
WEnd


Func CheckTitles()
If WinGetTitle("[ACTIVE]") <> $CurrentActiveWindow Then
$PreviousActiveWindow = $CurrentActiveWindow
$CurrentActiveWindow = WinGetTitle("[ACTIVE]")
EndIf
EndFunc


Func ChangeWindowTitle()
WinSetTitle("[ACTIVE]", "", $PreviousActiveWindow)
$hWnd = WinGetHandle("[ACTIVE]")
If Not IsHWnd($hWnd) Then MsgBox(0, "ERROR", "")
_GUISetIcon($hWnd, "H:\Programming\AU3 in progress\Failure.ico", "")
EndFunc




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

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

As I said you will need to tweak it. It's no surprise it doesn't work.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

; Author: Mikell
#include <WinAPI.au3>

Run("notepad.exe")
Do
  Sleep(10)
Until WinExists("[CLASS:Notepad]")
Local $hWnd = WinGetHandle("[CLASS:Notepad]")

_WinSetIcon($hWnd, "shell32.dll", 25)
;~ _WinSetIcon($hWnd, "X:\Path\Icon.ico")
WinSetTitle($hWnd, "", "Testing")

;=========================================
Func _WinSetIcon($hWnd, $sFile, $iIndex = 0)
    Local $tIcons = DllStructCreate("ptr Data")
    DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $sFile, "int", $iIndex, "struct*", 0, "struct*", $tIcons, "uint", 1)
    If @error Then Return SetError(1, 0, 0)
    Local $hIcon = DllStructGetData($tIcons, "Data")
   _SendMessage($hWnd, 0x0080, 1, $hIcon ) ;$WM_SETICON = 0x0080
   _WinAPI_DestroyIcon($hIcon)
   Return 1
EndFunc

Link to comment
Share on other sites

Awesome !

johnmcloud

Thanks for the quick solution :)

p.s. thank you too 

guinness

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

  • 5 years later...
  • Moderators

aVen9er,

Stick to just the one thread please - I have deleted your duplicate post.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

There may be something wrong with your code.  Using this :

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

Const $sTitle = "Testing"
;Run ("Testing.exe")

Do
  Sleep(10)
Until WinExists($sTitle)
Local $hWnd = WinGetHandle($sTitle)
Sleep(1000)
_WinSetIcon($hWnd, "shell32.dll", 41)

Func _WinSetIcon($hWnd, $sFile, $iIndex = 0)
  Local $hIcon = _WinAPI_ExtractIcon($sFile, $iIndex, True)
  _SendMessage($hWnd, $WM_SETICON, 1, $hIcon)
  ConsoleWrite(_WinAPI_DestroyIcon($hIcon) & @CRLF)
EndFunc   ;==>_WinSetIcon

With a compiled x64 AutoIt GUI :

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Testing")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

Works fine even if first script is x86.  Works also if second script.exe is ran inside or outside first script.

Link to comment
Share on other sites

Your example works, but I am trying to change the Total Commander (x64) icon and it doesn't work. (Interestingly works on x86 Total Commander)

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

Const $sTitle = "[Title:Total Commander (x64);Class:TTOTAL_CMD]"

Do
    Sleep(10)
Until WinExists($sTitle)


Local $hWnd = WinGetHandle($sTitle)
Sleep(1000)
_WinSetIcon($hWnd, "shell32.dll", 41)


Msgbox(0, @ScriptName, WinExists($sTitle))      ; checked: Window exists


Func _WinSetIcon($hWnd, $sFile, $iIndex = 0)
    Local $hIcon = _WinAPI_ExtractIcon($sFile, $iIndex, True)
    _SendMessage($hWnd, $WM_SETICON, 1, $hIcon)
    ConsoleWrite(_WinAPI_DestroyIcon($hIcon) & @CRLF)
EndFunc   ;==>_WinSetIcon

 

How to change the icon in Total Commander (x64)?

Edited by aVen9er
Link to comment
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
 Share

  • Recently Browsing   0 members

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