Add Overlay to Taskbaritem (#2196)

* Add taskbaritemoverlay

* remove old commented code
This commit is contained in:
MyDrift 2024-06-28 16:40:38 +02:00 committed by GitHub
parent 0c841f98e8
commit f6af93afbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -287,19 +287,37 @@ Add-Type @"
}
}
# need to experiemnt more
# setting icon for the windows is still not working
# $pngUrl = "https://christitus.com/images/logo-full.png"
# $pngPath = "$env:TEMP\cttlogo.png"
# $iconPath = "$env:TEMP\cttlogo.ico"
# # Download the PNG file
# Invoke-WebRequest -Uri $pngUrl -OutFile $pngPath
# if (Test-Path -Path $pngPath) {
# ConvertTo-Icon -bitmapPath $pngPath -iconPath $iconPath
# }
# $icon = [System.Drawing.Icon]::ExtractAssociatedIcon($iconPath)
# Write-Host $icon.Handle
# [Window]::SendMessage($windowHandle, 0x80, [IntPtr]::Zero, $icon.Handle)
# Using a TaskbarItem Overlay until someone figures out how to replace the icon correctly
# URL of the image
$imageUrl = "https://christitus.com/images/logo-full.png"
# Download the image
$imagePath = "$env:TEMP\logo-full.png"
Invoke-WebRequest -Uri $imageUrl -OutFile $imagePath
# Read the image file as a byte array
$imageBytes = [System.IO.File]::ReadAllBytes($imagePath)
# Convert the byte array to a Base64 string
$base64String = [System.Convert]::ToBase64String($imageBytes)
# Create a streaming image by streaming the base64 string to a bitmap streamsource
$bitmap = New-Object System.Windows.Media.Imaging.BitmapImage
$bitmap.BeginInit()
$bitmap.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($base64String)
$bitmap.EndInit()
$bitmap.Freeze()
# Ensure TaskbarItemInfo is created if not already
if (-not $sync["Form"].TaskbarItemInfo) {
$sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo
}
# Set the overlay icon for the taskbar
$sync["Form"].TaskbarItemInfo.Overlay = $bitmap
$rect = New-Object RECT
[Window]::GetWindowRect($windowHandle, [ref]$rect)