user3693167
user3693167

Reputation: 813

Adding a program to run with Windows Startup to start in notifications in task bar

I have developed a C# wpf application with Visual Studio 2012. I published it with Inno Setup. When I start my program by double clicking the item it starts ans show me GUI "A". When I minimize, it goes to notifications in task bar and shows GUI "B". What I need is let this start with windows start-up. When it starts with start-up I do not want to show GUI "A", just directly minimize it in notifications.

How can I achieve that ?

Upvotes: 0

Views: 1073

Answers (3)

Ashok Rathod
Ashok Rathod

Reputation: 840

  1. Create one Static Variable Name as IsAppStartCall in your GUI A.

    static bool IsAppStartCall = true;

2.Create Parameterised constructor for GUI A and in that check IsAppStartCall or not.

public void GUIA(bool isAppStartCall)
{
  IsAppStartCall = isAppStartCall;

  // do your other tasks here
}

3.Now in your Window Loaded event check above code like this

//in loaded event last statement should be like this. //this will ensure that whenever AppstartCall=true is there then and then it will set this window to mimimise otherwise not.

if(IsAppStartCall)
{
 this.WindowState=WindowState.Minimized;
 IsAppStartCall= false; //as once we achieved this functionality we will set it to false
}

Find Solution that worked me

GUIA.xaml

<Window x:Class="WpfApplication1.GUIA"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button x:Name="btnCloseAnotherWindow" Click="btnCloseAnotherWindow_Click" Content="Click Me"  Width="100" Height="100"/>
    </Grid>
</Window>

GUIA.xaml.cs

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>


    public partial class GUIA : Window
    {
        static bool IsAppStart = true;

        public GUIA()
        {
            InitializeComponent();
            this.Loaded += GUIA_Loaded;
        }

        public GUIA(bool isAppStart)
        {
            IsAppStart = isAppStart;
            this.Loaded += GUIA_Loaded;
        }

        void GUIA_Loaded(object sender, RoutedEventArgs e)
        {
            if (IsAppStart)
            {
                this.WindowState = System.Windows.WindowState.Minimized;
            }
        }

        private void btnCloseAnotherWindow_Click(object sender, RoutedEventArgs e)
        {
            GUIA obj = new GUIA(false);
            obj.Show();
        }

    }
}

Upvotes: 1

gretro
gretro

Reputation: 2009

Create a task in the Windows Scheduler at the program's first run or at the install time (if possible). You can create a batch script that will do it for you. You may consult this link to learn how to work with schtasks. There a are a number of parameters that you can set in the Scheduler to allow to launch the application at session login.

As for starting your application in "minimized" mode, you will need to implement it yourself. When the application starts, you may pass parameters to the application. You should create a property that will tell your application to launch in minimized mode. To read the arguments from the Command line, you may consult this other post.

Example : C:\apps\Foo.exe -minimized

Good luck

Upvotes: 2

jmcilhinney
jmcilhinney

Reputation: 54417

You should design your app to accept a commandline parameter to indicate that it starts in the minimised state. Your startup commandline can then pass that argument and you can decide how to start based on whether it's present and/or its value.

Upvotes: 0

Related Questions