Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,981 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,281 people online right now. Registration is fast and FREE... Join Now!




Running a separate program

 
Reply to this topicStart new topic

Running a separate program

aj32
5 Sep, 2007 - 02:07 PM
Post #1

D.I.C Addict
Group Icon

Joined: 30 Aug, 2007
Posts: 577



Thanked: 2 times
Dream Kudos: 675
My Contributions
I just started programming in Microsoft Visual C++ express edition 2005, I want to create a program that, when a button is pressed, it starts a different application. (I would also like an example code too, since I am new to VisualC++)
-Thanks!

This post has been edited by aj32: 5 Sep, 2007 - 02:08 PM
User is offlineProfile CardPM
+Quote Post

musya
RE: Running A Separate Program
5 Sep, 2007 - 02:41 PM
Post #2

D.I.C Regular
Group Icon

Joined: 25 Apr, 2007
Posts: 291



Thanked: 1 times
Dream Kudos: 50
My Contributions
QUOTE(aj32 @ 5 Sep, 2007 - 03:07 PM) *

I just started programming in Microsoft Visual C++ express edition 2005, I want to create a program that, when a button is pressed, it starts a different application. (I would also like an example code too, since I am new to VisualC++)
-Thanks!


Please show some code, but as for running a program you can use the system command system("c://Program Files/Quicktime/QuickTimePlayer.exe")

That will run the quicktime player executable for running the quicktime player program
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Running A Separate Program
5 Sep, 2007 - 02:51 PM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,179



Thanked: 208 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
To open other files and start other programs is rather easy in VC++ 2005. All you need to do is include the statement using namespace System::Diagnostics; at the top of your project and then use the "Process" object to start the program or open a file using its default program.

Here is an example...

CODE

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
       Process^ myprocess = gcnew Process();
       myprocess->StartInfo->FileName = "c:\\WINDOWS\\Notepad.exe";
       myprocess->Start();
}


If you have notepad in your windows directory (where it is usually at) then it will start notepad right up. We create an instance of the Process object, we set its Filename of the StartInfo property and then start it.

Hope this makes sense to you. smile.gif
User is online!Profile CardPM
+Quote Post

Amadeus
RE: Running A Separate Program
5 Sep, 2007 - 03:01 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 36 times
Dream Kudos: 25
My Contributions
That applies to using managed C++...the user may well be using standard C++.
User is online!Profile CardPM
+Quote Post

Martyr2
RE: Running A Separate Program
5 Sep, 2007 - 03:14 PM
Post #5

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,179



Thanked: 208 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Yes, yes they may. But if they are doing a windows application in VC++ 2005, he could very well be using managed. It is all good. cool.gif

This post has been edited by Martyr2: 5 Sep, 2007 - 03:15 PM
User is online!Profile CardPM
+Quote Post

Amadeus
RE: Running A Separate Program
5 Sep, 2007 - 03:20 PM
Post #6

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 36 times
Dream Kudos: 25
My Contributions
Agreed...I'm just noting that a windows application is still far more likely to be done in standard C++, even using VC++ 2005. As long as the user is aware that the code is applicable only to .NET Managed C++ applications, he'll be fine.
User is online!Profile CardPM
+Quote Post

aj32
RE: Running A Separate Program
5 Sep, 2007 - 03:56 PM
Post #7

D.I.C Addict
Group Icon

Joined: 30 Aug, 2007
Posts: 577



Thanked: 2 times
Dream Kudos: 675
My Contributions
QUOTE

To open other files and start other programs is rather easy in VC++ 2005. All you need to do is include the statement using namespace System::Diagnostics; at the top of your project and then use the "Process" object to start the program or open a file using its default program.





Ok, What file should I put the code into?

PS: What is the difference between "managed c++" and "Standard c++? mellow.gif "
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Running A Separate Program
5 Sep, 2007 - 05:30 PM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 36 times
Dream Kudos: 25
My Contributions
http://en.wikipedia.org/wiki/Managed_Extensions_for_C++

http://www.ondotnet.com/pub/a/dotnet/2003/.../intromcpp.html

Managed C++, or more properly Managed Extensions for C++ is an implementation of the language meant to take advantage of the .NET object library and CLI. To date, it has not proven too popular, but who knows what the future will bring. It has often been viewed as an attempt by Microsoft to bring C++ coders on board with the .NET platform.
User is online!Profile CardPM
+Quote Post

aj32
RE: Running A Separate Program
6 Sep, 2007 - 03:29 AM
Post #9

D.I.C Addict
Group Icon

Joined: 30 Aug, 2007
Posts: 577



Thanked: 2 times
Dream Kudos: 675
My Contributions
I figured out how to use the code Martyr2 gave me.
Now I would like to know how to use a text box for user input (of the location of the file to open)and open it.

I am using managed C++. thumbs-up.gif
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Running A Separate Program
6 Sep, 2007 - 03:57 AM
Post #10

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 36 times
Dream Kudos: 25
My Contributions
You may actually wish to walk through a few tutorials on using managed C++ to create GUIs...here are a couple:

http://www.codeproject.com/managedcpp/mcppwinforms01.asp

http://www.codeproject.com/managedcpp/

Also, remember that the program will only run on computers with the .NET framework installed (or an emulator).
User is online!Profile CardPM
+Quote Post

aj32
RE: Running A Separate Program
6 Sep, 2007 - 11:30 AM
Post #11

D.I.C Addict
Group Icon

Joined: 30 Aug, 2007
Posts: 577



Thanked: 2 times
Dream Kudos: 675
My Contributions
Thanks Amadeus, those tutorials you gave me are a really good help, Thanks. icon_up.gif
User is offlineProfile CardPM
+Quote Post

aj32
RE: Running A Separate Program
6 Sep, 2007 - 02:54 PM
Post #12

D.I.C Addict
Group Icon

Joined: 30 Aug, 2007
Posts: 577



Thanked: 2 times
Dream Kudos: 675
My Contributions
Can someone show me how to use Text input boxes in visual C++?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:34AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month