473,387 Members | 1,579 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,387 software developers and data experts.

Application and Console???

Is there anyway we can write an Application project and also have an option
for console where it take the command line for input?

Thanks
Nov 17 '05 #1
4 1274
Yes, it can be done using the AllocConsole API call (via P/Invoke). An
example can be found here:
http://www.pinvoke.net/default.aspx/...ocConsole.html

(Note, no matter how many times I correct that page, someone insists on
restoring the older, wrong information, so, if you don't see an example on
that page, check earlier revisions)

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"ttan" <tt**@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Is there anyway we can write an Application project and also have an option for console where it take the command line for input?

Thanks

Nov 17 '05 #2
Sure, it's not even hard. Just create a console project (so VS creates void
main) but also have your class inherit from System.Windows.Forms.Form. In
Main, do all required command line parsing to decide whether you want to run
as an app or in a console. For example, if the EXE is started with no
arguments you might want to run as an app. Or you could have a switch
indicating wether to start the UI or not. Create an instance of your form.
You can run this as a Windows app by using:

System.Windows.Forms.Application.Run(<instance of your form>);

If you don't want to start the UI, just use the form object as you would
work with any other class.

Hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"ttan" <tt**@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Is there anyway we can write an Application project and also have an
option
for console where it take the command line for input?

Thanks

Nov 17 '05 #3
thanks for the info, it help a lot.

"Kai Brinkmann [MSFT]" wrote:
Sure, it's not even hard. Just create a console project (so VS creates void
main) but also have your class inherit from System.Windows.Forms.Form. In
Main, do all required command line parsing to decide whether you want to run
as an app or in a console. For example, if the EXE is started with no
arguments you might want to run as an app. Or you could have a switch
indicating wether to start the UI or not. Create an instance of your form.
You can run this as a Windows app by using:

System.Windows.Forms.Application.Run(<instance of your form>);

If you don't want to start the UI, just use the form object as you would
work with any other class.

Hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"ttan" <tt**@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Is there anyway we can write an Application project and also have an
option
for console where it take the command line for input?

Thanks


Nov 17 '05 #4
thanks for the info, it help a lot.

"Kai Brinkmann [MSFT]" wrote:
Sure, it's not even hard. Just create a console project (so VS creates void
main) but also have your class inherit from System.Windows.Forms.Form. In
Main, do all required command line parsing to decide whether you want to run
as an app or in a console. For example, if the EXE is started with no
arguments you might want to run as an app. Or you could have a switch
indicating wether to start the UI or not. Create an instance of your form.
You can run this as a Windows app by using:

System.Windows.Forms.Application.Run(<instance of your form>);

If you don't want to start the UI, just use the form object as you would
work with any other class.

Hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"ttan" <tt**@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Is there anyway we can write an Application project and also have an
option
for console where it take the command line for input?

Thanks


Nov 17 '05 #5

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

Similar topics

7
by: Job Lot | last post by:
How can I terminate console application in Try…Catch…Finally…End Try block so that code in Finally gets executed. If I use End statement Finally does not get executed. Following is my code...
5
by: Mullin Yu | last post by:
i want to build an application of both gui and batch interface by using windows application project. i check either passing any args or not. if no, then open the gui application. if yes, use the...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
3
by: inpreet | last post by:
I am trying to build a console application in C#.Net. This application is suppose to run in background without user interaction. How can I hide console to appear?
6
by: Erez Shor | last post by:
Hi, I need to build and asp page which access a remote windows server's registry and create a registry key. In order for the ASP page to be able to access the registry on the remote server I need...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
0
by: Maxwell | last post by:
Hello, I recently completed a MC++ (VS2003) DLL that wraps a non MFC C++ DLL and need to use it in a MC++ Console Application (no forms/guis of any kind just output to console). Trouble is...
4
by: eduardorp1 | last post by:
I have a GUI application that needs to be invoked from the command line as well. It should work both as a GUI and as a console application. When I invoke it from the command line, it reads all...
6
by: tony | last post by:
Hello! When you have windows forms you have the same possibility as when you have a Console application to use Console.Writeln to write whatever on the screen. Now to my question: Is it...
0
by: Stephen Thomas | last post by:
Hi there I wonder if any one has encountered this problem or can suggest what is wrong. I am trying the a procedure from the msn site but get the following message: Error 1 The type or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.