Although I actually think that having main() in its own class is a good idea (and, apparently, so does Microsoft, as this is the default way a lot of things are created in Whidbey) I don't think it is a *necessary* change to make this type of application happen. The normal restrictions on main() would apply -- publicly accessible, static, must return int or void -- but I don't believe there is anything in a class derived from the Form or UserControl objects which would interfere with an application running as a console application.
I think more on the quux of the matter is that Application.Run() is what manages windows forms, and that console operations can be done as well with a preliminary call to Console.OpenStandardOutput(). I am curious as to what differences there are between Kamen's code and mine. That should boil it right down to bare essentials for the answer to this one. -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Peter Ritchie Sent: Monday, July 25, 2005 1:24 PM To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] WinForms _and_ console mode To outline, for those who would like to create an application that supports console and WinForms in the most straight-foward way: Create a console application. Create a form class (Select meny Project/Add Windows Form...) Where you want the form to be displayed add code similar to the following: Application.Run(new ApplicationNamespaceName.FormClassName()); If starting from a WinForms-based application, the Main() method should be moved to a non-Form-derived class; On Mon, 25 Jul 2005 18:06:53 +0000, Rick Taylor <[EMAIL PROTECTED]> wrote: >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? >> > >> =================================== This list is hosted by DevelopMentorR 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