//*****************************************
//******** PC Configurator V1.00 **********
//*** (C) - 2001 B.Bowling/A. Grippo ******
//** All derivatives from this software ***
//**  are required to keep this header ****
//*****************************************

static char *rcsId() { return "$Id$"; }

#include "stdafx.h"
#include "megatune.h"
#include "megatuneDlg.h"
#include "msDatabase.h"

extern msDatabase mdb;

#ifdef _DEBUG
#  define new DEBUG_NEW
#  undef THIS_FILE
   static char THIS_FILE[] = __FILE__;

#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif

//------------------------------------------------------------------------------
// CMegatuneApp

BEGIN_MESSAGE_MAP(CMegatuneApp, CWinApp)
   //{{AFX_MSG_MAP(CMegatuneApp)
	ON_COMMAND(ID_APP_EXIT, OnAppExit)
	//}}AFX_MSG_MAP
   ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

//------------------------------------------------------------------------------
// CMegatuneApp construction

CMegatuneApp::CMegatuneApp()
{
   // TODO: add construction code here,
   // Place all significant initialization in InitInstance
}

//------------------------------------------------------------------------------
// The one and only CMegatuneApp object

CMegatuneApp theApp;

//------------------------------------------------------------------------------
// CMegatuneApp initialization

BOOL CMegatuneApp::InitInstance()
{
#ifdef _DEBUG
   int iFlags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
   iFlags |= _CRTDBG_ALLOC_MEM_DF;
   iFlags |= _CRTDBG_CHECK_ALWAYS_DF;
   //iFlags |= _CRTDBG_DELAY_FREE_MEM_DF;
   iFlags |= _CRTDBG_CHECK_CRT_DF;
   iFlags |= _CRTDBG_LEAK_CHECK_DF;
   _CrtSetDbgFlag(iFlags);
#endif

   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

#ifdef _DEBUG
   _CrtMemState state;
   _CrtMemCheckpoint(&state);
#endif

   if (m_lpCmdLine[0]) {
      mdb.settingsFile = m_lpCmdLine;
      mdb.settingsFile.Remove('"');
      mdb.readSettings();
   }

   CMegatuneDlg dlg;
   m_pMainWnd    = &dlg;
   int nResponse =  dlg.DoModal();

   if (nResponse == IDOK) {
      // TODO: Place code here to handle when the dialog is
      //  dismissed with OK
   }
   else if (nResponse == IDCANCEL) {
      // TODO: Place code here to handle when the dialog is
      //  dismissed with Cancel
   }

#ifdef _DEBUG
   int stat = _CrtCheckMemory();
//   stat = _CrtMemDumpMemoryLeaks();
   _CrtMemDumpStatistics(&state);
#endif

   // Since the dialog has been closed, return FALSE so that we exit the
   //  application, rather than start the application's message pump.
   return FALSE;
}

//------------------------------------------------------------------------------

void CMegatuneApp::OnAppExit()
{
#ifdef _DEBUG
   int stat = _CrtCheckMemory();
//   stat = _CrtMemDumpMemoryLeaks();
#endif
}

