Community discussion forum

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

  • 3 months 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 FormLoad, 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 FormLoad, 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.

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 3 months ago

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

  • 3 months 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).