473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Compile Options

A.M
Hi,

I need to develop an application that acts as both consolde or windows
formas application based on command line args.

If have two choice as compiler output options: Console Application or
Windows Application.

If I choose Console Application as compiler output, and then I run the
application in windows mode,it shows a blank black window and the dialog box
window.
If I choose Windows Application, Then the application can not run in console
mode and [Console.Write] or [Console.Read] won't work.

Is it possible that a windows form application can also show a console
window?

Thanks,
Alan

Nov 16 '05 #1
6 1543
A.M wrote:
If I choose Console Application as compiler output, and then I run the
application in windows mode,it shows a blank black window and the
dialog box window.
Yup, the process is marked as requiring a console, so windows will always
create a console for it.
If I choose Windows Application, Then the application can not run in
console mode and [Console.Write] or [Console.Read] won't work.


Ah, but Consol.In and Console.Out can be replaced with TextReader/TextWriter
(use SetIn and SetOut methods), so you can direct Console Read/Write to your
TextReader/TextWriter, I've attached some very bare bones code that shows
this:

using System;
using System.IO;
using System.Text;
using System.Windows.Forms;

// Basic dialog that displays the text
class GUIConsole : Form
{
ListBox lb;
public GUIConsole()
{
lb = new ListBox();
lb.Dock = DockStyle.Fill;
this.Controls.Add(lb);
}
public void WriteLine(string s)
{
// this is not satisfactory, it ignores newlines in the string
lb.Items.Add(s);
}
}

// Very basic text writer, need to implement WriteLines that take data types
other
// than string, need to implement Write
class Writer : TextWriter
{
GUIConsole cons;
public Writer(GUIConsole cons)
{
this.cons = cons;
cons.Show();
}
public override Encoding Encoding
{
get{ return null; }
}
public override void Close()
{
cons.Visible = false;
base.Close();
}
// All of the dormatted WriteLines call this
public override void WriteLine(string s)
{
cons.WriteLine(s);
}
}

// Application form
class App : Form
{
GUIConsole console;
App()
{
console = new GUIConsole();
Console.SetOut(new Writer(console));
this.Click += new EventHandler(this.click);
}
// If you click on the form, it test will be printed on the 'console'
void click(object o, EventArgs args)
{
Console.WriteLine("test");
}
static void Main()
{
Application.Run(new App());
}
}

Richard
--
..NET training, development, consulting and mentoring
my email ev******@zicf.bet is encrypted with ROT13 (www.rot13.org)
sign up for my free .NET newsletter at
http://www.wd-mag.com/newsletters/
Nov 16 '05 #2
Compile it as Console application - this doesn't prevent you from showing
Windows Forms as well.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
"A.M" <no*****@online.nospam> schrieb im Newsbeitrag
news:uw**************@TK2MSFTNGP15.phx.gbl...
Hi,

I need to develop an application that acts as both consolde or windows
formas application based on command line args.

If have two choice as compiler output options: Console Application or
Windows Application.

If I choose Console Application as compiler output, and then I run the
application in windows mode,it shows a blank black window and the dialog box window.
If I choose Windows Application, Then the application can not run in console mode and [Console.Write] or [Console.Read] won't work.

Is it possible that a windows form application can also show a console
window?

Thanks,
Alan

Nov 16 '05 #3
A.M
Thank you for help.

If you do thar, The problem is you always have a blank console window beside
the winforms window!

Alan
"cody" <pl*************************@gmx.de> wrote in message
news:uc**************@TK2MSFTNGP09.phx.gbl...
Compile it as Console application - this doesn't prevent you from showing
Windows Forms as well.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
"A.M" <no*****@online.nospam> schrieb im Newsbeitrag
news:uw**************@TK2MSFTNGP15.phx.gbl...
Hi,

I need to develop an application that acts as both consolde or windows
formas application based on command line args.

If have two choice as compiler output options: Console Application or
Windows Application.

If I choose Console Application as compiler output, and then I run the
application in windows mode,it shows a blank black window and the dialog

box
window.
If I choose Windows Application, Then the application can not run in

console
mode and [Console.Write] or [Console.Read] won't work.

Is it possible that a windows form application can also show a console
window?

Thanks,
Alan


Nov 16 '05 #4
Hi AM,

As for the scenario you mentioned, I think Richard's suggestion on defining
a customer "Stream" object (the GUIConsole) and redirect our winform
application's Console output to the "GUIConsole" is considerable. Richard
use a "listbox" as the output in its sample, you can event directly
display console 's output on your main form.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 16 '05 #5
You mean you want to let it pop up if you want, not seeing it all the time?
Well, you could call cmd.exe/command.com and get its window handle
(interop). But writing something in there will surely be not easy.
Why don't you simply create an additional normal winforms window and put a
multiline textbox in there? You can also make it look like the original
command window.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"A.M" <no*****@online.nospam> schrieb im Newsbeitrag
news:OV**************@tk2msftngp13.phx.gbl...
Thank you for help.

If you do thar, The problem is you always have a blank console window beside the winforms window!

