A Single-Instance Application Class - 项目摘要 |
摘要
| 管理 |
论坛 文档
| 软件包 |
|
|
|
项目描述: |
Making single-instance an application means enabling the application to recognize, at startup, if another running instance of itself exists so that, in this case, the application stops its execution. Generally, before quitting, the new instance retrieves the main window handle of the existing instance via the FindWindow() or FindWindowEx() function and uses this handle to bring the application window to foreground.
The problem can be solved in several ways. The most known solutions are:
Using a CMutex (a synchronization object global to the system).
Using shared data sections.
The small class described in this article, CSingleInstanceApp, uses the first method to implement the single-instance behaviour in a MFC application. It makes very simple to add the feature to a new project, eliminating the necessity of rewriting a consistent amount of code.
生成单实例应用程序是应用程序在启动时可以检测是否有同一程序正在运行,如果有,则这个程序就停止运行。一般,在退出之前,新实例使用FindWindow() 或FindWindowEx()检查现存实例的主窗口的句柄,使用这个句柄将应用程序窗口设置到前台。
这一问题可以有多种方法,最常见的是:
-使用CMutex(一个系统的全局同步对象)。
-使用共享数据段
这个项目中的这个小类(CSingleInstanceApp)使用第一种方法在MFC应用程序中实现单实例应用程序的功能。可以简单地将这一功能加到新项目中,不需要重写代码。
来源: http://www.codeguru.com/misc/single_instance_app.shtml |
类别: |
|
发布者:
cbd002
|
|
最新发布源码包 |
没有发布任何的软件包! |
|