B4J Question Hide Taskbar Icon when App Window is Minimised

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I have an app that is basically a background task, but which I still want to control form the GUI. I use the system tray with a menu which is the main way for the user to control the process.


The app has a main window which I minimize on startup so I end up with the task icon in the windows task bar and a system tray icon with its right click menu. I wish to hide the Icon in the task bar to save taskbar real estate and to dissuade users from closing the app inadvertently. (I do have a close request dialog).

I am using jFormUtils, but there doesn't seem to be a way of hiding the task-bar icon. Is it possible to do this?

System Tray Manu:
'============================================================================================
Sub iconTray_MenuClick (Text As String)
    Log("Tray Menu Text = " & Text)
    Select Text
        Case "Open Main Form"
            
            If fu.IsIconified(MainForm) = True Then
                fu.SetIconified(MainForm, False)
            End If
            
        Case "Hide Main Form"
            If fu.IsIconified(MainForm) = False Then
                fu.SetIconified(MainForm, True)
            End If   
            
        Case "Stop MCU Server When Done"
            mcuc.bridgeShutDownOnComplete
            iconTray.SetImage(YellowImage)
            
        Case "Stop MCU Server Now"
            mcuc.shutDownServer
            iconTray.SetImage(YellowImage)
            
        Case "Start MCU Server"
            mcuc.startServer
            iconTray.SetImage(GreenImage)
            
        Case "Exit - When Done"
            Dim icon As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "warning.png", 60dip, 60dip, True)
    
            Dim sf As Object = xui.Msgbox2Async("Do you wish to close the bridge?", _
                                        "Shortt Bridge Close", _
                                         "Yes", "", "No", icon)

            Wait For (sf) Msgbox_Result (Result As Int)
    
            If Result = xui.DialogResponse_Cancel Or  Result = xui.DialogResponse_Negative Then
                Return
            End If
            
            mcuc.bridgeShutDownOnComplete
            
            Do While mcuc.TranInProgress = True
                Sleep(120)
            Loop
            sysTray.RemoveTrayIcon(iconTray)
            MainForm.Close
    End Select
End Sub

This kind of thing is done a lot with apps like anti-virus programs which run in the background with a system tray icon and when double clicked open up an application window. Whilst the window is open the task bar has an icon, when the window is closed the icon disappears.

Regards
Rob
 

rgarnett1955

Active Member
Licensed User
Longtime User
Thank's Erel,

That was exactly what I needed. I hadn't realised that you could Show/Close the form and keep the app running.

The double click works fine also.

I will attach the project as a zip for others.

Best regards
Rob
 

Attachments

  • ShorttClockBridgeSvrUI_Example_Tray.rar
    70.8 KB · Views: 92
Upvote 0
Top