我怎么能运行外部程序在C? [英] how can I run an external program In C?

查看:130
本文介绍了我怎么能运行外部程序在C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何运行C中的外部程序?对于像浏览器示例应用程序记事本等。还我怎么能设置外部应用程序的窗口一定规模?例如 300×300 像素的窗口大小。

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.

推荐答案

的标准方法是系统 - 工程pretty多任何地方,但让你无法控制在如何子进程中运行。

The standard way is system -- works pretty much anywhere, but gives you no control over how the child process runs.

在上升控制(和复杂性)的顺序,Windows提供了: 的WinExec 的ShellExecute 的ShellExecuteEx 的CreateProcess 。随着CreateProcess的你传递一个 STARTUPINFO STARTUPINFOEX 结构。无论哪种方式,您可以指定子窗口的起始位置和/或大小(虽然子进程可以和可以移动/调整它的窗口,它甚至可见之前)。

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

您也可能要考虑 升压过程 ,这是不接受升压的正式组成部分,但提供更多的控制比系统,同时保持合理的移植到相当数量的最广泛使用的系统(包括Windows和任何合理的POSIX状,如Linux或OS X)。

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

这篇关于我怎么能运行外部程序在C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