Alan
"cody" <pl*************************@gmx.de> wrote in message
news:uc**************@TK2MSFTNGP09.phx.gbl...
Compile it as Console application - this doesn't prevent you from showing Windows Forms as well.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
"A.M" <no*****@online.nospam> schrieb im Newsbeitrag
news:uw**************@TK2MSFTNGP15.phx.gbl...
Hi,

I need to develop an application that acts as both consolde or windows
formas application based on command line args.

If have two choice as compiler output options: Console Application or
Windows Application.

If I choose Console Application as compiler output, and then I run the
application in windows mode,it shows a blank black window and the
dialog box
window.
If I choose Windows Application, Then the application can not run in

console
mode and [Console.Write] or [Console.Read] won't work.

Is it possible that a windows form application can also show a console
window?

Thanks,
Alan



Nov 16 '05 #6
Hi Alan,

Have you considered Richard's suggestion on Redirect the Console's output
to our custom Writer? Here is a simple demo I built through Richard's
suggestion which redirect the "Console" output to the Main Winform, just as
the console:
================================================== ====
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;

namespace GUIConsoleApp
{
public class GUIConsoleForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtConsole;
private System.ComponentModel.Container components = null;
private GUIConsoleWriter writer = null;

public GUIConsoleForm()
{
InitializeComponent();
writer = new GUIConsoleWriter(this);
Console.SetOut(writer);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

public void WriteLine(string str)
{
txtConsole.Text = txtConsole.Text + System.Environment.NewLine + str;
txtConsole.SelectionStart=this.txtConsole.Text.Len gth;
txtConsole.ScrollToCaret();
}
#region Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë

private void InitializeComponent()
{
this.txtConsole = new System.Windows.Forms.TextBox();
this.SuspendLayout();

this.txtConsole.BackColor =
System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(0)),
((System.Byte)(64)));
this.txtConsole.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtConsole.ForeColor = System.Drawing.Color.White;
this.txtConsole.Location = new System.Drawing.Point(0, 0);
this.txtConsole.Multiline = true;
this.txtConsole.Name = "txtConsole";
this.txtConsole.ReadOnly = true;
this.txtConsole.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtConsole.Size = new System.Drawing.Size(544, 317);
this.txtConsole.TabIndex = 0;
this.txtConsole.Text = "";
this.txtConsole.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.txtCon sole_MouseDown);

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.ClientSize = new System.Drawing.Size(544, 317);
this.Controls.Add(this.txtConsole);
this.Name = "GUIConsoleForm";
this.Text = "GUIConsole";
this.Load += new System.EventHandler(this.GUIConsoleForm_Load);
this.ResumeLayout(false);

}
#endregion
[STAThread]
static void Main()
{
Application.Run(new GUIConsoleForm());
}
private void GUIConsoleForm_Load(object sender, System.EventArgs e)
{
Console.WriteLine("Form Load!");
}

private void txtConsole_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Console.WriteLine("MouseDown at (" + e.X + " , " + e.Y + ")");
}
}

class GUIConsoleWriter : TextWriter
{
GUIConsoleForm _console;

public GUIConsoleWriter(GUIConsoleForm console)
{
this._console = console;
}
public override Encoding Encoding
{
get{ return null; }
}
public override void Close()
{
_console.Visible = false;
base.Close();
}

public override void WriteLine(string s)
{
_console.WriteLine(s);
}
}

}
==========================================

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Brian | last post by:
Greetings: I am trying to compile the following code via command line. It compiles just fine in visual studio 2002 v7 so i took looked at the properties and i got the following command line...
10
by: Curt Emich | last post by:
I'm trying to create a dataset. I start by creating a connection. Then I create and configure a data adapter. Finally, I select "generate dataset" after right-clicking on the data adapter. It...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
12
by: JS | last post by:
I use winXP and have installed Cygwin. I use Dev-C++ and the Cygwin compiler, but for some reason I can't compile this code: #include <setjmp.h> #include <stdio.h> #include <stdlib.h> ...
3
by: Michael | last post by:
Hi! Is it possible to check the active solution configuration (debug, release or some user defined) at compile time using for example preprocessor directives? Best regards, Michael
1
by: Raterus | last post by:
Hi, Is there a way I can see what commands VS.net is using to compile my asp.net projects? I'm sure its using the vbc/csc programs, but I'd love to see the command-line options it is using. ...
5
by: MLH | last post by:
A97 aborts creation of MDE reporting that there's a compile error in one form. Sure enough, if I remove the form from the source database and attempt to compile the MDE, it succeeds. But when I...
5
by: DFB | last post by:
I am the author of the ZLibNetWrapper project on SourceForge (located at zlibnetwrapper.sf.net). This project is a simple mixed-mode .NET wrapper around the ZLib compression library. The ZLib...
3
by: NvrBst | last post by:
Right now I have C99 code in .c extensions. I compile it in VSC++ and it complains about a lot of errors. I change the extensions to .cpp and compile in VSC++ and it succeeds. Is there a way...
1
by: Jon | last post by:
We have a web site that has been running at a customer site for over a year...all of the sudden last week on one page we get the following error Timed out waiting for a program to execute. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.