[英]Create a background process in windows
How do I make a process go the background programatically? 如何使程序以编程方式进入后台?
What I want is for the user to double-click the process executable, and it just goes into the background ... and does not open a window while executing. 我想要的是用户双击流程可执行文件,它只是进入后台...而在执行时不会打开窗口。
Any code snippet in visual c++ would be very helpful Visual C ++中的任何代码片段都将非常有帮助
Have you considered creating a Windows Service instead? 您是否考虑过创建Windows服务 ? They're specifically designed to run in the background without showing a UI.
它们专门设计为在后台运行而不显示UI。
Otherwise, just create an application without a window . 否则,只需创建一个没有window的应用程序 。
I know this is old, but I thought I would post something for when people find this through search. 我知道这很老了,但是我想当人们通过搜索找到它时,我会发布一些东西。
While I like Cody Gray's answer for design correctness, sometimes you don't have a choice. 尽管我喜欢Cody Gray的设计正确性答案,但有时您别无选择。
If you want to launch a program without jumping to the new window (it appears in the background or minimized) or not create a window at all try looking at the ShellExecute
and ShellExecuteEx
functions. 如果要启动程序而不跳转到新窗口(它显示在后台或最小化),或者根本不创建窗口,请尝试查看
ShellExecute
和ShellExecuteEx
函数。 The argument nShowCmd
(or nShow
) gives you (among others) the options: 参数
nShowCmd
(或nShow
)为您提供了其他选择:
SW_HIDE
SW_HIDE
Hides the window and activates another window.
隐藏该窗口并激活另一个窗口。
SW_SHOWMINNOACTIVE
SW_SHOWMINNOACTIVE
Displays the window as a minimized window.
将窗口显示为最小化窗口。 The active window remains active.
活动窗口保持活动状态。
As the documentation says, SW_HIDE creates a process running the executable you give it, but if this program would normally create a window, none appears. 如文档所述, SW_HIDE将创建一个运行您提供的可执行文件的进程,但是如果该程序通常会创建一个窗口,则不会出现任何窗口。
这可能会有所帮助: http : //ss64.com/nt/start.html
I tried this way and it worked fine: Create a console application and write your codes in the sub main as any other console application. 我尝试过这种方法,它运行良好:创建一个控制台应用程序,并像其他任何控制台应用程序一样在子主目录中编写代码。 Now change the application type in the project properties to windows Forms application from Console application thats it
现在,将项目属性中的应用程序类型从控制台应用程序更改为Windows Forms应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.