Click here to Skip to main content
15,887,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've made a program that minimizes to the system tray. But it won't stay there. It disappears into the "up arrow" area of the taskbar. I know it can be done, because other applications don't have this problem (such as AVG).

So... what's the trick?
Posted
Updated 6-Oct-15 11:29am
v4

Read this[^], think it may have the answer you seek.
 
Share this answer
 
Comments
R. Giskard Reventlov 6-Oct-15 18:52pm    
This is an English language website: if you want to talk rubbish go to StackOverflow.
Thanks for the link. Some of them I've already seen, but some not. In the meantime, I found some code that is "supposed" to get around the issue. However, I'm getting the famous "such and such is not declared and may not be... yada, yada. Maybe someone can tell me why this is happening to me?

VB
    Private Shared Function ROT13(ByVal input As String) As String
        Dim sb As New StringBuilder
        For Each c As Char In input
            If Char.IsLetter(c) Then
                If Convert.ToInt32((Char.ToUpper(c))) < 78 Then
                    sb.Append(Convert.ToChar(Convert.ToInt32(c) + 13))
                Else
                    sb.Append(Convert.ToChar(Convert.ToInt32(c) - 13))
                End If
            Else
                sb.Append(c)
            End If
        Next
        Return sb.ToString
    End Function

    Public Sub writeToRegStream(ByVal appExecutable As String, ByVal visibleValue As IconStreamVisibleValues)

        Dim iconStreamBytes() As Byte = Nothing
        Dim iconHeader() As Byte = Nothing
        Dim exeName() As Byte = Nothing
        Dim recordCount As Integer = 0

        ' Open registry key with write access permission.
        Dim r As RegistryKey = Registry.CurrentUser.OpenSubKey(
       "Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify", True)

        ' We need the raw IconStream bytes read from registry.
        iconStreamBytes = r.GetValue("IconStreams", Nothing)

        Using ms As New MemoryStream(iconStreamBytes)

            Using reader As New BinaryReader(ms)

                ' Read the icon streams header, this also advances
                ' the position in the stream @20 offset.
                iconHeader = reader.ReadBytes(20)

                ' Read the IconStreams record count @12 byte offset
                ' in IconStreams header.
                recordCount = BitConverter.ToInt32(iconHeader, 12)

                ' Each IconStreams record after the 20 byte header
                ' is 1640 bytes.
                For i As Integer = 1 To recordCount

                    ' Get the executable path information bytes.
                    exeName = reader.ReadBytes(528)

                    ' Advance 4 bytes in the stream for visibility position.
                    reader.ReadInt32()

                    ' The full executable path decoded using ROT13.
                    If (ROT13(Encoding.Unicode.GetString(exeName))).Contains(appExecutable) Then

                        ' Prepare to write the new visibility value into the stream.
                        Using bw As New BinaryWriter(ms)

                            ' The offset value in the stream to write.
                            bw.Seek(reader.BaseStream.Position - 4, SeekOrigin.Begin)

                            ' Write the new visible value.
                            bw.Write(CInt(visibleValue))

                            ' Save the new edited IconStreams bytes into the registry.
                            r.SetValue("IconStreams", ms.ToArray)
                        End Using

                        Exit For '__leave
                    End If

                    ' Skip bytes
                    reader.BaseStream.Seek(1108, SeekOrigin.Current)

                Next

            End Using
        End Using

        ' Close the registry handle
        r.Close()

    End Sub

End Class


It's the "writeToRegStream" sub that is giving me heartache. Also, can you tell if this will work or not? I'm really not sure at this point.

Thanks again everyone.
 
Share this answer
 
v2
Comments
Matt T Heffron 6-Oct-15 20:08pm    
This doesn't appear to be related to your original question. If it actually is, then use "Improve question" above, just below the original posting. If it is NOT related, then post it as a new question with an appropriate title. Afterwards, in either case, this "Solution" should be deleted.

-- At "second look" it does appear sort of related. You haven't told us what it is doing that is not what you expect. Did you use the debugger and examine the behavior?
jumper77 6-Oct-15 21:03pm    
Hi Matt, thanks for replying. I got my code working now. It was pilot error. I'm not sure if the code I posted will actually help or not, but I will let you know when I can (which should be soon, I hope). Appreciate you taking the time to help.
jumper77 6-Oct-15 21:44pm    
Sorry, forgot to answer your questions... My issue is that my tray icon keeps going into the "hidden" section of the system tray. And I must sadly say that I haven't tried to debug this behavior. That's bad of me, but thanks for the kick.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900