473,387 Members | 1,483 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.

Equivalent ShellExecute in C++/CLI or NET

Hello,

Somebody knows which is the equivalent one in C++/CLI ?

HINSTANCE ShellExecute(HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);

--
Tomas
Apr 14 '07 #1
5 10963
"Tomas" <To***@newsgroup.nospamwrote in message
news:65**********************************@microsof t.com...
Somebody knows which is the equivalent one in C++/CLI ?

HINSTANCE ShellExecute(HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
You create a Process object. In that object you insert some startup
information (see the ProcessStartInfo class) - specifically the fact that
the process exists to "open" a file and the name of the file. Then you call
the Start method on the process object. The example below (oops - in C#)
runs Notepad to open the file foo.txt

Regards,
Will
www.ivrforbeginners.com

using System;
using System.Diagnostics;

namespace Test
{
class Test
{
static void Main(string[] args)
{
Process p;
ProcessStartInfo pInfo;

pInfo = new ProcessStartInfo();
pInfo.Verb = "open";
pInfo.FileName = "c:\\foo.txt";
pInfo.UseShellExecute = true;

p = Process.Start(pInfo);
}
}
}


Apr 14 '07 #2
William,

Since when has C# been C++?

You can do exactly what you said in 3 line of code in C#/VB.NET because you
can say (VB.NET code):

If IO.File.Exists("C:\Foo.txt") = True Then
System.Diagnostics.Process.Start("C:\Foo.txt")
End If

or if you want:

If IO.File.Exists("C:\Foo.txt") = True Then
System.Disagnotics.Process.Start("C:\Foo.txt")

Which now is 1 line of code being an inline 'If' statement

As Open is the default verb in 'notepad.exe %1' you don't need to declare
the ProcessStartInfo. Plus, you do not need to use ShellExecute either
because the process will start a new instance of notepad launching what txt
file you passed to it

but the user wanted C/C++ & probably not managed Framework code either.

--
Newbie Coder
(It's just a name)

"William DePalo [MVP VC++]" <wi***********@mvps.orgwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Tomas" <To***@newsgroup.nospamwrote in message
news:65**********************************@microsof t.com...
Somebody knows which is the equivalent one in C++/CLI ?

HINSTANCE ShellExecute(HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);

You create a Process object. In that object you insert some startup
information (see the ProcessStartInfo class) - specifically the fact that
the process exists to "open" a file and the name of the file. Then you
call
the Start method on the process object. The example below (oops - in C#)
runs Notepad to open the file foo.txt

Regards,
Will
www.ivrforbeginners.com

using System;
using System.Diagnostics;

namespace Test
{
class Test
{
static void Main(string[] args)
{
Process p;
ProcessStartInfo pInfo;

pInfo = new ProcessStartInfo();
pInfo.Verb = "open";
pInfo.FileName = "c:\\foo.txt";
pInfo.UseShellExecute = true;

p = Process.Start(pInfo);
}
}
}


Apr 15 '07 #3
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
Since when has C# been C++?
That's a pretty stupid question. Where did you read that I or anyone else
said that it was?
You can do exactly what you said in 3 line of code in
C#/VB.NET because you can say (VB.NET code):
So what?
As Open is the default verb in 'notepad.exe %1' you don't need to declare
the ProcessStartInfo. Plus, you do not need to use ShellExecute either
because the process will start a new instance of notepad launching what
txt
file you passed to it
No kidding? The OP asked about the .Net framework equivalent of Win32's
ShellExecute(). I could have simply pointed him to the framework classes in
question and told him he needed to set the UseShellExecute flag. Instead I
gave him a copy of C# compilable code. Sorry I disappointed you.

I could have given him C++, but didn't for three reasons.

1) I don't like to post code I haven't compiled and didn't have the time
when I posted to open up the IDE and build a sample.
2) There are two managed variants of C++, and I don't know which one he is
using.
3) For small tasks that make use of the framework, the difference between C#
and C++ is little more than syntatctic sugar for competent developers.

That said, this is the C++/CLI equivalent of the C# I posted:

// Process.cpp : main project file.

#include "stdafx.h"

using namespace System;
using namespace System::Diagnostics;

int main(array<System::String ^^args)
{
Process ^p;
ProcessStartInfo ^pInfo;

pInfo = gcnew ProcessStartInfo();
pInfo->Verb = "open";
pInfo->FileName = "c:\\foo.txt";
pInfo->UseShellExecute = true;

p = Process::Start(pInfo);
}

Regards,
Will

Apr 15 '07 #4
Thanks Will, this is what I looking for.

--
Tomas
English is not my first language.
Excuse me the inconvenients.
Apr 15 '07 #5
You can also just use the SHELL keyword

Example:

Shell("C:\SomePath\SomeFile.txt", AppWinStyle.NormalFocus)
Shell("C:\SomePath\SomeFile.txt", AppWinStyle.NormalFocus, True,
1000)

True in the second example is WaitForExit & the integer of 1000 is how many
milliseconds to wait

--
Newbie Coder
(It's just a name)

"William DePalo [MVP VC++]" <wi***********@mvps.orgwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
Since when has C# been C++?

That's a pretty stupid question. Where did you read that I or anyone else
said that it was?
You can do exactly what you said in 3 line of code in
C#/VB.NET because you can say (VB.NET code):

So what?
As Open is the default verb in 'notepad.exe %1' you don't need to
declare
the ProcessStartInfo. Plus, you do not need to use ShellExecute either
because the process will start a new instance of notepad launching what
txt
file you passed to it

No kidding? The OP asked about the .Net framework equivalent of Win32's
ShellExecute(). I could have simply pointed him to the framework classes
in
question and told him he needed to set the UseShellExecute flag. Instead I
gave him a copy of C# compilable code. Sorry I disappointed you.

I could have given him C++, but didn't for three reasons.

1) I don't like to post code I haven't compiled and didn't have the time
when I posted to open up the IDE and build a sample.
2) There are two managed variants of C++, and I don't know which one he is
using.
3) For small tasks that make use of the framework, the difference between
C#
and C++ is little more than syntatctic sugar for competent developers.

