// SuperVisSheet.cpp : implementation file
//

#include "stdafx.h"
#include "supervis.h"
#include "SuperVisSheet.h"

#include "SNDinc.h"

#include "snddll.h"

#include "snddbg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSuperVisSheet

IMPLEMENT_DYNAMIC(CSuperVisSheet, CPropertySheet)

CSuperVisSheet::CSuperVisSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
	//Read config in ini file...
	ReadIniFile();
	
	AddControlPages();
}

CSuperVisSheet::CSuperVisSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
	
	//Read config in ini file...
	ReadIniFile();
	
	AddControlPages();
}


CSuperVisSheet::CSuperVisSheet()
	:CPropertySheet("SuperVisater99")
{
	
	//Read config in ini file...
	ReadIniFile();
	
	AddControlPages();
}

CSuperVisSheet::~CSuperVisSheet()
{
	//Save config in ini file...
	WriteIniFile();

}


BEGIN_MESSAGE_MAP(CSuperVisSheet, CPropertySheet)
	//{{AFX_MSG_MAP(CSuperVisSheet)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
	ON_COMMAND(IDC_QUIT, OnQuit)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSuperVisSheet message handlers

void CSuperVisSheet::GetIniFilePath()
{
	char szIniFile[256];
	char szDllDirectory[256]=".";

	strncpy(szDllDirectory,SND_fn_szGetSoftDirectory(),sizeof(szDllDirectory)-1);

	strncpy(szIniFile, szDllDirectory, sizeof(szIniFile) -1);
	strncat(szIniFile, "\\supervis.ini", sizeof(szIniFile) -1);

	m_cIniFile = szIniFile;

}

