Hi All,
I really thought, there would be some help by the experts I am not of
this
type], but I have stored some - for me importent - resoures.
Try the code [C#] at the end, it works for me.
Hope, this helps,
Best regards,
Manfred Braun
(Private)
Mannheim
Germany
mailto:
[email protected]
(Remove the anti-spam-underscore to mail me!)
===================================================================
/*
Compile: csc /t:exe /out

ualTest2.exe DualTest2.cs
from
http://www.dotnet247.com/247reference/msgs/17/88693.aspx
Other console-realted code was published by Matthias Sjögren.
*/
using System;
using System.IO;
using System.Diagnostics;
using System.Configuration;
using System.Runtime.InteropServices; //Needed for WIN32API-calls.
using System.Threading;
using System.Windows.Forms;
class DualTest
{
private static string strAppName = "DualTest";
public static bool useWindow = false;
public static Form Form1 = new Form();
public static int intFreeConsoleRTC;
static int Main(string[] args)
{
//Read application specific settings:
try
{
useWindow =
bool.Parse(ConfigurationSettings.AppSettings["AlwaysUseWindow"]);
}
catch(System.Exception)
{}
if( (args.Length == 0) || (useWindow) )
{
Console.WriteLine("No args, using a window...");
intFreeConsoleRTC = FreeConsole();
if(intFreeConsoleRTC != 0)
{
try
{
/*
The Thread.Sleep() demonstrates, that the console is detached.
If one
starts this proggi with a doubleclick in windows explorer, first,
a console window opens. After calling "FreeConsole()", the
console window disappears. The delay is made, to show this effect,
because opening the form is delayed.
*/
Thread.Sleep(2500);
//First method, de-commented now:
Application.Run(Form1);
//This could also be used!
//System.Windows.Forms.MessageBox.Show("Hello, world!");
}
catch(Exception e)
{
//Do something here
}
}
else
{
//The console was NOT detached for some reasons, we can continue
writing
there...
Console.WriteLine("Console was NOT freed, reason:" +
intFreeConsoleRTC );
}
return 1;
}
else
{
//We use the existing arguments and proceed...
Console.WriteLine(strAppName + ", have all, NOT using a window.");
return 0;
}
}
[DllImport("kernel32.dll")]
private static extern int FreeConsole(); //BOOL FreeConsole(VOID);
}
===================================================================
Thank you ... this is what i was trying to get at ...
So you must have two apps if you would like "typical" console
interaction ...
Thanks,
Jim
William Stacey [MVP] wrote:
A common pattern to achieve this is:
- Create two apps. One gui and one console by the same name and put
them in
the same directory.
- Name the console version *.com and the gui *.exe. The .com will be
found
first in the normal search order so you console app will start first.
- Your console app will parse the command line. If console args, the
app
continues as your normal.
- If args dictate GUI args, you Process start the *.exe command in
same
dir
passing in the args.
This will allow your console version to use the parent console as you
would
expect (i.e. no new console). And will also allow you to start the
GUI
version based on args and leave the current console intact. A
desktop
icon
or start menu would point the exe version if you wanted gui. From
console
you could also specify *.exe if you wanted direct access to the gui
version.
hth