Rick,

How do you manage to get this result is beyond me.

When I use the exact same code (and that approach was my first thought
anyway), I get both a new console window _and_ a form.  Don't want the
console window to open up though :) - only if I intend to have _no_ UI at
all.

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Rick Taylor
Sent: Monday, July 25, 2005 9:07 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] WinForms _and_ console mode

I may not be understanding exactly what you are after, but, as a test, I
created a new console app in the IDE. To that, I added a reference to
System.Windows.Forms.dll. From there, I created a new form named TestForm,
and added some controls to it. From there, I altered my main method to look
like (entire class here)

using System;
using System.Windows.Forms;
namespace MixedAppTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
if (args.Length>0)
{
Application.Run(new MixedAppTest.TestForm()); } else {
Console.WriteLine("Hello there"); Console.ReadLine(); } // // TODO: Add code
to start application here // } } } (comcast web interface is messing with my
formatting, paste into new class and it should be ok). If I launch the app
from the command line with no params, I get the command line prompt. If I
include any params, I get the form.
does that help? I'm not sure if this is what you are after.



-------------- Original message --------------

> I think the typical way to do this is with staged executables.
>
> devenv (the command line utility for the Visual Studio IDE) is
> actually two executables. When you type devenv on the command line,
> you're actually running the command line version, which will spawn the
> true Windows app as necessary. To do this, there's two executables:
> devenv.comand
> devenv.exe. From a command prompt, the .com file has precedence (it's
> really just a renamed .exe; it doesn't have to be a .com file). When
> run from the shell (i.e., start/run), the .exe file has precendence.
>
> I think you'll end up having to do the same thing.
>
> On 7/25/05, Kamen Lilov wrote:
> >
> > I have a WinForms app. When started directly (without cmd line
> > parameters), I want it to be a regular application - it displays a
> > main form and works as expected.
> >
> > When invoked with certain parameters, however, I want it to be
> > treated as a
> > Win32 console app. I want to be able to do Console.Write and emit
> > the output in the command session where the app was started. I know
> > I can PInvoke and call AllocConsole but this is _not_ what my
> > intention is. The console of my caller (e.g. the cmd.exe prompt)
> > should be the one that gets my output, and I want the application to
> > execute fully before control is returned to the console - or to the next
app in a batch file.
> >
> > How do I approach this?
> >
>
> --
> Brad Wilson
> http://www.dotnetdevs.com/
> http://www.agileprogrammer.com/dotnetguy/
>
> Peter: "Oh my god, Brian, there's a message in my Alphabits. It says,
> 'Oooooo.' "
> Brian: "Peter, those are Cheerios."
> - Family Guy
>
> ===================================
> This list is hosted by DevelopMentor- http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com

===================================
This list is hosted by DevelopMentor-  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to