void CSuperVisSheet::ReadIniFile()
{

	CSupervisApp* pApp = (CSupervisApp*)AfxGetApp();

	char buffer[256];
	
	//Retrieve the .Ini path
	GetIniFilePath();

	//
	//Get the registry configuration
	//

	//Key for the application
	pApp->m_iActivePage = GetPrivateProfileInt("Settings", "ActivePage", 0, (LPCSTR)m_cIniFile);
	pApp->m_iWindowLeft = GetPrivateProfileInt("Settings", "WindowLeft", 232, (LPCSTR)m_cIniFile);
	pApp->m_iWindowTop = GetPrivateProfileInt("Settings", "WindowTop", 146, (LPCSTR)m_cIniFile);
	pApp->m_iWindowRight = GetPrivateProfileInt("Settings", "WindowRight", 1012, (LPCSTR)m_cIniFile);
	pApp->m_iWindowBottom = GetPrivateProfileInt("Settings", "WindowBottom", 855, (LPCSTR)m_cIniFile);
	
	//SuperVisSetting key
	GetPrivateProfileString("SettingsPage", "BinaryLCBPath", "NoLCBPath", buffer, sizeof(buffer) - 1, (LPCSTR)m_cIniFile);
	pApp->m_cBinaryLCBPath = buffer;
	GetPrivateProfileString("SettingsPage", "BinaryLCBFileTitle", "NoLCBFileTitle", buffer, sizeof(buffer) - 1, (LPCSTR)m_cIniFile);
	pApp->m_cBinaryLCBFileTitle = buffer;
	pApp->m_bWindowOnTop = GetPrivateProfileInt("SettingsPage", "AlwaysOnTop", FALSE, (LPCSTR)m_cIniFile);
	pApp->m_iRefreshRate = GetPrivateProfileInt("SettingsPage", "RefreshRate", 500, (LPCSTR)m_cIniFile);


	//Key for the Mixer Page
	pApp->m_MixerPageRegKeys.iCheckBankId= GetPrivateProfileInt("MixerPage", "CheckBankId", 0, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iCheckResId= GetPrivateProfileInt("MixerPage", "CheckResId", 0, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.bCheckFirstOccur= GetPrivateProfileInt("MixerPage", "CheckFirstOccur", 0, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iColTime= GetPrivateProfileInt("MixerPage", "ColTime", 77, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iColResName= GetPrivateProfileInt("MixerPage", "ColResName", 90, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iColResId= GetPrivateProfileInt("MixerPage", "ColResId", 35, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iColBankName= GetPrivateProfileInt("MixerPage", "ColBankName", 71, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iColBankId= GetPrivateProfileInt("MixerPage", "ColBankId", 54, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iColType = GetPrivateProfileInt("MixerPage", "ColType", 100, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iColVol= GetPrivateProfileInt("MixerPage", "ColVol", 50, (LPCSTR)m_cIniFile);
	pApp->m_MixerPageRegKeys.iColInfo= GetPrivateProfileInt("MixerPage", "ColInfo", 194, (LPCSTR)m_cIniFile);


	//Key for the EventsHistory Page
	pApp->m_EventPageRegKeys.iCheckBankId= GetPrivateProfileInt("EventHistoryPage", "CheckBankId", 0, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.iCheckEventId= GetPrivateProfileInt("EventHistoryPage", "CheckResId", 0, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.bCheckFirstOccur= GetPrivateProfileInt("EventHistoryPage", "CheckFirstOccur", 0, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.iColTime= GetPrivateProfileInt("EventHistoryPage", "ColTime", 75, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.iColEvtName= GetPrivateProfileInt("EventHistoryPage", "ColEvtName", 101, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.iColEvtId = GetPrivateProfileInt("EventHistoryPage", "ColEvtId", 52, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.iColBankName= GetPrivateProfileInt("EventHistoryPage", "ColBankName", 71, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.iColBankId= GetPrivateProfileInt("EventHistoryPage", "ColBankId", 51, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.iColEvtType = GetPrivateProfileInt("EventHistoryPage", "ColEvtType", 100, (LPCSTR)m_cIniFile);
	pApp->m_EventPageRegKeys.iColInfo = GetPrivateProfileInt("EventHistoryPage", "ColInfo", 212, (LPCSTR)m_cIniFile);

	//Key for the Micro&Object Page
	pApp->m_RegKeyMicPage.iColMicId= GetPrivateProfileInt("MicroPage", "iColMicId", 75, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColX= GetPrivateProfileInt("MicroPage", "iColX", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColY= GetPrivateProfileInt("MicroPage", "iColY", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColZ= GetPrivateProfileInt("MicroPage", "iColZ", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColNx= GetPrivateProfileInt("MicroPage", "iColNx", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColNy = GetPrivateProfileInt("MicroPage", "iColNy", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColNz= GetPrivateProfileInt("MicroPage", "iColNz", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColTx= GetPrivateProfileInt("MicroPage", "iColTx", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColTy = GetPrivateProfileInt("MicroPage", "iColTy", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyMicPage.iColTz = GetPrivateProfileInt("MicroPage", "iColTz", 60, (LPCSTR)m_cIniFile);

	pApp->m_RegKeyObjPage.iColObjId= GetPrivateProfileInt("ObjectPage", "iColObjId", 102, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyObjPage.iColX= GetPrivateProfileInt("ObjectPage", "iColX", 70, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyObjPage.iColY= GetPrivateProfileInt("ObjectPage", "iColY", 70, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyObjPage.iColZ= GetPrivateProfileInt("ObjectPage", "iColZ", 70, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyObjPage.iColFreq= GetPrivateProfileInt("ObjectPage", "iColFreq", 78, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyObjPage.iColVol = GetPrivateProfileInt("ObjectPage", "iColVol", 75, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyObjPage.iColAsso= GetPrivateProfileInt("ObjectPage", "iColAsso", 125, (LPCSTR)m_cIniFile);


	//Key for Volume Line & Theme Page
	pApp->m_RegKeyThemePage.iColVolId= GetPrivateProfileInt("ThemePage", "iColVolId", 200, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyThemePage.iColVol= GetPrivateProfileInt("ThemePage", "iColVol", 200, (LPCSTR)m_cIniFile);


	//Key for the Virtual Voices Page
	pApp->m_RegKeyVoicePage.iColVoiceId = GetPrivateProfileInt("VoicesPage", "iColVoiceId", 83, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyVoicePage.iColPaused = GetPrivateProfileInt("VoicesPage", "iColPaused", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyVoicePage.iColResPtr = GetPrivateProfileInt("VoicesPage", "iColResPtr", 75, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyVoicePage.iColResId = GetPrivateProfileInt("VoicesPage", "iColResId", 75, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyVoicePage.iColLoop= GetPrivateProfileInt("VoicesPage", "iColLoop", 45, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyVoicePage.iColNorm = GetPrivateProfileInt("VoicesPage", "iColNorm", 75, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyVoicePage.iColInstance = GetPrivateProfileInt("VoicesPage", "iColInstance", 68, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyVoicePage.iColAudibleV = GetPrivateProfileInt("VoicesPage", "iColAudibleV", 100, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyVoicePage.iColHardV = GetPrivateProfileInt("VoicesPage", "iColHardV", 100, (LPCSTR)m_cIniFile);


	//Key for the Wav Voices Page
	pApp->m_RegKeyWavVoicePage.iColWavVoiceId = GetPrivateProfileInt("WavVoicesPage", "iColWavVoiceId", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyWavVoicePage.iColResPtr = GetPrivateProfileInt("WavVoicesPage", "iColResPtr", 100, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyWavVoicePage.iColResId = GetPrivateProfileInt("WavVoicesPage", "iColResId", 75, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyWavVoicePage.iColPaused = GetPrivateProfileInt("WavVoicesPage", "iColPaused", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyWavVoicePage.iColVol = GetPrivateProfileInt("WavVoicesPage", "iColVol", 60, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyWavVoicePage.iColPan = GetPrivateProfileInt("WavVoicesPage", "iColPan", 75, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyWavVoicePage.iColSpace = GetPrivateProfileInt("WavVoicesPage", "iColSpace", 75, (LPCSTR)m_cIniFile);
	pApp->m_RegKeyWavVoicePage.iColFreq = GetPrivateProfileInt("WavVoicesPage", "iColFreq", 75, (LPCSTR)m_cIniFile);


}

void CSuperVisSheet::WriteIniFile()
{

	char buffer[256];

	CSupervisApp* pApp = (CSupervisApp*)AfxGetApp();

	//Key for the application
	sprintf(buffer, "%d", pApp->m_iActivePage);
	WritePrivateProfileString("Settings", "ActivePage", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_iWindowLeft);
	WritePrivateProfileString("Settings", "WindowLeft", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_iWindowTop);
	WritePrivateProfileString("Settings", "WindowTop", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_iWindowRight);
	WritePrivateProfileString("Settings", "WindowRight", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_iWindowBottom);
	WritePrivateProfileString("Settings", "WindowBottom", buffer, (LPCSTR)m_cIniFile);

	
	//SuperVisSetting key
	WritePrivateProfileString("SettingsPage", "LCBPath", (LPCSTR)(pApp->m_cBinaryLCBPath), (LPCSTR)m_cIniFile);
	WritePrivateProfileString("SettingsPage", "LCBFileTitle", (LPCSTR)(pApp->m_cBinaryLCBFileTitle), (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_bWindowOnTop);
	WritePrivateProfileString("SettingsPage", "AlwaysOnTop", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_iRefreshRate);
	WritePrivateProfileString("SettingsPage", "RefreshRate", buffer, (LPCSTR)m_cIniFile);



	//Key for the Mixer Page
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iCheckBankId);
	WritePrivateProfileString("MixerPage", "RefreshRate", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iCheckResId);
	WritePrivateProfileString("MixerPage", "CheckResId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.bCheckFirstOccur);
	WritePrivateProfileString("MixerPage", "CheckFirstOccur", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iColTime);
	WritePrivateProfileString("MixerPage", "ColTime", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iColResName);
	WritePrivateProfileString("MixerPage", "ColResName", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iColResId);
	WritePrivateProfileString("MixerPage", "ColResId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iColBankName);
	WritePrivateProfileString("MixerPage", "ColBankName", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iColBankId);
	WritePrivateProfileString("MixerPage", "ColBankId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iColVol);
	WritePrivateProfileString("MixerPage", "ColVol", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iColType);
	WritePrivateProfileString("MixerPage", "ColType", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_MixerPageRegKeys.iColInfo);
	WritePrivateProfileString("MixerPage", "ColInfo", buffer, (LPCSTR)m_cIniFile);


	//Key for the EventsHistory Page
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iCheckBankId);
	WritePrivateProfileString("EventHistoryPage", "CheckBankId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iCheckEventId);
	WritePrivateProfileString("EventHistoryPage", "CheckEventId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.bCheckFirstOccur);
	WritePrivateProfileString("EventHistoryPage", "CheckFirstOccur", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iColTime);
	WritePrivateProfileString("EventHistoryPage", "ColTime", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iColEvtName);
	WritePrivateProfileString("EventHistoryPage", "ColEvtName", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iColEvtId);
	WritePrivateProfileString("EventHistoryPage", "ColEvtId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iColBankName);
	WritePrivateProfileString("EventHistoryPage", "ColBankName", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iColBankId);
	WritePrivateProfileString("EventHistoryPage", "ColBankId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iColEvtType);
	WritePrivateProfileString("EventHistoryPage", "ColEvtType", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_EventPageRegKeys.iColInfo);
	WritePrivateProfileString("EventHistoryPage", "ColInfo", buffer, (LPCSTR)m_cIniFile);



	//Key for the Micro&Object Page
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColMicId);
	WritePrivateProfileString("MicroPage", "iColMicId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColX);
	WritePrivateProfileString("MicroPage", "iColX", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColY);
	WritePrivateProfileString("MicroPage", "iColY", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColZ);
	WritePrivateProfileString("MicroPage", "iColZ", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColNx);
	WritePrivateProfileString("MicroPage", "iColNx", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColNy);
	WritePrivateProfileString("MicroPage", "iColNy", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColNz);
	WritePrivateProfileString("MicroPage", "iColNz", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColTx);
	WritePrivateProfileString("MicroPage", "iColTx", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColTy);
	WritePrivateProfileString("MicroPage", "iColTy", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyMicPage.iColTz);
	WritePrivateProfileString("MicroPage", "iColTz", buffer, (LPCSTR)m_cIniFile);


	sprintf(buffer, "%d", pApp->m_RegKeyObjPage.iColObjId);
	WritePrivateProfileString("ObjectPage", "iColObjId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyObjPage.iColX);
	WritePrivateProfileString("ObjectPage", "iColX", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyObjPage.iColY);
	WritePrivateProfileString("ObjectPage", "iColY", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyObjPage.iColZ);
	WritePrivateProfileString("ObjectPage", "iColZ", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyObjPage.iColFreq);
	WritePrivateProfileString("ObjectPage", "iColFreq", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyObjPage.iColVol);
	WritePrivateProfileString("ObjectPage", "iColVol", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyObjPage.iColAsso);
	WritePrivateProfileString("ObjectPage", "iColAsso", buffer, (LPCSTR)m_cIniFile);


	//Key for Volume Line & Theme Page
	sprintf(buffer, "%d", pApp->m_RegKeyThemePage.iColVolId);
	WritePrivateProfileString("ThemePage", "iColVolId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyThemePage.iColVol);
	WritePrivateProfileString("ThemePage", "iColVol", buffer, (LPCSTR)m_cIniFile);
	

	//Key for the Virtual Voices Page
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColVoiceId);
	WritePrivateProfileString("VoicesPage", "iColVoiceId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColPaused);
	WritePrivateProfileString("VoicesPage", "iColPaused", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColResPtr);
	WritePrivateProfileString("VoicesPage", "iColResPtr", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColResId);
	WritePrivateProfileString("VoicesPage", "iColResId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColLoop);
	WritePrivateProfileString("VoicesPage", "iColLoop", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColNorm);
	WritePrivateProfileString("VoicesPage", "iColNorm", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColInstance);
	WritePrivateProfileString("VoicesPage", "iColInstance", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColAudibleV);
	WritePrivateProfileString("VoicesPage", "iColAudibleV", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyVoicePage.iColHardV);
	WritePrivateProfileString("VoicesPage", "iColHardV", buffer, (LPCSTR)m_cIniFile);



	//Key for the Wav Voices Page
	sprintf(buffer, "%d", pApp->m_RegKeyWavVoicePage.iColWavVoiceId);
	WritePrivateProfileString("WavVoicesPage", "iColWavVoiceId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyWavVoicePage.iColResPtr);
	WritePrivateProfileString("WavVoicesPage", "iColResPtr", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyWavVoicePage.iColResId);
	WritePrivateProfileString("WavVoicesPage", "iColResId", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyWavVoicePage.iColPaused);
	WritePrivateProfileString("WavVoicesPage", "iColPaused", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyWavVoicePage.iColVol);
	WritePrivateProfileString("WavVoicesPage", "iColVol", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyWavVoicePage.iColPan);
	WritePrivateProfileString("WavVoicesPage", "iColPan", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyWavVoicePage.iColSpace);
	WritePrivateProfileString("WavVoicesPage", "iColSpace", buffer, (LPCSTR)m_cIniFile);
	sprintf(buffer, "%d", pApp->m_RegKeyWavVoicePage.iColFreq);
	WritePrivateProfileString("WavVoicesPage", "iColFreq", buffer, (LPCSTR)m_cIniFile);


}



void CSuperVisSheet::AddControlPages()
{

	AddPage(&m_EventsHistoryPage);
	AddPage(&m_MixerPage);
	AddPage(&m_MicroAndObjectsPage);
	AddPage(&m_VoicesPage);
	AddPage(&m_WavVoicesPage);
	AddPage(&m_ThemesPage);
	AddPage(&m_SuperVisSettingPage);


}

BOOL CSuperVisSheet::OnInitDialog() 
{

	BOOL bResult = CPropertySheet::OnInitDialog();

	CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();

	 pSuperVisApp->m_SuperVisThread->m_bIsPSheettActive = TRUE;

	//
	//Little trick to add a button in a modeless CPropertySheet. A modeless
	//propertysheet doesnt have ok, cancel and apply buttons.
	//
	RECT rc;
	GetWindowRect (&rc);
	// Increase the height of the CPropertySheet by 30
	rc.bottom += 35;          
	// Resize the CPropertySheet

	MoveWindow (rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top);

	// Convert to client coordinates
	ScreenToClient (&rc);
	// m_Button is of type CButton and is a member of CMySheet
	m_Button.Create ("&Quit", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
		CRect (rc.right - 85, rc.bottom-35, rc.right - 10, rc.bottom-10),
	this, IDC_QUIT);

	m_Button.SetFont( GetFont() );

	//Set the always OnTop Key
	if(pSuperVisApp->m_bWindowOnTop)
		SetWindowPos(&wndTopMost ,0 ,0, 0, 0, SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOMOVE);
	else
		SetWindowPos(&wndNoTopMost  ,0 ,0, 0, 0, SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOMOVE);


	//Move the window to where is was last time
	CRect Pos;
	Pos.left = pSuperVisApp->m_iWindowLeft;
	Pos.top=  pSuperVisApp->m_iWindowTop;
	Pos.right = pSuperVisApp->m_iWindowRight;
	Pos.bottom = pSuperVisApp->m_iWindowBottom;

	MoveWindow(Pos, FALSE);


/*
	//Retrieve the Size of the Window
	m_bFirstSizing = TRUE;
	GetWindowRect(m_rOriginalSize);
//	ScreenToClient(&m_rOriginalSize);
*/

	return bResult;

  
	
}


// Handler for button click of IDC_QUIT
void CSuperVisSheet::OnQuit ()
{ 
    
	//Kill the propertysheet
	DestroyWindow();

	//Desacitvate the Supervisater
	CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
	pSuperVisApp->m_bSuperVisaterActive = FALSE;
	

}

void CSuperVisSheet::PostNcDestroy() 
{

	//Set the flag so we dont close the window a second time when the engine quit
	((CSupervisApp*)AfxGetApp())->m_SuperVisThread->m_bIsPSheettActive = FALSE;

	//Set the flag for the engine know we are inactive
	((CSupervisApp*)AfxGetApp())->m_bSuperVisaterActive = FALSE;
	
	//We erase everything
	delete this;
	
	CPropertySheet::PostNcDestroy();
}

BOOL CSuperVisSheet::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// If pHandlerInfo is NULL, then handle the message
	if (pHandlerInfo == NULL)
	{
		if (nID == ID_WATCH)
		{
			if (nCode == CN_COMMAND)
			{
				
				m_EventsHistoryPage.SendEventInWatchList();
			

			}
			
			
			return TRUE;
		}
		
	}	
	
	return CPropertySheet::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

void CSuperVisSheet::SendDestroyMsg()
{

	PostMessage(WM_USER_DESTROY_WINDOW, 0, 0);

}

BOOL CSuperVisSheet::PreTranslateMessage(MSG* pMsg) 
{
	//We destroy the supervisheet here
	//We cannot pass the CWnd across thread and this cause problem while using updatedata
	if (pMsg->message == WM_USER_DESTROY_WINDOW){
		DestroyWindow();
	}

	if (pMsg->message == WM_TIMER){

		if(pMsg->wParam == WM_USER_TIMER){

			//Process the timer message to refresh all the control
			RefreshSuperVisater();

		}

	}

	return CPropertySheet::PreTranslateMessage(pMsg);
}

void CSuperVisSheet::RefreshSuperVisater()
{

	CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
	
	CSingleLock sLock( pSuperVisApp->SuperVisMutex, FALSE );

	//Wait for Mutex Object
	sLock.Lock( INFINITE );
	
	//We look which page is active and we refresh it
	int iActivePageIndex = GetActiveIndex();

	switch (iActivePageIndex)
	{

		//EventsHistoryPage
		case 0:
			break;

		//MixerPage
		case 1:
			break;
					
		//MicroAndObjestsPage
		case 2:
			m_MicroAndObjectsPage.RefreshMicroList();
			m_MicroAndObjectsPage.RefreshObjectList();
			break;
	
		//VoicesPage
		case 3:
			m_VoicesPage.RefreshVoiceList();
			break;

		//WavVoicesPage
		case 4:
			m_WavVoicesPage.RefreshVoicesList();
			break;
	
		//ThemePage
		case 5:
			m_ThemesPage.RefreshVolList();
			m_ThemesPage.RefreshTheme();
			break;

		//SuperVisSettingPage
		case 6:
			break;

	}

	//Release Mutex Object
	sLock.Unlock();

}

/*
void CSuperVisSheet::OnSizing(UINT fwSide, LPRECT pRect) 
{
	CPropertySheet::OnSizing(fwSide, pRect);

	CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();


	if(m_bFirstSizing)
	{
		m_bFirstSizing = FALSE;
		pSuperVisApp->m_SuperVisThread->SuperVisSheet->m_EventsHistoryPage.GetInitWindowSize();
		m_Button.GetWindowRect(m_ButtonInitSize);
		m_Button.ScreenToClient(&m_ButtonInitSize);
	}




	CRect CurRect;
	GetWindowRect(&CurRect);
	int deltax = (pRect->right - pRect->left) - (m_rOriginalSize.right - m_rOriginalSize.left);
	int deltay = (pRect->bottom - pRect->top) - (m_rOriginalSize.bottom - m_rOriginalSize.top);


	//Move the Quit button
	CRect rect = m_ButtonInitSize;
	rect.right += deltax;
	rect.left = rect.right - (m_ButtonInitSize.right - m_ButtonInitSize.left);
	rect.bottom += deltay;
	m_Button.MoveWindow(rect);
	
	//We look which page is active and we resize it
	int iActivePageIndex = GetActiveIndex();

	switch (iActivePageIndex)
	{
		//VoicesPage
		case 0:

			break;

		//ThemePage
		case 1:

			break;

		//SuperVisSettingPage
		case 2:
			break;

		//MixerPage
		case 3:
			break;
		
		//MicroAndObjestsPage
		case 4:

			break;
		
		//EventsHistoryPage
		case 5:
			pSuperVisApp->m_SuperVisThread->SuperVisSheet->m_EventsHistoryPage.SetWindowSize(deltax, deltay) ;
			break;
		
		//WavVoicesPage
		case 6:

			break;
	}

	
}
*/
void CSuperVisSheet::OnDestroy() 
{
	CPropertySheet::OnDestroy();
	
	CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
		
	pSuperVisApp->m_iActivePage = GetActiveIndex();

	CRect Pos;
	GetWindowRect(Pos);
	
	pSuperVisApp->m_iWindowLeft = Pos.left;
	pSuperVisApp->m_iWindowTop = Pos.top;
	pSuperVisApp->m_iWindowRight = Pos.right;
	pSuperVisApp->m_iWindowBottom = Pos.bottom;




}

LRESULT CSuperVisSheet::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	
	//The thread just received a message to do OLE automation with soundeditor
	//to get the bank name and the Event name
	//Wparam : index of the array to display
	//LParam : Event to synchronise the two thread
	if (message == WM_SETNAME_EVENT){

		CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
		pSuperVisApp->m_SuperVisThread->SuperVisSheet->m_EventsHistoryPage.SetEventsName(long(wParam));
		
		pSuperVisApp->AddHistoSyncEvent->SetEvent();
	}

	//The thread just received a message to do OLE automation with soundeditor
	//to get the bank name and the first occurence Event name
	//Wparam : index of the array to display
	//LParam : Event to synchronise the two thread
	if (message == WM_SETNAME_FIRST_OCCUR_EVENT){

		CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
		pSuperVisApp->m_SuperVisThread->SuperVisSheet->m_EventsHistoryPage.SetFirstOccurEventsName(long(wParam));

		pSuperVisApp->AddHistoSyncEvent->SetEvent();
				
	}

	//The thread just received a message to do OLE automation with soundeditor
	//to get the bank name and the res name
	//Wparam : index of the array to display
	//LParam : Event to synchronise the two thread
	if (message == WM_SETNAME_RES){

		CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
		pSuperVisApp->m_SuperVisThread->SuperVisSheet->m_MixerPage.SetResName(long(wParam));

		pSuperVisApp->AddHistoSyncEvent->SetEvent();
				
	}

	//The thread just received a message to do OLE automation with soundeditor
	//to get the bank name and the first occurence res name
	//Wparam : index of the array to display
	//LParam : Event to synchronise the two thread
	if (message == WM_SETNAME_FIRST_OCCUR_RES){

		CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
		pSuperVisApp->m_SuperVisThread->SuperVisSheet->m_MixerPage.SetFirstOccurResName(long(wParam));

		pSuperVisApp->AddHistoSyncEvent->SetEvent();
				
	}

		//The thread just received a message to do OLE automation with soundeditor
	//to get the bank name and the first occurence res name
	//Wparam : index of the array to display
	//LParam : Event to synchronise the two thread
	if (message == WM_RESETLIST){

		CSupervisApp* pSuperVisApp = (CSupervisApp*)AfxGetApp();
		pSuperVisApp->m_SuperVisThread->SuperVisSheet->m_MixerPage.ResetReslistButton();

		
	}


	
	
	return CPropertySheet::DefWindowProc(message, wParam, lParam);
}
