0

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 ?

user3693167
  • 783
  • 1
  • 9
  • 16
  • in windows Loaded Event you can set this.WindowState= WindowState.Minimized. – Ashok Rathod Jul 17 '14 at 03:07
  • @AshokRathod But I want to do it only on start-up. When he double click the icon normally the GUI "A" should come. – user3693167 Jul 17 '14 at 03:18
  • yaa it will be done at startup only and you will be able to enable on just single click also – Ashok Rathod Jul 17 '14 at 03:24
  • @AshokRathod How to limit that to the startup only ? – user3693167 Jul 17 '14 at 05:08
  • you can take one application level static variable where you would define its startup event or anything else. whenever u want to open other then startup set that flag variable to false and hence you will be able to decide in loaded event that you had to minimize or not. – Ashok Rathod Jul 17 '14 at 05:10
  • @AshokRathod Okay. Thank you. I understand the logic. Could you support me any documentation of hot to do it ? :) – user3693167 Jul 17 '14 at 05:23
  • I had provided working code as answer.please check answer – Ashok Rathod Jul 17 '14 at 05:34
  • 1
    Take a look at this [Blog Article](http://blogs.msdn.com/b/avip/archive/2008/10/27/wpf-supporting-command-line-arguments-and-file-extensions.aspx) about command line arguments and wpf. and this [SO Question](http://stackoverflow.com/questions/9600453/command-line-arguments-in-c-sharp-application) – Mark Hall Jul 17 '14 at 05:38

3 Answers3

2

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

Community
  • 1
  • 1
gretro
  • 1,934
  • 15
  • 25
1
  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();
        }

    }
}
Ashok Rathod
  • 840
  • 9
  • 24
  • please mark it as answer if it really helps you.and please let me know if u still have any doubt – Ashok Rathod Jul 17 '14 at 05:36
  • Sure. Thank you for the answer. I have a doubt. How can the program knows whether its the start-up or not ? – user3693167 Jul 17 '14 at 06:30
  • 1
    @Ashok, please stop begging for acceptation. OP already knows how to accept answers and they surely decide when to do so. Thanks! P.S. you've shown just how to modify the C# app. with no mention how to schedule the app. to start at Windows startup (which should do the installer). – TLama Jul 17 '14 at 06:55
0

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.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46