Skip to content

Commit

Permalink
Add Overlay to Taskbaritem (#2196)
Browse files Browse the repository at this point in the history
* Add taskbaritemoverlay

* remove old commented code
  • Loading branch information
MyDrift-user authored Jun 28, 2024
1 parent 0c841f9 commit f6af93a
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f6af93a

Please sign in to comment.