wxShell,wxExecute vs. Windows ShellExecute

694 views
Skip to first unread message

Carsten A. Arnholm

unread,
Nov 23, 2010, 3:02:34 PM11/23/10
to wx-u...@lists.wxwidgets.org
Hi,

I am using wxMSW and wxGTK 2.8.11

In my old Windows programs I sometimes do this to open a file with the
program the user has associated with the file type
ShellExecute(NULL,"open",filepath, NULL, NULL, SW_SHOWNORMAL);

Is there a way to do the same in wxWidgets, that would work for wxMSW and
wxGTK?

On Windows I got this to work, however it also gave me a terminal window I
didn't want
::wxShell(filepath);
The above didn't work on Linux.

Instead I tried,
::wxExecute(filepath);
with much the same result

This worked for text files
::wxExecute(wxT("notepad ") + filepath); // Windows
::wxExecute(wxT("kate ") + filepath); // Linux

... but obviously the solution isn't common to Windows & Linux and it isn't
respecting the users choice of editor. Plus it doesn't work for other file
types.

Is there some way to open a file using the program defined by the file type
association in the OS? perhaps. something along the lines of
::wxExecute(filepath,wxEXEC_OPEN);

..to be a portable way of achieving the same as the ShellExecute example
above?

--
Carsten A. Arnholm
http://arnholm.org/
N59.7758 E10.4576

Carsten A. Arnholm

unread,
Nov 23, 2010, 5:43:21 PM11/23/10
to wx-u...@lists.wxwidgets.org
Carsten A. Arnholm wrote:
> Is there some way to open a file using the program defined by the
> file type association in the OS? perhaps. something along the lines of
>>> wxExecute(filepath,wxEXEC_OPEN);
>
> ..to be a portable way of achieving the same as the ShellExecute
> example above?

I can see now that the exec sample has something that appears to be what I
am looking for (OnFileExec function).

Vadim Zeitlin

unread,
Nov 23, 2010, 6:01:24 PM11/23/10
to wx-u...@googlegroups.com
On Tue, 23 Nov 2010 21:02:34 +0100 "Carsten A. Arnholm" <arn...@online.no> wrote:

CAA> I am using wxMSW and wxGTK 2.8.11

You're out of luck, wxLaunchDefaultApplication() is in 2.9 only. In 2.8
you'll need to use wxMimeTypesManager manually, as the exec sample does (as
you already discovered).

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Carsten A. Arnholm

unread,
Nov 24, 2010, 2:11:56 AM11/24/10
to wx-u...@lists.wxwidgets.org

"Vadim Zeitlin" <va...@wxwidgets.org> wrote in message
news:E1PL1rd-...@smtp.tt-solutions.com...

CAA> I am using wxMSW and wxGTK 2.8.11

VZ> You're out of luck, wxLaunchDefaultApplication() is in 2.9 only. In 2.8
VZ> you'll need to use wxMimeTypesManager manually, as the exec sample does
(as
VZ> you already discovered).
VZ>
VZ> Regards,
VZ> VZ

Ok, many thanks, then I have the information requested. Nice to know this
will be even better in 2.9.

Again, thanks for the quick reply.

Carsten Arnholm

Reply all
Reply to author
Forward
0 new messages