Thanks to help from a Code Project member (D.K.), I have created an app (Win 7) that modifies its taskbar icon, displaying a numerical value that is important to us. (Note: on the Taskbar, not the Notification bar.)
Everything works fine when the program is run from the local workstation. But when I place the .exe on a server and create a local shortcut to it on the desktop, the modified icon does not appear -- only the icon specified in the App settings under Visual Studio. (And if I remove that icon spec, I get the stock "no-icon" icon.)
I checked the local firewall -- since the program runs (only the icon fails to present itself), I couldn't see how it could be the firewall, but to be sure I added the .exe and granted it access.
All users have access rights to the folder on the server.
I've searched CP for "icon" and not found anything; Google came up dry for me as well.
The server is Windows Server 2003 R2.
The app is a Windows Form app.
Here is the code for handling the icon -- 3 functions; the first is the main one, the second formats the number displayed in the icon, and the third picks a font that allows the number to fit in the space of an icon:
Call: Me.Icon = MakeIcon(CDbl(total)) 'updates the taskbar icon with the Total value
Functions:
Private Function MakeIcon(ByVal val As Double) As Icon
Dim bmp As New Bitmap(64, 64)
Dim g As Graphics = Graphics.FromImage(bmp)
g.FillRectangle(IIf(val >= 0, Brushes.DarkBlue, Brushes.Maroon), 0, 0, 64, 64)
currTaskbarFont = ChooseFont(g, val, bmp)
Dim s As String = ConvertToKilosAndMegs(val)
Dim w As SizeF = g.MeasureString(s, currTaskbarFont)
g.DrawString(s, currTaskbarFont, Brushes.White, _
(bmp.Width - w.Width) / 2, (bmp.Height - w.Height) / 2)
Return Drawing.Icon.FromHandle(bmp.GetHicon)
End Function
Private Function ConvertToKilosAndMegs(ByVal val As Double) As String
Dim sResults As String
Select Case Math.Abs(val)
Case Is > 9999.9999
sResults = (val * 0.001).ToString("F0") & "K"
Case Is > 9999999.9999
sResults = (val * 0.000001).ToString("F0") & "M"
Case Else
sResults = val.ToString("F0")
End Select
Return sResults
End Function
Private Function ChooseFont(ByRef g As Graphics, ByVal val As Double, ByRef container As Bitmap) As Font
Dim myFont As Font = fnt(0)
Try
For i As Integer = 1 To TASKBAR_FONT_COUNT - 1
If g.MeasureString(val.ToString("F0"), fnt(i)).Width >= container.Width * 1.1 Then
myFont = fnt(i - 1)
Exit For
Else
myFont = fnt(i)
End If
Next
Catch ex As Exception
MsgBox("An error has been encountered in the routine that selects " _
& "the optimum font size for the Taskbar Icon." & vbCrLf _
& "The icon may not display the Total P&L value properly.", _
MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Error with Taskbar Icon")
End Try
Return myFont
End Function
Any suggestions would be much appreciated!