Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...