How can I run an external program in C? For example application programs like a browser
, word
, Notepad
, etc. Also how can I set a certain size of the window of the external application program? For example a window size of 300 X 300
pixels.
The standard way is system
-- works pretty much anywhere, but gives you no control over how the child process runs.
In ascending order of control (and complexity), Windows provides: WinExec
, ShellExecute
, ShellExecuteEx
, and CreateProcess
. With CreateProcess you pass a STARTUPINFO
or STARTUPINFOEX
structure. Either way, you can specify the starting position and/or size for the child window (though the child process can and may move/resize its window before it's even visible).
You might also want to consider Boost Process
, which isn't accepted as an official part of Boost, but provides a bit more control than system
, while remaining reasonably portable to a fair number of the most widely used systems (including both Windows and anything reasonably POSIX-like, such as Linux or OS X).
You run and external program using system from the C standard library or the Win32 CreateProcess function.
To resize a the main window of an application you create. First start the process with CreateWindow. Then use EnumThreadWindows with the handle from CreateProcess to find the main window of that process. Finally, you can call MoveWindow with that handle to set the size and position.
you can use system function for this purpose like,
#include <stdlib.h>
int main()
{
system("your-program-name");
return 0;
}
This will be executed in command prompt.
But if you want to use winapi the best way is to use CreateProcess() function, http://msdn.microsoft.com/en-us/library/ms682425.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With