// test_onlyOneExe.cpp : Defines the class behaviors for the application.
#include "stdafx.h"
#include "test_onlyOneExe.h"
#include "test_onlyOneExeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CTest_onlyOneExeApp
BEGIN_MESSAGE_MAP(CTest_onlyOneExeApp, CWinApp)
//{{AFX_MSG_MAP(CTest_onlyOneExeApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/
// CTest_onlyOneExeApp construction
CTest_onlyOneExeApp::CTest_onlyOneExeApp()
29.{
30. // TODO: add construction code here,
31. // Place all significant initialization in InitInstance
32.}
33.
34./
35.// The one and only CTest_onlyOneExeApp object
36.
37.CTest_onlyOneExeApp theApp;
38.
39./
40.// CTest_onlyOneExeApp initialization
41.
42.BOOL CTest_onlyOneExeApp::InitInstance()
43.{
44. if(!IsFirstInstance("test_onlyOneExe"))
45. return false;
46.
47. AfxEnableControlContainer();
48.
49. // Standard initialization
50. // If you are not using these features and wish to reduce the size
51. // of your final executable, you should remove from the following
52. // the specific initialization routines you do not need.
53.
54.#ifdef _AFXDLL
55. Enable3dControls(); // Call this when using MFC in a shared DLL
56.#else
57. Enable3dControlsStatic(); // Call this when linking to MFC statically
58.#endif
59.
60. CTest_onlyOneExeDlg dlg;
61. m_pMainWnd = &dlg;
62. int nResponse = dlg.DoModal();
63. if (nResponse == IDOK)
64. {
65. // TODO: Place code here to handle when the dialog is
66. // dismissed with OK
67. }
68. else if (nResponse == IDCANCEL)
69. {
70. // TODO: Place code here to handle when the dialog is
71. // dismissed with Cancel
72. }
73.
74. // Since the dialog has been closed, return FALSE so that we exit the
75. // application, rather than start the application's message pump.
76. return FALSE;
77.}
78.
BOOL CTest_onlyOneExeApp::IsFirstInstance(CString title)
{
CWnd *pWndPrev, *pWndChild;
if (pWndPrev = CWnd::FindWindow(NULL,title))
{
//AfxMessageBox( _TEXT("只允许一个实例在运行!"));