简体   繁体   中英

How to minimize application as soon as it started?

How can I minimize application as soon as it starts up to run it at the background in Windows Mobile 6? I want to minimize application it is launch automatically (ie auto-starts) and when later, if user wants to see application, it can run from the Program menu etc.

I tried some of the code but it does not work!

Traditional minimize scheme, although it will not solve my problem as using this code will never show the application to the user again (even this code does not work)

private void GUI_Load(object sender, EventArgs e)
{                    
     this.Hide();
     this.Visible = false;
}

and second option is to call native API (source: http://www.blondmobile.com/2008/04/windows-mobilec-how-to-minimize-your_5311.html )

private void GUI_Load(object sender, EventArgs e)
{                    
     this.HideApplication();
}

[DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_MINIMIZED = 6;

public void HideApplication()
{
      ShowWindow(this.Handle, SW_MINIMIZED);
}

Second code does work from any other part of the program, but not from Load Event.

The only solution I thought is using System.Windows.Forms.Timer and It works

private void GUI_Load(object sender, EventArgs e)
{                        
// Initialize timer to hide application when automatically launched
_hideTimer = new System.Windows.Forms.Timer();
_hideTimer.Interval = 0; // 0 Seconds
_hideTimer.Tick += new EventHandler(_hideTimer_Tick);
_hideTimer.Enabled = true;
}

// Declare timer object
System.Windows.Forms.Timer _hideTimer;
void _hideTimer_Tick(object sender, EventArgs e)
{
    // Disable timer to not use it again
    _hideTimer.Enabled = false;
    // Hide application
    this.HideApplication();
    // Dispose timer as we need it only once when application auto-starts
    _hideTimer.Dispose();
}

[DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_MINIMIZED = 6;

public void HideApplication()
{
      ShowWindow(this.Handle, SW_MINIMIZED);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM