JCHub

  • Home
  • Category
    • A/V
    • WebRTC
    • Beauty of Programming
    • Linux
    • Windows
    • Moments of Life
    • Campus Life
  • Reference
    • API Reference
    • Utilities
    • AV Test
    • Doc
  • Message Board
  • About
JCHub
Code as My Sword, Lost in Obsession
  1. Main page
  2. Windows
  3. Main content

VC实现程序单实例运行

2015年11月25日 1990hotness 0likes 0comments

有时候我们希望我们的程序只能运行一个实例。常见的一个方法是通过创建互斥对象实现。在主程序中加入如下代码即可实现:

1
2
3
4
5
6
7
HANDLE h = CreateMutex(NULL, FALSE, L"程序名");
if ((NULL != h) && (GetLastError() == ERROR_ALREADY_EXISTS))
{
CloseHandle(h);
MessageBox(NULL, L"程序已经运行", L"提示", NULL);
ExitProcess(0);
}

This article is licensed with Creative Commons Attribution-NonCommercial-No Derivatives 4.0 International License
Tag: VC++
Last updated:2017年6月11日

Jeff

管理员——代码为剑,如痴如醉

Tip the author Like
< Last article
Next article >

Comments

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
Cancel

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts
  • Visual Studio检查内存泄露方法
  • 如何让MFC或其他VS编译的程序支持高DPI
  • 使用libVLC实现的播放器:支持双击全屏
  • FireBreath插件IE浏览器中文字符乱码问题
  • 基于FireBreath的npapi插件在Firefox下的调试
Categories

COPYRIGHT © 2026 jianchihu.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang