How do you run a program from C++? I know how to do it in VB, but I don't know what to use to do it in C++, anything similar to Shell="c:\~~~~\*.exe", vbnormalfocus and such?
Printable View
How do you run a program from C++? I know how to do it in VB, but I don't know what to use to do it in C++, anything similar to Shell="c:\~~~~\*.exe", vbnormalfocus and such?
Use the ShellExecute API. You also need to include windows.h header.
Code:HWND hWnd = FindWindow (NULL,"appname"); //if you don't know the HWND
ShellExecute(hWnd,"open" ,"c:\\windows\\notepad.exe",NULL,NULL,SW_SHOW );
I think the WinExec api is easier to understand for this task.
It's in kernel32 and think it's available in C++.
Here's an example.
Ps: Vlatko, I don't think the ShellExecute really needs the hWnd parameter, I used it in VB just by passing 0&, should work too (I'm at my work now so I can't test)
[Edited by Jop on 01-08-2001 at 12:56 PM]
The hWnd parameter has its own value here. Receiving errors in a form of a message box.
MSDN:
Code:hwnd
Window handle to a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.
Thanks! didn't even know that :rolleyes: