Creating an App that runs as both Console and GUI

L

Lobsterpants

Hi folks,

I am developing an application that will either:
1. Run completly through the GUI (no command line options set)
2. Run completly through the command line
3. Allow the user to default some options through the command line and
then open the GUI with these options set.

I can acheve all of this EXCEPT when I run I always get a console
window even if I have gone straight into the gui. Is there a way to
acheve what I am after as I have googled like crazy and not got close -
here is what I have so far:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static void Main(string[] Args)
{
Arguments CommandLine=new Arguments(Args);
//help
if(CommandLine["h"] != null)
{
Console.WriteLine("output help...");
}
else
{
frmmyForm myForm = new frmmyForm();
if(CommandLine["Flag"] != null)
{
myForm.SetUserFlag = true; //default a field on the form
}
//out File
if(CommandLine["O"] != null)
{
myForm.OutFile = CommandLine["O"];
myForm.GoSpoodle(); //we have enough info so do the proccessing
}
else
{
Application.Run (myForm);
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All help gratefully received
 
T

Tim Haughton

Hi folks,

I am developing an application that will either:
1. Run completly through the GUI (no command line options set)
2. Run completly through the command line
3. Allow the user to default some options through the command line and
then open the GUI with these options set.

The type of application is specified at build time with the /target switch.

You could however lauch a command line app, and that could decide whether or
not to launch a seperate Windows app, then close, or carry on processing in
it's console window. You would have to factor out all common code into a
seperate assembly.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
 
O

Oliver Sturm

I am developing an application that will either:
1. Run completly through the GUI (no command line options set)
2. Run completly through the command line
3. Allow the user to default some options through the command line and
then open the GUI with these options set.

You should start by creating your application as a command line
application. You can open gui windows from it as you see fit. The
downside is that you'll normally have a Console window as well - but
it's possible to get rid of that. See this url (from Google groups) for
an example on how to use the FreeConsole API call to do this:

http://shrinkster.com/35v

Hope this helps!


Oliver Sturm
 
L

Lobsterpants

Thankyou Oliver and Tim,

I've tried Olivers solution and it exactly what I needed.

Thankyou both very much for your time.
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top