www.pudn.com > goodchessGame.zip > FiveInOne.cpp


// FiveInOne.cpp : Defines the class behaviors for the application. 
// 
 
#include "stdafx.h" 
#include "FiveInOne.h" 
 
#include "MainFrm.h" 
#include "FiveInOneDoc.h" 
#include "StaticCredit.h" 
#include "Language.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CFiveInOneApp 
 
BEGIN_MESSAGE_MAP(CFiveInOneApp, CWinApp) 
	//{{AFX_MSG_MAP(CFiveInOneApp) 
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
		//    DO NOT EDIT what you see in these blocks of generated code! 
	//}}AFX_MSG_MAP 
	// Standard file based document commands 
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) 
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CFiveInOneApp construction 
 
CFiveInOneApp::CFiveInOneApp() 
{ 
	// TODO: add construction code here, 
	// Place all significant initialization in InitInstance 
	 
	EnableHtmlHelp(); 
 
	m_pGameController = NULL; 
} 
 
CFiveInOneApp::~CFiveInOneApp() 
{ 
	if (m_hSingleInstanceSemaphore) 
        CloseHandle (m_hSingleInstanceSemaphore); 
} 
///////////////////////////////////////////////////////////////////////////// 
// The one and only CFiveInOneApp object 
 
CFiveInOneApp theApp; 
 
///////////////////////////////////////////////////////////////////////////// 
// CFiveInOneApp initialization 
 
BOOL CFiveInOneApp::InitInstance() 
{ 
	 
	//if (!IsOnlyInstance()) 
	//	return FALSE;   // Cannot run more than one instance on same machine  
 
 
	// 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("Mitesh and Family Software Company")); 
 
 
	LoadStdProfileSettings();  // Load standard INI file options (including MRU) 
 
	// Register the application's document templates.  Document templates 
	//  serve as the connection between documents, frame windows and views. 
 
	int Ret = -1; 
	Ret = m_OptionsDlg.DoModal(); 
	if(Ret != IDOK) 
		return FALSE; 
 
	CSingleDocTemplate* pDocTemplate = NULL; 
 
	switch(m_OptionsDlg.m_nGameID) 
		{ 
		case COptionsDialog::GAME_MARRIAGE: 
			{ 
				if(m_OptionsDlg.m_nPlayNetwork == 0) 
				{ 
					pDocTemplate = new CSingleDocTemplate( 
						IDR_MAINFRAME, 
						RUNTIME_CLASS(CFiveInOneDoc), 
						RUNTIME_CLASS(CMainFrame),       // main SDI frame window 
						RUNTIME_CLASS(CMarriageGameNetworkController)); 
				} 
				else 
				{ 
					pDocTemplate = new CSingleDocTemplate( 
						IDR_MAINFRAME, 
						RUNTIME_CLASS(CFiveInOneDoc), 
						RUNTIME_CLASS(CMainFrame),       // main SDI frame window 
						RUNTIME_CLASS(CMarriageGameSingleCompController)); 
				} 
				break; 
			} 
		case COptionsDialog::GAME_CALLBREAK: 
			{ 
				if(m_OptionsDlg.m_nPlayNetwork == 0) 
				{ 
					pDocTemplate = new CSingleDocTemplate( 
						IDR_MAINFRAME, 
						RUNTIME_CLASS(CFiveInOneDoc), 
						RUNTIME_CLASS(CMainFrame),       // main SDI frame window 
						RUNTIME_CLASS(CCallBreakGameNetworkController)); 
				} 
				else 
				{ 
					pDocTemplate = new CSingleDocTemplate( 
						IDR_MAINFRAME, 
						RUNTIME_CLASS(CFiveInOneDoc), 
						RUNTIME_CLASS(CMainFrame),       // main SDI frame window 
						RUNTIME_CLASS(CCallBreakGameSingleCompController)); 
				} 
			 
			} 
			break; 
		case COptionsDialog::GAME_HEARTS: 
			{ 
			} 
		case COptionsDialog::GAME_POPLU: 
			{ 
			} 
		case COptionsDialog::GAME_TWENTYNINE: 
			{ 
			} 
		} 
 
	if(pDocTemplate == NULL) 
		return FALSE; 
	AddDocTemplate(pDocTemplate); 
 
	// Parse command line for standard shell commands, DDE, file open 
	CCommandLineInfo cmdInfo; 
	ParseCommandLine(cmdInfo); 
 
	// Dispatch commands specified on the command line 
	if (!ProcessShellCommand(cmdInfo)) 
		return FALSE; 
 
	// The one and only window has been initialized, so show and update it. 
	m_pMainWnd->ShowWindow(SW_MAXIMIZE); 
	m_pMainWnd->UpdateWindow(); 
 
	m_pGameController =(CGameController*)(((CMainFrame*)AfxGetMainWnd())->GetActiveView()); 
	m_pGameController->Begin(); 
	return TRUE; 
} 
 
