Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
580 views
in Technique[技术] by (71.8m points)

winapi - how can I run an external program In C?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...