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);
If the first parameter on the
startcommand 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
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
startcommand is to use theShellExecute()orShellExecuteEx()Win32 API.