Reputation: 96807
I noticed that I can start a program with it's associated handler by writing start filename. However, for some files, all I get is a console, and I don't know why. I'm trying to populate a list control in MFC, and I want to have the program and it's associated handler to run when I double click the selection. Is there a better way, or an explanation to why this doesn't work?
This is the code that could be the problem:
int selection = listControl.GetCurSel();
CString text;
listControl.GetText(selection,text);
string std_str = StringUtils::CStringToString(text);
string st = string("start \"")+std_str+string("\"");
const char* command = st.c_str();
system(command);
Upvotes: 1
Views: 286
Reputation: 340208
If the first parameter on the start
command line is enclosed in double-quotes, it uses that as the window title instead of the command. It's lame, but that's what it does...
Try
string st = string("start \"\" \"")+std_str+string("\"");
instead.
But if you're trying to get the shell handler for a file to execute from within your process, a better, cleaner way to do this instead of invoking the start
command is to use the ShellExecute()
or ShellExecuteEx()
Win32 API.
Upvotes: 5
Reputation: 264391
I believe start uses the file handler associated with the file's extension.
Basically it will use the files extension to lookup what application to run.
It sounds like the extension to the files you are using are resulting in a default handler of the console being started.
You could start by reading the MS documentation:
http://msdn.microsoft.com/en-us/library/53ezey2s.aspx
Upvotes: 1