[SOLVED] NotifyIcon doesn't show at tray startup with windows logon

  • 12 years ago

    Basically i am installing wallpi to start with user logon with setting a item in HKCU\Software\Microsoft\Windows\CurrentVersion\Run. That is all ok, but firstly I put WindowState=Minimalized to Form_Load, and "Me.Hide : NotifyIcon.Visible = True" in OnResize (if minimalizing) event. That worked, but sometimes it hide form, but didn't show NI. So I add Timer which Is started in FormLoad, in order to delay Form hiding and NI showing few milliseconds after FormLoad. It worked in more cases than previous model, but it is still failing in some cases (when explorer is largely bussy at start, making updates etc). Don't you know "The right way" to install application to tray after logon? I thought that Me.Hide, Notify.Show in any order is enough at end of Form_Load, but it is not, and application with lost window is great bug, even if it is only one of ten launches. Crying Thx for any idea.

  • 12 years ago

    Ok I  maybe solved that problem. It may be caused by "Hide inactive icons" setting in main panel.

  • 12 years ago

    So I finally solved it. It was not a win-bug at all. Lets tell that if you don't use Form_Load for any of NotifyIcon works you may get correct behaviour. Property ni.visible, as sub me.hide() are out of order in Load event handler. The correct way which is now hiding form at startup immediatelly, and showing icon without "sporadic failures":

    Sub Form.New():

    • Call ResetIcon
    • Check arguments and (IF)  set visibility of NotifyIcon

    Instead of Form_Load use Form_Shown():

    • Check arguments and (IF) call Me.Hide()

    Override Form.DefWndProc

    • Send all messages default, and only for Msg=&HC091 (IF Me.Invisible)
      call ResetIcon, which should restore icon after explorer restart.

    Sub ResetIcon():

    • Remove old icon from components and dispose it (IF)
    • Intialize new instance Notify icon manually, adding it to me.components
    • Set icon's icon, text, and optionally visibility

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Engineers are all basically high-functioning autistics who have no idea how normal people do stuff.” - Cory Doctorow