BOOL CFiveInOneApp::IsOnlyInstance () 
{ 
 
#define SINGLE_INSTANCE_SEM_NAME        "FiveInOneAppSingleInstanceSemaphore" 
 
    m_hSingleInstanceSemaphore = OpenSemaphore (SEMAPHORE_ALL_ACCESS, TRUE, SINGLE_INSTANCE_SEM_NAME); 
    if (NULL != m_hSingleInstanceSemaphore) 
    {   // Other instance exists 
        AfxMessageBox (IDS_SINGLE_INSTANCE, MB_OK | MB_ICONEXCLAMATION); 
        return FALSE; 
    } 
 
    m_hSingleInstanceSemaphore = CreateSemaphore (NULL, 0, 1, SINGLE_INSTANCE_SEM_NAME); 
    if (NULL != m_hSingleInstanceSemaphore) 
        return TRUE; 
 
    DWORD dwErr = GetLastError (); 
    CString cstr; 
    cstr.Format ("Cannot create semaphore : %d", dwErr); 
    AfxMessageBox (cstr,MB_OK | MB_ICONHAND); 
    return FALSE; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
 
static CString gstrCopyright = TEXT("1.0|Copyright (C) 2003|by Mitesh Raj Pandey|shailaj@mail.com.np||"); 
 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
	void LoadAllStrings(); 
 
// 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 
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
	CStaticCredit m_Credits; 
	CString m_strCredits; 
 
	//{{AFX_MSG(CAboutDlg) 
	afx_msg void OnClose(); 
	virtual BOOL OnInitDialog(); 
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	//}}AFX_DATA_INIT 
} 
 
void CAboutDlg::LoadAllStrings() { 
	CString strLicense; 
	VERIFY(CLanguage::LoadString(strLicense, IDS_License)); 
	CString strConcept; 
	VERIFY(CLanguage::LoadString(strConcept, IDS_Concept)); 
	CString strWarrantee; 
	VERIFY(CLanguage::LoadString(strWarrantee, IDS_Warrantee)); 
	CString strDisclosure; 
	VERIFY(CLanguage::LoadString(strDisclosure, IDS_Disclosure)); 
	CString strCredits; 
	VERIFY(CLanguage::LoadString(strCredits, IDS_Credits)); 
 
	VERIFY(CLanguage::LoadString(m_strCredits, AFX_IDS_APP_TITLE)); 
 
	m_strCredits +=TEXT("\t|")  
				 + gstrCopyright 
				 + strLicense 
				 + strConcept 
				 + strWarrantee 
				 + strDisclosure 
				 + strCredits 
				 + TEXT("|||||||||||||||||||") 
				 ; 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	//}}AFX_DATA_MAP 
 
	if( ! pDX->m_bSaveAndValidate ) 
		m_Credits.SetCredits(m_strCredits, '|'); 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
	ON_WM_CLOSE() 
	ON_WM_SHOWWINDOW() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
// App command to run the dialog 
void CFiveInOneApp::OnAppAbout() 
{ 
	CAboutDlg aboutDlg; 
	aboutDlg.DoModal(); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CFiveInOneApp message handlers 
 
void CAboutDlg::OnClose()  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	m_Credits.EndScrolling(); 
 
	CDialog::OnClose(); 
} 
 
BOOL CAboutDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	 
	LoadAllStrings(); 
 
	m_Credits.SubclassDlgItem(IDC_Credits, this); 
	m_Credits.SetSpeed(DISPLAY_MEDIUM); 
	m_Credits.SetTransparent(); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CAboutDlg::OnShowWindow(BOOL bShow, UINT nStatus)  
{ 
	CDialog::OnShowWindow(bShow, nStatus); 
	 
	// TODO: Add your message handler code here 
	 
	UpdateData(FALSE); 
	m_Credits.StartScrolling(); 
} 
 
LRESULT CAboutDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	 
	if (message == WM_SYSCOMMAND && (wParam & 0xFFF0) == SC_MOVE)  
	{ 
		return 0;  
	}  
	 
	return CDialog::WindowProc(message, wParam, lParam); 
}