在vc ++ mfc中一次只运行一个exe实例 [英] Run only one instance of exe at a time in vc++ mfc

查看:232
本文介绍了在vc ++ mfc中一次只运行一个exe实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框应用程序,我想一次运行一次该应用程序exe,即当我运行该应用程序的exe时,我无法同时打开同一应用程序的另一个实例。如何? div class =h2_lin>解决方案

只需检查您的InitInstance方法(或程序开头的任何其他位置)是否已运行具有此名称的进程。如果是这样,退出。



快速偶然发现



如何检查应用程序是否已在运行 [ ^ ]


请参阅MSDN文章如何编写支持Windows XP中快速用户切换的应用程序 [ ^ ]。 检测现有应用程序实例部分描述了如何添加代码以检查另一个实例是否已在其他用户启动时运行。





避免应用程序的多个实例 [ ^ ]。

[/ EDIT]

I have an dialog application and I want to run that application exe once at a time i.e. when I run the exe of that application then I can not open another instance of the same application at the same time.How can ??

解决方案

Just check on your InitInstance method (or anywhere else at the start of your program) whether a process with this name is already running. If so, exit.

Stumbled upon this quickly

How to check if an application is already running [^]


See the MSDN article How to write an application that supports fast user switching in Windows XP[^]. The section Detect an Existing Application Instance describes how to add code to check if another instance is already running even when started by another user.

[EDIT]
An example with good explanations can be also found at Avoiding Multiple Instances of an Application[^].
[/EDIT]


这篇关于在vc ++ mfc中一次只运行一个exe实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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