帮忙解释一下这段vc++程序

BOOLCSnowWorldApp::InitInstance(){HANDLEhMutext=CreateMutex(NULL,TRUE,m_pszAppName);U... BOOL CSnowWorldApp::InitInstance()
{
HANDLE hMutext = CreateMutex( NULL, TRUE, m_pszAppName );
UNREFERENCED_PARAMETER( hMutext );
if ( GetLastError() == ERROR_ALREADY_EXISTS )
return FALSE;

AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));

// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object.

CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;

// create and load the frame with its resources

pFrame->LoadFrame(IDR_MAINFRAME,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);

// The one and only window has been initialized, so show and update it.
pFrame->CenterWindow();
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();

return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CSnowWorldApp message handlers

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CSnowWorldApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CSnowWorldApp message handlers
展开
 我来答
178752468
2009-11-03 · TA获得超过291个赞
知道小有建树答主
回答量:517
采纳率:0%
帮助的人:403万
展开全部
HANDLE hMutext = CreateMutex( NULL, TRUE, m_pszAppName );
UNREFERENCED_PARAMETER( hMutext );
if ( GetLastError() == ERROR_ALREADY_EXISTS )
return FALSE;
关键代码在上面几行
让程序始终只有一个实例运行
通过创建命名Mutex来判断是否程序已经运行,是则退出。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
yc_19861104
2009-11-03 · 超过20用户采纳过TA的回答
知道答主
回答量:55
采纳率:0%
帮助的人:0
展开全部
同意楼上看法,关键在于下面的代码:
HANDLE hMutext = CreateMutex( NULL, TRUE, m_pszAppName );
UNREFERENCED_PARAMETER( hMutext );
if ( GetLastError() == ERROR_ALREADY_EXISTS )
return FALSE;
其他的代码是MFC自己添加的。你如果想搞情况的话,可以看下孙鑫老师的《VC++深入详解》,挺好的。另外可以可以自己查看定义,设置断点。
上面的代码就是让程序只有一个实例。让程序创建一个互斥对象。这样让程序再有实力的时候就会自动退出。保持只有一个实例!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
原帅心甜02
2009-11-03 · TA获得超过418个赞
知道小有建树答主
回答量:419
采纳率:0%
帮助的人:297万
展开全部
MFC自带的。无视掉吧·····或者看看孙新童鞋的VC++深入详解
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式