From f6af93afbd15c2e8cacc55e4f636449662110483 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Fri, 28 Jun 2024 16:40:38 +0200 Subject: [PATCH] Add Overlay to Taskbaritem (#2196) * Add taskbaritemoverlay * remove old commented code --- scripts/main.ps1 | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 572ecee4..ecceb510 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -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)