That said, this is the C++/CLI equivalent of the C# I posted:

// Process.cpp : main project file.

#include "stdafx.h"

using namespace System;
using namespace System::Diagnostics;

int main(array<System::String ^^args)
{
Process ^p;
ProcessStartInfo ^pInfo;

pInfo = gcnew ProcessStartInfo();
pInfo->Verb = "open";
pInfo->FileName = "c:\\foo.txt";
pInfo->UseShellExecute = true;

p = Process::Start(pInfo);
}

Regards,
Will



Apr 17 '07 #6

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

Similar topics

0
by: Marcel Sammut | last post by:
Greetings, I am converting a VB6 application to .net and am having troubles trying to print a document directley to the printer. My VB6 app used the API ShellExecute method to accomplish this,...
3
by: Wiktor Zychla | last post by:
I have a problem I cannot solve. My application hosts IE activex control. I follow the standard procedure: I just aximp shdocvw.dll. Note that this gives you two files: axshdocvw.dll and...
1
by: MCzajk | last post by:
Is there a function similar to ShellExecute, which I can hook to when the program is started using Start Menu icon? MCzajk
11
by: Le, Thanh-Nhan | last post by:
Hi, Is there a same function in .Net as API shellexecute? Thanks Nhan
0
by: the_openFace | last post by:
I'm trying to display the shell's property page for various files and I'm using this code: class Win32Shell { // ... other stuff here public static extern Int32 ShellExecute( Int32 hwnd,...
0
by: the openBack | last post by:
I'm trying to display the shell's property page for various files and I'm using this code: class Win32Shell { // ... other stuff here public static extern Int32 ShellExecute( Int32 hwnd,...
0
by: David | last post by:
We have an mfc application in which we use ShellExecute to launch the browser with an initial web site. {ShellExecute( NULL, "open", "http://www.SomeWebSite.com", NULL, NULL, SW_SHOWNORMAL ) } ...
2
by: John Smith | last post by:
Hi, I have an access database form with an image. I'm trying to create an onclick event on the image so that when a user clicks on the image it opens that file with the default viewer the...
2
by: Diego Armando Maradona | last post by:
Hi, I am using toshiba tec sx8 thermal printer for printing our labels, in My old Delphi application I was using such code; ShellExecute(0,'open',Data.cmdbuffer, PChar('/c copy...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.