Click here to Skip to main content
15,892,809 members
Articles / Desktop Programming / MFC

Single Instance Application

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
31 Oct 20023 min read 117.7K   1.3K   39  
An example approach to solving the single instance application problem with command line argument passing.
// Singleton.h : main header file for the SINGLETON application
//

#if !defined(AFX_SINGLETON_H__418129AE_FFE7_40DE_B3A3_13A7BD3C44FD__INCLUDED_)
#define AFX_SINGLETON_H__418129AE_FFE7_40DE_B3A3_13A7BD3C44FD__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"		// main symbols
#include "singleinstance.h"		

/////////////////////////////////////////////////////////////////////////////
// CSingletonApp:
// See Singleton.cpp for the implementation of this class
//
class CSingletonApp : public CWinApp, public CSingleInstance
{
public:
	CSingletonApp();
	virtual ~CSingletonApp();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSingletonApp)
	public:
	virtual BOOL InitInstance();
	virtual void WakeUp ( LPCTSTR aCommandLine ) const ;

	//}}AFX_VIRTUAL

// Implementation

	//{{AFX_MSG(CSingletonApp)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SINGLETON_H__418129AE_FFE7_40DE_B3A3_13A7BD3C44FD__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
Developing windows applications for over 15 years now starting on Win 3.1 with Object Oriented Pascal, progressed to C++ and OWL, in 1996 switch to MFC and never looked back, now focusing on .NET/Mono.

Comments and Discussions