Minimize application on startup

  • Thread starter Thread starter Star
  • Start date Start date
S

Star

Hi all,

I have been browsing the newsgroups trying to find the way
of doing that, but unfortunately everything that I tried didn't work.

I tried placing Hide() or Visible = false in the Form_Load event.

Basically I just need to hide the application as soon as your start it.
Once is running, if you click on the shortcut application it should show up.

Is there an easy way of doing that?

Thanks
 
Define "shortcut application" for us. I don't have a good idea of what the
operation of the application looks like. You might want to indicate what
platform you are targeting, too.

Paul T.
 
You can try getting the desktop window and then sending it to the foreground,
this effectively brings up the today screen:

SetForegroundWindow( GetDesktopWindow());

Create a timer in your Activate method for initial activation. Then on timer
event, kill the timer and call the above pInvoke methods.

you can find the pInvoke definitions on pinvoke.net. I hope this helps.

Regards,
Rick D.
Contractor
 
thanks for your help.

I tried what you suggested but the problem is I still see the form for
one second before disappears. I cannot make the timer interval smaller
because in that case doesn't work. I would need something that doesn't
show the form at all.

Here is my code:


private void FormMain_Activated(object sender, EventArgs e)
{
if (!m_bInitialized)
{
preventSleepTimer = new System.Threading.Timer(new
System.Threading.TimerCallback(PokeDeviceToKeepAwake),
null, 5000, System.Threading.Timeout.Infinite);
m_bInitialized = true;
}
}

private void PokeDeviceToKeepAwake(object extra)
{
try
{
preventSleepTimer.Dispose();
preventSleepTimer = null;


Utils.Generic.SetForegroundWindow(Utils.Generic.GetDesktopWindow());
}
catch
{

}
}


Thanks
 
Define "shortcut application" for us.

I mean when you click on the icon in the Program's Folder where the
shortcut of my application is located. In summary, if you call my
application again needs to be visible again.
You might want to indicate what
platform you are targeting, too.

I'm using VS2005, C#, Windows Mobile 5.0 pocket PC target device,
Compact Framework 2.0, desktop Windows XP...

anything else that you need?

Thanks
 
Define "shortcut application" for us.
I mean when you click on the icon in the Program's Folder where the
shortcut of my application is located. In summary, if you call my
application again needs to be visible again.

But, it's not visible to begin with, no? You want it to come up initially
invisible, but to behave differently if it's already running? If so, that
seems strange, but sending the application to the background, per Rick's
suggestion. I don't think that there's any way to have a form-based
application where the form is initially invisible (that doesn't surprise me,
as I can't figure out why you'd want it to work that way myself). It would
be possible to do this from unmanaged code where you have more direct
control over the window's state...
I'm using VS2005, C#, Windows Mobile 5.0 pocket PC target device,
Compact Framework 2.0, desktop Windows XP...

anything else that you need?

Thanks

Paul T.
 
Sorry, I think my English is not too good.

It's very simple. When you start the application it will start
minimized. If you ACTIVATE it again, it will show up. As simple as that.

My program is a GPS tracker that reads data from a GPS. If you set an
option in the configuration, the program will start minimized and
reading values from the GPS, so you don't have to worry about minimizing
manually.
 
It's a known limitation in amnaged code. Application.Run always calls SHow
on the Form passed in.

The upcoming new release of the Smart Device Framework (version 2.2, due out
before the year is over) has a provision for running without showing, but we
achieved it only through creating our own message pump and application
startup routine to prevent it from using the one in the CF. There's no
other way to do it (that we've found anyway).


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com
 
Thanks for the information.

Regards






- Show quoted text -

Star,

I too am writing my own GPS tracking application (probably like a LOT
of other people) and am interested in this also.

What I want to achieve is my application to run in the background, and
take it's settings from a config file. I then have a different UI
application that allows the user to set the configuration settings
(which includes setting when to stop and start tracking, etc.). Any
result on your query or advice on my text would be appreciated!
 
And doing that would just change the position of your window in the z-order.
It could still be shown later.

Wait for OpenNETCF 2.2 or get the older ApplicationEx class from OpenNETCF
and modify the code, this is what we done and it works great. Sometimes the
framework is too helpful for its own good! ;)
 
You have to modify the source code for Application2.Run to launch the
application without showing the Form passed into the Run command. It has
nothing to do with creating a Filter or a Windows Procedure.

SDF 2.2 will include an overload that does this and will be out soon.


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com
 
Back
Top