My bad, I now copied it all, but now it shows icons only to same "ApplicationFrameWindow" apps. Messenger and Nvidia Control Panel don't get icons... hmm
Code: Select all
#Requires AutoHotkey v2.0
User32Path := A_WinDir "\System32\imageres.dll"
pIconCount := 0
MyGui := Gui()
ProgramsLV := MyGui.Add("ListView", "+Icon w1640 h600 r1", ["hWnd"])
; Create ImageList
pIL := DllCall("comctl32.dll\ImageList_Create", "int", 256, "int", 256, "uint", 0x20, "int", 10, "int", 10)
ProgramsLV.SetImageList(pIL)
AllWins := WinGetList()
for hWnd in AllWins
{ IconImg := 0
Path := WinGetProcessPath(hWnd)
Name := WinGetTitle(hWnd)
; Get Icon
if (Path := GetLargestUWPLogoPath(hwnd)) ; if UWP
IconImg := LoadPicture(Path, 'Icon1', &IMAGE_ICON) ; Get UWP Icon
else ; Get Normal Icon
DllCall("PrivateExtractIcons","str",Path,"int",0,"int",256,"int",256 ,"uint*",&IconImg,"uint*",0,"uint",1,"uint",0,"int")
if !(IconImg) ; If no Icon, get system one
DllCall("PrivateExtractIcons" ,"str",User32Path,"int",11,"int",256,"int",256 ,"uint*",&IconImg,"uint*",0,"uint",1,"uint",0,"int")
DllCall("comctl32.dll\ImageList_ReplaceIcon", "uint", pIL, "int", -1, "uint", IconImg)
pIconCount += 1
ProgramsLV.Add("Icon" pIconCount, Name)
}
MyGui.Show()
GetLargestUWPLogoPath(hwnd, Default?) {
Address := CallbackCreate(EnumChildProc.Bind(WinGetPID(hwnd)), 'Fast', 2)
DllCall('User32.dll\EnumChildWindows', 'Ptr', hwnd, 'Ptr', Address, 'Ptr*', &ChildPID := 0, 'Int'), CallbackFree(Address)
return ChildPID && AppHasPackage(ChildPID) ? GetLargestLogoPath(GetDefaultLogoPath(ProcessGetPath(ChildPID))) : ''
EnumChildProc(PID, hwnd, lParam) {
ChildPID := WinGetPID(hwnd)
if ChildPID != PID {
NumPut 'UInt', ChildPID, lParam
return false
}
return true
}
AppHasPackage(ChildPID) {
static PROCESS_QUERY_LIMITED_INFORMATION := 0x1000, APPMODEL_ERROR_NO_PACKAGE := 15700
ProcessHandle := DllCall('Kernel32.dll\OpenProcess', 'UInt', PROCESS_QUERY_LIMITED_INFORMATION, 'Int', false, 'UInt', ChildPID, 'Ptr')
IsUWP := DllCall('Kernel32.dll\GetPackageId', 'Ptr', ProcessHandle, 'UInt*', &BufferLength := 0, 'Ptr', 0, 'Int') != APPMODEL_ERROR_NO_PACKAGE
DllCall('Kernel32.dll\CloseHandle', 'Ptr', ProcessHandle, 'Int')
return IsUWP
}
GetDefaultLogoPath(Path) {
SplitPath Path, , &Dir
if !RegExMatch(FileRead(Dir '\AppxManifest.xml', 'UTF-8'), '<Logo>(.*)</Logo>', &Match)
throw Error('Unable to read logo information from file.', -1, Dir '\AppxManifest.xml')
return Dir '\' Match[1]
}
GetLargestLogoPath(Path) {
Size := 0
LoopFilePath := 0
SplitPath Path, , &Dir, &Extension, &NameNoExt
Loop Files Dir '\' NameNoExt '.scale-*.' Extension
if A_LoopFileSize > Size && RegExMatch(A_LoopFileName, '\d+\.' Extension '$') ; Avoid contrast files.
LoopFilePath := A_LoopFilePath, Size := A_LoopFileSize
return LoopFilePath
}
}
#s::Reload