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 # Using a TaskbarItem Overlay until someone figures out how to replace the icon correctly
# $pngUrl = "https://christitus.com/images/logo-full.png"
# $pngPath = "$env:TEMP\cttlogo.png" # URL of the image
# $iconPath = "$env:TEMP\cttlogo.ico" $imageUrl = "https://christitus.com/images/logo-full.png"
# # Download the PNG file
# Invoke-WebRequest -Uri $pngUrl -OutFile $pngPath # Download the image
# if (Test-Path -Path $pngPath) { $imagePath = "$env:TEMP\logo-full.png"
# ConvertTo-Icon -bitmapPath $pngPath -iconPath $iconPath Invoke-WebRequest -Uri $imageUrl -OutFile $imagePath
# }
# $icon = [System.Drawing.Icon]::ExtractAssociatedIcon($iconPath) # Read the image file as a byte array
# Write-Host $icon.Handle $imageBytes = [System.IO.File]::ReadAllBytes($imagePath)
# [Window]::SendMessage($windowHandle, 0x80, [IntPtr]::Zero, $icon.Handle)
# 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 $rect = New-Object RECT
[Window]::GetWindowRect($windowHandle, [ref]$rect) [Window]::GetWindowRect($windowHandle, [ref]$rect)