#pragma once

#include "stdafx.h"

#include "Includes.h"

#include "Dialog.h"

#include "BringUp.h"

#include "Defines.h"

#include "GUI_DefineFunctions.cpp"

#include "GUI_SaveTextFile.cpp"

using namespace std;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CMasterOfMagicEditorDlg dialog

CMasterOfMagicEditorDlg::CMasterOfMagicEditorDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CMasterOfMagicEditorDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
}

void CMasterOfMagicEditorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	//DDX_Control(pDX, IDC_SECTION_BUTTONS, m_SelectBox);
}

BEGIN_MESSAGE_MAP(CMasterOfMagicEditorDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_ERASEBKGND()
	ON_COMMAND(IDC_QUIT, &CMasterOfMagicEditorDlg::OnQuit)
	ON_COMMAND(IDC_SECTIONS, &CMasterOfMagicEditorDlg::OnSections)
	ON_COMMAND(IDC_SETTINGS, &CMasterOfMagicEditorDlg::OnSettings)
	ON_COMMAND(IDC_ABOUT, &CMasterOfMagicEditorDlg::OnAbout)
	ON_WM_DESTROY()
	ON_WM_CLOSE()
END_MESSAGE_MAP()


// CMasterOfMagicEditorDlg message handlers

BOOL CMasterOfMagicEditorDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CMasterOfMagicEditorApp",GetSafeHwnd());

	InitializeArray();

	SetIcon(m_hIcon, TRUE);			
	SetIcon(m_hIcon, FALSE);

	if(Debug_ == 1) {
		Debug.open(debug_fname,ios::trunc);
		if(Debug.bad()) {
			CallMessageBox("Error opening ",debug_fname);
		}
	}
	return TRUE;  
}

void CMasterOfMagicEditorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	CDialogEx::OnSysCommand(nID, lParam);
}

void CMasterOfMagicEditorDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

HCURSOR CMasterOfMagicEditorDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

bool CMasterOfMagicEditorDlg::SBitdraw(CDC *pDC, UINT nIDResource, int i) 
{
	CBitmap* m_bitmap;
	m_bitmap=new CBitmap();
	m_bitmap->LoadBitmap(nIDResource);
	if(!m_bitmap->m_hObject)
				return true;


	CRect rect;
	GetClientRect(&rect);
	CDC dc;
	dc.CreateCompatibleDC(pDC);    
	dc.SelectObject(m_bitmap);
	int bmw, bmh ;
	BITMAP bmap;
	m_bitmap->GetBitmap(&bmap);
	bmw = bmap.bmWidth;
	bmh = bmap.bmHeight;
	int xo=0, yo=0;
	switch(i){
	case 1:
		pDC->StretchBlt(xo, yo, rect.Width(),
							rect.Height(), &dc,
							0, 0,bmw,bmh, SRCCOPY);
		break;
	case 2:
		if(bmw < rect.Width())
			xo = (rect.Width() - bmw)/2;
		else 
			xo=0;
		if(bmh < rect.Height())
			yo = (rect.Height()-bmh)/2;
		else
			yo=0;
		pDC->BitBlt (xo, yo, rect.Width(),
					rect.Height(), &dc,
					0, 0, SRCCOPY);
		break;
	case 3:
		for (yo = 0; yo < rect.Height(); yo += bmh)
		{
			for (xo = 0; xo < rect.Width(); xo += bmw)
			{
				pDC->BitBlt (xo, yo, rect.Width(),
							rect.Height(), &dc,
							0, 0, SRCCOPY);
			}
		}
	}
	return true;
}

BOOL CMasterOfMagicEditorDlg::OnEraseBkgnd(CDC* pDC)
{
	//Invalidate();
	RedrawWindow();
	SBitdraw(pDC, IDB_BITMAP1, 1);

	return TRUE;
}

void CMasterOfMagicEditorDlg::OnClose()
{
	SaveDialogRect("CMasterOfMagicEditorApp",GetSafeHwnd());

	CDialogEx::OnClose();
}


void CMasterOfMagicEditorDlg::OnQuit()
{
	SaveDialogRect("CMasterOfMagicEditorApp",GetSafeHwnd());
	PostQuitMessage(0);
}


void CMasterOfMagicEditorDlg::OnSections()
{
	if (Loaded != -1) {
		if(!m_SectionDlg) {
			m_SectionDlg = new CSection();
			m_SectionDlg->Create(IDD_SECTIONS, this);
			m_SectionDlg->ShowWindow(SW_SHOW);
		}
	} else {
		CallMessageBox("You Have Not Loaded A Data File.");
	}
}

void CMasterOfMagicEditorDlg::OnSettings()
{
	if(!m_SettingsDlg) {
		m_SettingsDlg = new CSettings();
		m_SettingsDlg->Create(IDD_SETTINGS, this);
		m_SettingsDlg->ShowWindow(SW_SHOW);
	}
}


void CMasterOfMagicEditorDlg::OnAbout()
{
	CDialog *m_AboutDlg = new CDialog(IDD_ABOUTBOX, this);
	m_AboutDlg->DoModal();
}

BOOL CMasterOfMagicEditorDlg::DestroyWindow()
{
	SaveDialogRect("CMasterOfMagicEditorApp",GetSafeHwnd());

	return CDialogEx::DestroyWindow();
}

// CitemPwrEdit dialog

IMPLEMENT_DYNAMIC(CitemPwrEdit, CDialogEx)

CitemPwrEdit::CitemPwrEdit(CWnd* pParent /*=NULL*/)
	: CDialogEx(CitemPwrEdit::IDD, pParent)
{

}

CitemPwrEdit::~CitemPwrEdit()
{
}

void CitemPwrEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CitemPwrEdit, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CitemPwrEdit::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CitemPwrEdit::OnClickedIdok2)
	ON_BN_CLICKED(IDC_BUTTON1, &CitemPwrEdit::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CitemPwrEdit::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CitemPwrEdit::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CitemPwrEdit::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CitemPwrEdit::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CitemPwrEdit::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CitemPwrEdit::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CitemPwrEdit::OnBnClickedButton8)
END_MESSAGE_MAP()


// CitemPwrEdit message handlers


void CitemPwrEdit::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CitemPwrEdit",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}


void CitemPwrEdit::OnBnClickedOk()
{
	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;

	for(int Step = 0;Step < step_max[0];Step++)
	{
		char Value[255];
		m_ItemPwrEditDlg->GetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Value,255);
		LvItem.pszText=Value;
		LvItem.iSubItem=Step;
		m_ItemPwrDlg->SendDlgItemMessage(IDC_ITEM_PWR_LIST,LVM_SETITEMTEXT, (WPARAM)(int)Button, (LPARAM)&LvItem);
	}
	memset(&LvItem,0,sizeof(LvItem));
	
	CDialogEx::OnOK();

	m_ItemPwrEditDlg->DestroyWindow();

	m_ItemPwrEditDlg = NULL;
}


void CitemPwrEdit::OnClickedIdok2()
{
	CDialogEx::OnOK();

	m_ItemPwrEditDlg->DestroyWindow();

	m_ItemPwrEditDlg = NULL;
}


void CitemPwrEdit::OnBnClickedButton1()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_ITEM_PWR_ENCHNT_ON_ONE);
	Dialog->ShowWindow(SW_SHOW);
}


void CitemPwrEdit::OnBnClickedButton2()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_ITEM_PWR_ENCHNT_ON_TWO);
	Dialog->ShowWindow(SW_SHOW);
}


void CitemPwrEdit::OnBnClickedButton3()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_ITEM_PWR_TYPE);
	Dialog->ShowWindow(SW_SHOW);
}


void CitemPwrEdit::OnBnClickedButton4()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_ITEM_PWR_BONUS);
	Dialog->ShowWindow(SW_SHOW);
}


void CitemPwrEdit::OnBnClickedButton5()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_ITEM_PWR_SPECIALS_ONE);
	Dialog->ShowWindow(SW_SHOW);
}


void CitemPwrEdit::OnBnClickedButton6()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_ITEM_PWR_SPECIALS_TWO);
	Dialog->ShowWindow(SW_SHOW);
}


void CitemPwrEdit::OnBnClickedButton7()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_ITEM_PWR_SPECIALS_THREE);
	Dialog->ShowWindow(SW_SHOW);
}


void CitemPwrEdit::OnBnClickedButton8()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_ITEM_PWR_SPECIALS_FOUR);
	Dialog->ShowWindow(SW_SHOW);
}

// CItemPwr dialog

IMPLEMENT_DYNAMIC(CItemPwr, CDialogEx)

CItemPwr::CItemPwr(CWnd* pParent /*=NULL*/)
	: CDialogEx(CItemPwr::IDD, pParent)
{

}

CItemPwr::~CItemPwr()
{
}

void CItemPwr::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CItemPwr, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CItemPwr::OnBnClickedOk)
	ON_NOTIFY(NM_DBLCLK, IDC_ITEM_PWR_LIST, &CItemPwr::OnLvnLinkClickedItemPwrList)
END_MESSAGE_MAP()


// CItemPwr message handlers

void CItemPwr::OnBnClickedOk()
{
	SaveArrayTable(GetSafeHwnd(),IDC_ITEM_PWR_LIST,ButtonNameIndex);
	ButtonNameIndex = -1;
	CDialogEx::OnOK();

	m_ItemPwrDlg->DestroyWindow();

	m_ItemPwrDlg = NULL;
}


BOOL CItemPwr::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CItemPwr",GetSafeHwnd());

   LoadArrayTable(GetSafeHwnd(),IDC_ITEM_PWR_LIST,ButtonNameIndex);

	//m_ItemPwrBox = (CListBox*)GetDlgItem(IDC_ITEM_PWR_LIST);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CItemPwr::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CItemPwr",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CItemPwr::OnLvnLinkClickedItemPwrList(NMHDR *pNMHDR, LRESULT *pResult)
{
	Button = SendDlgItemMessage(IDC_ITEM_PWR_LIST,LVM_GETNEXTITEM,-1,LVNI_SELECTED);

	char Text[255];
				  
	m_ItemPwrEditDlg = new CitemPwrEdit();
	m_ItemPwrEditDlg->Create(IDD_ITEM_POWERS_EDIT);

	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.pszText=Text;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;
					
	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		LvItem.iSubItem=Step;
		m_ItemPwrDlg->SendDlgItemMessage(IDC_ITEM_PWR_LIST,LVM_GETITEMTEXT, Button, (LPARAM)&LvItem);
		m_ItemPwrEditDlg->SetDlgItemText(GetHelpControlID(ButtonNameIndex,Step),GetControlHelpNames(ButtonNameIndex,Step));
		m_ItemPwrEditDlg->SetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Text);
	}
	memset(&LvItem,0,sizeof(LvItem));

	m_ItemPwrEditDlg->ShowWindow(SW_SHOW);

	*pResult = 0;
}

// CBuildingEdit dialog

IMPLEMENT_DYNAMIC(CBuildingEdit, CDialogEx)

CBuildingEdit::CBuildingEdit(CWnd* pParent /*=NULL*/)
	: CDialogEx(CBuildingEdit::IDD, pParent)
{

}

CBuildingEdit::~CBuildingEdit()
{
}

void CBuildingEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CBuildingEdit, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDC_BUTTON1, &CBuildingEdit::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CBuildingEdit::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CBuildingEdit::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CBuildingEdit::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CBuildingEdit::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CBuildingEdit::OnBnClickedButton6)
	ON_BN_CLICKED(IDOK2, &CBuildingEdit::OnBnClickedOk2)
	ON_BN_CLICKED(IDOK, &CBuildingEdit::OnBnClickedOk)
END_MESSAGE_MAP()


// CBuildingEdit message handlers

BOOL CBuildingEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CBuildingEdit",GetSafeHwnd());

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CBuildingEdit::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CBuildingEdit",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CBuildingEdit::OnBnClickedButton1()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_BUILD_REQ_ONE);
	Dialog->ShowWindow(SW_SHOW);
}


void CBuildingEdit::OnBnClickedButton2()
{
		CDialogEx* Dialog = new CDialogEx();
		Dialog->Create(IDD_BUILD_REQ_TWO);
		Dialog->ShowWindow(SW_SHOW);
}


void CBuildingEdit::OnBnClickedButton3()
{
		CDialogEx* Dialog = new CDialogEx();
		Dialog->Create(IDD_BUILD_REPLACE);
		Dialog->ShowWindow(SW_SHOW);
}


void CBuildingEdit::OnBnClickedButton4()
{
		CDialogEx* Dialog = new CDialogEx();
		Dialog->Create(IDD_BUILD_REG_XP);
		Dialog->ShowWindow(SW_SHOW);
}


void CBuildingEdit::OnBnClickedButton5()
{
		CDialogEx* Dialog = new CDialogEx();
		Dialog->Create(IDD_BUILD_VETERAN_XP);
		Dialog->ShowWindow(SW_SHOW);
}


void CBuildingEdit::OnBnClickedButton6()
{
		CDialogEx* Dialog = new CDialogEx();
		Dialog->Create(IDD_BUILD_MAGIC_WEAP);
		Dialog->ShowWindow(SW_SHOW);
}


void CBuildingEdit::OnBnClickedOk2()
{
	// TODO: Add your control notification handler code here
	CDialogEx::OnOK();

	m_BuildingEditDlg->DestroyWindow();

	m_BuildingEditDlg = NULL;
}


void CBuildingEdit::OnBnClickedOk()
{
	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;

	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		char Value[255];
		m_BuildingEditDlg->GetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Value,255);
		LvItem.pszText=Value;
		LvItem.iSubItem=Step;
		m_BuildingDlg->SendDlgItemMessage(IDC_BUILDING_LIST,LVM_SETITEMTEXT, (WPARAM)(int)Button, (LPARAM)&LvItem);
	}
	memset(&LvItem,0,sizeof(LvItem));
	
	CDialogEx::OnOK();

	m_BuildingEditDlg->DestroyWindow();

	m_BuildingEditDlg = NULL;
}

// CBuilding dialog

IMPLEMENT_DYNAMIC(CBuilding, CDialogEx)

CBuilding::CBuilding(CWnd* pParent /*=NULL*/)
	: CDialogEx(CBuilding::IDD, pParent)
{

}

CBuilding::~CBuilding()
{
}

void CBuilding::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CBuilding, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CBuilding::OnBnClickedOk)
	ON_NOTIFY(NM_DBLCLK, IDC_BUILDING_LIST, &CBuilding::OnLvnLinkClickedBuildingList)
END_MESSAGE_MAP()


// CBuilding message handlers

void CBuilding::OnBnClickedOk()
{
	SaveArrayTable(GetSafeHwnd(),IDC_BUILDING_LIST,ButtonNameIndex);
	ButtonNameIndex = -1;
	CDialogEx::OnOK();
	m_BuildingDlg->DestroyWindow();

	m_BuildingDlg = NULL;
}


BOOL CBuilding::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CBuilding",GetSafeHwnd());

   LoadArrayTable(GetSafeHwnd(),IDC_BUILDING_LIST,ButtonNameIndex);

	return TRUE;
}

void CBuilding::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CBuilding",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CBuilding::OnLvnLinkClickedBuildingList(NMHDR *pNMHDR, LRESULT *pResult)
{
	Button = SendDlgItemMessage(IDC_BUILDING_LIST,LVM_GETNEXTITEM,-1,LVNI_SELECTED);

	char Text[255];
				  
	m_BuildingEditDlg = new CBuildingEdit();
	m_BuildingEditDlg->Create(IDD_BUILDING_EDIT);

	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.pszText=Text;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;
					
	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		LvItem.iSubItem=Step;
		m_BuildingDlg->SendDlgItemMessage(IDC_BUILDING_LIST,LVM_GETITEMTEXT, Button, (LPARAM)&LvItem);
		m_BuildingEditDlg->SetDlgItemText(GetHelpControlID(ButtonNameIndex,Step),GetControlHelpNames(ButtonNameIndex,Step));
		m_BuildingEditDlg->SetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Text);
	}
	memset(&LvItem,0,sizeof(LvItem));

	m_BuildingEditDlg->ShowWindow(SW_SHOW);

	*pResult = 0;
}

// CSpellEdit dialog

IMPLEMENT_DYNAMIC(CSpellEdit, CDialogEx)

CSpellEdit::CSpellEdit(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSpellEdit::IDD, pParent)
{

}

CSpellEdit::~CSpellEdit()
{
}

void CSpellEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSpellEdit, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CSpellEdit::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CSpellEdit::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CSpellEdit::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CSpellEdit::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CSpellEdit::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CSpellEdit::OnBnClickedButton6)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CSpellEdit::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CSpellEdit::OnBnClickedOk2)
END_MESSAGE_MAP()


// CSpellEdit message handlers


BOOL CSpellEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CSpellEdit",GetSafeHwnd());

	//m_SpellBox = (CListBox*)GetDlgItem(IDC_ITEM_PWR_LIST);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CSpellEdit::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CSpellEdit",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CSpellEdit::OnBnClickedButton1()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_SPELLS_BOOK);
	Dialog->ShowWindow(SW_SHOW);
}


void CSpellEdit::OnBnClickedButton2()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_SPELLS_REALM);
	Dialog->ShowWindow(SW_SHOW);
}


void CSpellEdit::OnBnClickedButton3()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_SPELLS_CASTING_ELIGIBILITY);
	Dialog->ShowWindow(SW_SHOW);
}


void CSpellEdit::OnBnClickedButton4()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_SPELLS_CAST_COST);
	Dialog->ShowWindow(SW_SHOW);
}


void CSpellEdit::OnBnClickedButton5()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_SPELLS_SOUND_EFFECT);
	Dialog->ShowWindow(SW_SHOW);
}


void CSpellEdit::OnBnClickedButton6()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_SPELLS_SUMMONED_UNITS);
	Dialog->ShowWindow(SW_SHOW);
}


void CSpellEdit::OnBnClickedOk()
{
	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;

	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		char Value[255];
		m_SpellEditDlg->GetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Value,255);
		LvItem.pszText=Value;
		LvItem.iSubItem=Step;
		m_SpellDlg->SendDlgItemMessage(IDC_SPELL_LIST,LVM_SETITEMTEXT, (WPARAM)(int)Button, (LPARAM)&LvItem);
	}
	memset(&LvItem,0,sizeof(LvItem));

	m_SpellEditDlg->DestroyWindow();

	m_SpellEditDlg = NULL;
	
	CDialogEx::OnOK();
}


void CSpellEdit::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_SpellEditDlg->DestroyWindow();

	m_SpellEditDlg = NULL;
}

// CSpell dialog

IMPLEMENT_DYNAMIC(CSpell, CDialogEx)

CSpell::CSpell(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSpell::IDD, pParent)
{

}

CSpell::~CSpell()
{
}

void CSpell::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSpell, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CSpell::OnBnClickedOk)
	ON_NOTIFY(NM_DBLCLK, IDC_SPELL_LIST, &CSpell::OnLvnLinkClickedSpellList)
END_MESSAGE_MAP()


// CSpell message handlers

void CSpell::OnBnClickedOk()
{
	SaveArrayTable(GetSafeHwnd(),IDC_SPELL_LIST,ButtonNameIndex);
	ButtonNameIndex = -1;
	CDialogEx::OnOK();

	m_SpellDlg->DestroyWindow();

	m_SpellDlg = NULL;
}


BOOL CSpell::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CSpell",GetSafeHwnd());

   LoadArrayTable(GetSafeHwnd(),IDC_SPELL_LIST,ButtonNameIndex);

	//m_SpellBox = (CListBox*)GetDlgItem(IDC_ITEM_PWR_LIST);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CSpell::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CSpell",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CSpell::OnLvnLinkClickedSpellList(NMHDR *pNMHDR, LRESULT *pResult)
{
	Button = SendDlgItemMessage(IDC_SPELL_LIST,LVM_GETNEXTITEM,-1,LVNI_SELECTED);

	char Text[255];
				  
	m_SpellEditDlg = new CSpellEdit();
	m_SpellEditDlg->Create(IDD_SPELL_EDIT);

	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.pszText=Text;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;
					
	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		LvItem.iSubItem=Step;
		m_SpellDlg->SendDlgItemMessage(IDC_SPELL_LIST,LVM_GETITEMTEXT, Button, (LPARAM)&LvItem);
		m_SpellEditDlg->SetDlgItemText(GetHelpControlID(ButtonNameIndex,Step),GetControlHelpNames(ButtonNameIndex,Step));
		m_SpellEditDlg->SetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Text);
	}
	memset(&LvItem,0,sizeof(LvItem));

	m_SpellEditDlg->ShowWindow(SW_SHOW);

	*pResult = 0;
}


// CUnitEdit dialog

IMPLEMENT_DYNAMIC(CUnitEdit, CDialogEx)

CUnitEdit::CUnitEdit(CWnd* pParent /*=NULL*/)
	: CDialogEx(CUnitEdit::IDD, pParent)
{

}

CUnitEdit::~CUnitEdit()
{
}

void CUnitEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CUnitEdit, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDC_BUTTON1, &CUnitEdit::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CUnitEdit::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CUnitEdit::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CUnitEdit::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CUnitEdit::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CUnitEdit::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CUnitEdit::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CUnitEdit::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CUnitEdit::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON10, &CUnitEdit::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON11, &CUnitEdit::OnBnClickedButton11)
	ON_BN_CLICKED(IDC_BUTTON12, &CUnitEdit::OnBnClickedButton12)
	ON_BN_CLICKED(IDC_BUTTON13, &CUnitEdit::OnBnClickedButton13)
	ON_BN_CLICKED(IDC_BUTTON14, &CUnitEdit::OnBnClickedButton14)
	ON_BN_CLICKED(IDC_BUTTON15, &CUnitEdit::OnBnClickedButton15)
	ON_BN_CLICKED(IDC_BUTTON16, &CUnitEdit::OnBnClickedButton16)
	ON_BN_CLICKED(IDC_BUTTON17, &CUnitEdit::OnBnClickedButton17)
	ON_BN_CLICKED(IDC_BUTTON18, &CUnitEdit::OnBnClickedButton18)
	ON_BN_CLICKED(IDC_BUTTON19, &CUnitEdit::OnBnClickedButton19)
	ON_BN_CLICKED(IDOK2, &CUnitEdit::OnBnClickedOk2)
	ON_BN_CLICKED(IDOK, &CUnitEdit::OnBnClickedOk)
END_MESSAGE_MAP()


// CUnitEdit message handlers

BOOL CUnitEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CUnitEdit",GetSafeHwnd());

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CUnitEdit::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CUnitEdit",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CUnitEdit::OnBnClickedButton1()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_RANGE_TYPE);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton2()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_MOVEMENT);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton3()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_COST);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton4()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_SUMMONED);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton5()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_RACE_CODE);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton6()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_BUILD_REQ);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton7()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_HERO_ITEM_SLOTS);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton8()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_HIT_POINTS);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton9()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_CARRY);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton10()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_FIGURINES);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton11()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_CONSTRUCTION);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton12()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_MOVEMENT_FLAGS);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton13()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_IMUNITY_FLAGS);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton14()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_ATTRIBUTE_FLAGS_ONE);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton15()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_ATTRIBUTE_FLAGS_TWO);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton16()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_ATTRIBUTE_FLAGS_THREE);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton17()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_ATTRIBUTE_FLAGS_FOUR);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton18()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_SPECIAL_ATTACKS_ONE);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedButton19()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_UNITS_SPECIAL_ATTACKS_TWO);
	Dialog->ShowWindow(SW_SHOW);
}


void CUnitEdit::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_UnitsEditDlg->DestroyWindow();

	m_UnitsEditDlg = NULL;
}


void CUnitEdit::OnBnClickedOk()
{
	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;

	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		char Value[255];
		m_UnitsEditDlg->GetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Value,255);
		LvItem.pszText=Value;
		LvItem.iSubItem=Step;
		m_UnitsDlg->SendDlgItemMessage(IDC_UNIT_LIST,LVM_SETITEMTEXT, (WPARAM)(int)Button, (LPARAM)&LvItem);
	}
	memset(&LvItem,0,sizeof(LvItem));
	
	CDialogEx::OnOK();

	m_UnitsEditDlg->DestroyWindow();

	m_UnitsEditDlg = NULL;
}

// CUnits dialog

IMPLEMENT_DYNAMIC(CUnits, CDialogEx)

CUnits::CUnits(CWnd* pParent /*=NULL*/)
	: CDialogEx(CUnits::IDD, pParent)
{

}

CUnits::~CUnits()
{
}

void CUnits::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CUnits, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CUnits::OnBnClickedOk)
	ON_NOTIFY(NM_DBLCLK, IDC_UNIT_LIST, &CUnits::OnLvnLinkClickedUnitsList)
END_MESSAGE_MAP()


// CUnits message handlers

void CUnits::OnBnClickedOk()
{
	SaveArrayTable(GetSafeHwnd(),IDC_UNIT_LIST,ButtonNameIndex);
	ButtonNameIndex = -1;
	CDialogEx::OnOK();
	m_UnitsDlg->DestroyWindow();

	m_UnitsDlg = NULL;
}


BOOL CUnits::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CUnits",GetSafeHwnd());

   LoadArrayTable(GetSafeHwnd(),IDC_UNIT_LIST,ButtonNameIndex);

	return TRUE;
}

void CUnits::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CUnits",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CUnits::OnLvnLinkClickedUnitsList(NMHDR *pNMHDR, LRESULT *pResult)
{
	Button = SendDlgItemMessage(IDC_UNIT_LIST,LVM_GETNEXTITEM,-1,LVNI_SELECTED);

	char Text[255];
				  
	m_UnitsEditDlg = new CUnitEdit();
	m_UnitsEditDlg->Create(IDD_UNIT_EDIT);

	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.pszText=Text;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;
					
	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		LvItem.iSubItem=Step;
		m_UnitsDlg->SendDlgItemMessage(IDC_UNIT_LIST,LVM_GETITEMTEXT, Button, (LPARAM)&LvItem);
		m_UnitsEditDlg->SetDlgItemText(GetHelpControlID(ButtonNameIndex,Step),GetControlHelpNames(ButtonNameIndex,Step));
		m_UnitsEditDlg->SetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Text);
	}
	memset(&LvItem,0,sizeof(LvItem));

	m_UnitsEditDlg->ShowWindow(SW_SHOW);

	*pResult = 0;
}

// CRaceEdit dialog

IMPLEMENT_DYNAMIC(CRaceEdit, CDialogEx)

CRaceEdit::CRaceEdit(CWnd* pParent /*=NULL*/)
	: CDialogEx(CRaceEdit::IDD, pParent)
{

}

CRaceEdit::~CRaceEdit()
{
}

void CRaceEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CRaceEdit, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CRaceEdit::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CRaceEdit::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CRaceEdit::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CRaceEdit::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CRaceEdit::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CRaceEdit::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CRaceEdit::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CRaceEdit::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CRaceEdit::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON11, &CRaceEdit::OnBnClickedButton11)
	ON_BN_CLICKED(IDC_BUTTON12, &CRaceEdit::OnBnClickedButton12)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CRaceEdit::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CRaceEdit::OnBnClickedOk2)
END_MESSAGE_MAP()


// CRaceEdit message handlers


BOOL CRaceEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CRaceEdit",GetSafeHwnd());

	//m_SpellBox = (CListBox*)GetDlgItem(IDC_ITEM_PWR_LIST);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CRaceEdit::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CRaceEdit",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}


void CRaceEdit::OnBnClickedButton1()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_NUM_BUILDINGS_BANNED);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton2()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_BUILD_BANNED1);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton3()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_BUILD_BANNED2);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton4()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_BUILD_BANNED3);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton5()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_BUILD_BANNED4);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton6()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_BUILD_BANNED5);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton7()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_BUILD_BANNED6);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton8()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_BUILD_BANNED7);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton9()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_OUTPOST_GROWTH);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton11()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_CITY_GROWTH);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedButton12()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_HOUSING_PICTURE);
	Dialog->ShowWindow(SW_SHOW);
}


void CRaceEdit::OnBnClickedOk()
{
	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;

	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		char Value[255];
		m_RaceDataEditDlg->GetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Value,255);
		LvItem.pszText=Value;
		LvItem.iSubItem=Step;
		m_RaceDataDlg->SendDlgItemMessage(IDC_RACE_DATA_LIST,LVM_SETITEMTEXT, (WPARAM)(int)Button, (LPARAM)&LvItem);
	}
	memset(&LvItem,0,sizeof(LvItem));

	CDialogEx::OnOK();

	m_RaceDataEditDlg->DestroyWindow();

	m_RaceDataEditDlg = NULL;
}


void CRaceEdit::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_RaceDataEditDlg->DestroyWindow();

	m_RaceDataEditDlg = NULL;
}

// CRaceData dialog

IMPLEMENT_DYNAMIC(CRaceData, CDialogEx)

CRaceData::CRaceData(CWnd* pParent /*=NULL*/)
	: CDialogEx(CRaceData::IDD, pParent)
{

}

CRaceData::~CRaceData()
{
}

void CRaceData::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CRaceData, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CRaceData::OnBnClickedOk)
	ON_NOTIFY(NM_DBLCLK, IDC_RACE_DATA_LIST, &CRaceData::OnLvnLinkClickedRaceDataList)
END_MESSAGE_MAP()


// CRaceData message handlers

void CRaceData::OnBnClickedOk()
{
	SaveArrayTable(GetSafeHwnd(),IDC_RACE_DATA_LIST,ButtonNameIndex);
	ButtonNameIndex = -1;
	CDialogEx::OnOK();

	m_RaceDataDlg->DestroyWindow();

	m_RaceDataDlg = NULL;
}


BOOL CRaceData::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CRaceData",GetSafeHwnd());

   LoadArrayTable(GetSafeHwnd(),IDC_RACE_DATA_LIST,ButtonNameIndex);

	//m_RaceDataBox = (CListBox*)GetDlgItem(IDC_ITEM_PWR_LIST);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CRaceData::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CRaceData",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CRaceData::OnLvnLinkClickedRaceDataList(NMHDR *pNMHDR, LRESULT *pResult)
{
	Button = SendDlgItemMessage(IDC_RACE_DATA_LIST,LVM_GETNEXTITEM,-1,LVNI_SELECTED);

	char Text[255];
				  
	m_RaceDataEditDlg = new CRaceEdit();
	m_RaceDataEditDlg->Create(IDD_RACE_EDIT);

	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.pszText=Text;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;
					
	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		LvItem.iSubItem=Step;
		m_RaceDataDlg->SendDlgItemMessage(IDC_RACE_DATA_LIST,LVM_GETITEMTEXT, Button, (LPARAM)&LvItem);
		m_RaceDataEditDlg->SetDlgItemText(GetHelpControlID(ButtonNameIndex,Step),GetControlHelpNames(ButtonNameIndex,Step));
		m_RaceDataEditDlg->SetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Text);
	}
	memset(&LvItem,0,sizeof(LvItem));

	m_RaceDataEditDlg->ShowWindow(SW_SHOW);

	*pResult = 0;
}



// CUpkeepEdit dialog

IMPLEMENT_DYNAMIC(CUpkeepEdit, CDialogEx)

CUpkeepEdit::CUpkeepEdit(CWnd* pParent /*=NULL*/)
	: CDialogEx(CUpkeepEdit::IDD, pParent)
{

}

CUpkeepEdit::~CUpkeepEdit()
{
}

void CUpkeepEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CUpkeepEdit, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CUpkeepEdit::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CUpkeepEdit::OnBnClickedOk2)
END_MESSAGE_MAP()


// CUpkeepEdit message handlers


BOOL CUpkeepEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CUpkeepEdit",GetSafeHwnd());

	//m_SpellBox = (CListBox*)GetDlgItem(IDC_ITEM_PWR_LIST);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CUpkeepEdit::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CUpkeepEdit",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CUpkeepEdit::OnBnClickedOk()
{
	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;

	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		char Value[255];
		m_UpkeepEditDlg->GetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Value,255);
		LvItem.pszText=Value;
		LvItem.iSubItem=Step;
		m_UpkeepDlg->SendDlgItemMessage(IDC_UPKEEP_LIST,LVM_SETITEMTEXT, (WPARAM)(int)Button, (LPARAM)&LvItem);
	}
	memset(&LvItem,0,sizeof(LvItem));

	CDialogEx::OnOK();

	m_UpkeepEditDlg->DestroyWindow();

	m_UpkeepEditDlg = NULL;
}


void CUpkeepEdit::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_UpkeepEditDlg->DestroyWindow();

	m_UpkeepEditDlg = NULL;
}


// CUpkeepCost dialog

IMPLEMENT_DYNAMIC(CUpkeepCost, CDialogEx)

CUpkeepCost::CUpkeepCost(CWnd* pParent /*=NULL*/)
	: CDialogEx(CUpkeepCost::IDD, pParent)
{

}

CUpkeepCost::~CUpkeepCost()
{
}

void CUpkeepCost::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CUpkeepCost, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CUpkeepCost::OnBnClickedOk)
	ON_NOTIFY(NM_DBLCLK, IDC_UPKEEP_LIST, &CUpkeepCost::OnLvnLinkClickedUpkeepList)
END_MESSAGE_MAP()


// CUpkeepCost message handlers


BOOL CUpkeepCost::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CUpkeepCost",GetSafeHwnd());

	LoadArrayTable(GetSafeHwnd(),IDC_UPKEEP_LIST,ButtonNameIndex);

	//m_SpellBox = (CListBox*)GetDlgItem(IDC_ITEM_PWR_LIST);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CUpkeepCost::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CUpkeepCost",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CUpkeepCost::OnBnClickedOk()
{
	SaveArrayTable(GetSafeHwnd(),IDC_UPKEEP_LIST,ButtonNameIndex);
	ButtonNameIndex = -1;
	CDialogEx::OnOK();

	m_UpkeepDlg->DestroyWindow();

	m_UpkeepDlg = NULL;
}

void CUpkeepCost::OnLvnLinkClickedUpkeepList(NMHDR *pNMHDR, LRESULT *pResult)
{
	Button = SendDlgItemMessage(IDC_UPKEEP_LIST,LVM_GETNEXTITEM,-1,LVNI_SELECTED);

	char Text[255];
				  
	m_UpkeepEditDlg = new CUpkeepEdit();
	m_UpkeepEditDlg->Create(IDD_UPKEEP__EDIT);

	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.pszText=Text;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;
					
	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		LvItem.iSubItem=Step;
		m_UpkeepDlg->SendDlgItemMessage(IDC_UPKEEP_LIST,LVM_GETITEMTEXT, Button, (LPARAM)&LvItem);
		m_UpkeepEditDlg->SetDlgItemText(GetHelpControlID(ButtonNameIndex,Step),GetControlHelpNames(ButtonNameIndex,Step));
		m_UpkeepEditDlg->SetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Text);
	}
	memset(&LvItem,0,sizeof(LvItem));

	m_UpkeepEditDlg->ShowWindow(SW_SHOW);

	*pResult = 0;
}

// CSpellID dialog

IMPLEMENT_DYNAMIC(CSpellID, CDialogEx)

CSpellID::CSpellID(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSpellID::IDD, pParent)
{

}

CSpellID::~CSpellID()
{
}

void CSpellID::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSpellID, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CSpellID::OnBnClickedOk)
END_MESSAGE_MAP()


// SpellID message handlers

void CSpellID::OnBnClickedOk()
{
	CDialogEx::OnOK();

	//m_SpellIDDlg->DestroyWindow();

	//m_SpellIDDlg = NULL;
}

BOOL CSpellID::OnInitDialog()
{


	CDialogEx::OnInitDialog();

	LoadDialogRect("CSpellID",GetSafeHwnd());

   LoadArrayTable(GetSafeHwnd(),IDC_SPELL_ID_LIST,2,2);

	return TRUE;
}

void CSpellID::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CSpellID",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CHeroStatsEdit dialog

IMPLEMENT_DYNAMIC(CHeroStatsEdit, CDialogEx)

CHeroStatsEdit::CHeroStatsEdit(CWnd* pParent /*=NULL*/)
	: CDialogEx(CHeroStatsEdit::IDD, pParent)
{

}

CHeroStatsEdit::~CHeroStatsEdit()
{
}

void CHeroStatsEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CHeroStatsEdit, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDC_BUTTON1, &CHeroStatsEdit::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CHeroStatsEdit::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CHeroStatsEdit::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CHeroStatsEdit::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CHeroStatsEdit::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CHeroStatsEdit::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CHeroStatsEdit::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CHeroStatsEdit::OnBnClickedButton8)
	ON_BN_CLICKED(IDOK2, &CHeroStatsEdit::OnBnClickedOk2)
	ON_BN_CLICKED(IDOK, &CHeroStatsEdit::OnBnClickedOk)
END_MESSAGE_MAP()


// CHeroStatsEdit message handlers

BOOL CHeroStatsEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CHeroStatsEdit",GetSafeHwnd());

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CHeroStatsEdit::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CHeroStatsEdit",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CHeroStatsEdit::OnBnClickedButton1()
{
	CDialogEx* Dialog = new CDialogEx();
	Dialog->Create(IDD_HERO_ABILITY_ONE);
	Dialog->ShowWindow(SW_SHOW);
}


void CHeroStatsEdit::OnBnClickedButton2()
{
		CDialogEx* Dialog = new CDialogEx();
		Dialog->Create(IDD_HERO_ABILITY_TWO);
		Dialog->ShowWindow(SW_SHOW);
}


void CHeroStatsEdit::OnBnClickedButton3()
{
		CDialogEx* Dialog = new CDialogEx();
		Dialog->Create(IDD_HERO_ABILITY_THREE);
		Dialog->ShowWindow(SW_SHOW);
}


void CHeroStatsEdit::OnBnClickedButton4()
{
		CDialogEx* Dialog = new CDialogEx();
		Dialog->Create(IDD_HERO_ABILITY_FOUR);
		Dialog->ShowWindow(SW_SHOW);
}

void CHeroStatsEdit::OnBnClickedButton5()
{
	CDialogEx* m_SpellIDDlg = new CSpellID();
	m_SpellIDDlg->Create(IDD_SPELL_NUMBERS);
	m_SpellIDDlg->ShowWindow(SW_SHOW);
}


void CHeroStatsEdit::OnBnClickedButton6()
{
	CDialogEx* m_SpellIDDlg = new CSpellID();
	m_SpellIDDlg->Create(IDD_SPELL_NUMBERS);
	m_SpellIDDlg->ShowWindow(SW_SHOW);
}


void CHeroStatsEdit::OnBnClickedButton7()
{
	CDialogEx* m_SpellIDDlg = new CSpellID();
	m_SpellIDDlg->Create(IDD_SPELL_NUMBERS);
	m_SpellIDDlg->ShowWindow(SW_SHOW);
}


void CHeroStatsEdit::OnBnClickedButton8()
{
	CDialogEx* m_SpellIDDlg = new CSpellID();
	m_SpellIDDlg->Create(IDD_SPELL_NUMBERS);
	m_SpellIDDlg->ShowWindow(SW_SHOW);
}



void CHeroStatsEdit::OnBnClickedOk2()
{
	// TODO: Add your control notification handler code here
	CDialogEx::OnOK();

	m_HeroStatsEditDlg->DestroyWindow();

	m_HeroStatsEditDlg = NULL;
}


void CHeroStatsEdit::OnBnClickedOk()
{
	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;

	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		char Value[255];
		m_HeroStatsEditDlg->GetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Value,255);
		LvItem.pszText=Value;
		LvItem.iSubItem=Step;
		m_HeroStatsDlg->SendDlgItemMessage(IDC_HERO_STATS_LIST,LVM_SETITEMTEXT, (WPARAM)(int)Button, (LPARAM)&LvItem);
	}
	memset(&LvItem,0,sizeof(LvItem));
	
	CDialogEx::OnOK();

	m_HeroStatsEditDlg->DestroyWindow();

	m_HeroStatsEditDlg = NULL;
}

// CHeroStats dialog

IMPLEMENT_DYNAMIC(CHeroStats, CDialogEx)

CHeroStats::CHeroStats(CWnd* pParent /*=NULL*/)
	: CDialogEx(CHeroStats::IDD, pParent)
{

}

CHeroStats::~CHeroStats()
{
}

void CHeroStats::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CHeroStats, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CHeroStats::OnBnClickedOk)
	ON_NOTIFY(NM_DBLCLK, IDC_HERO_STATS_LIST, &CHeroStats::OnLvnLinkClickedHeroStatsList)
END_MESSAGE_MAP()


// CHeroStats message handlers

void CHeroStats::OnBnClickedOk()
{
	SaveArrayTable(GetSafeHwnd(),IDC_HERO_STATS_LIST,ButtonNameIndex);
	ButtonNameIndex = -1;
	CDialogEx::OnOK();
	m_HeroStatsDlg->DestroyWindow();

	m_HeroStatsDlg = NULL;
}


BOOL CHeroStats::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CHeroStats",GetSafeHwnd());

   LoadArrayTable(GetSafeHwnd(),IDC_HERO_STATS_LIST,ButtonNameIndex);

	return TRUE;
}

void CHeroStats::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CHeroStats",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CHeroStats::OnLvnLinkClickedHeroStatsList(NMHDR *pNMHDR, LRESULT *pResult)
{
	Button = SendDlgItemMessage(IDC_HERO_STATS_LIST,LVM_GETNEXTITEM,-1,LVNI_SELECTED);

	char Text[255];
				  
	m_HeroStatsEditDlg = new CHeroStatsEdit();
	m_HeroStatsEditDlg->Create(IDD_HERO_STATS_EDIT);

	memset(&LvItem,0,sizeof(LvItem));
	LvItem.mask=LVIF_TEXT;
	LvItem.iSubItem=0;
	LvItem.pszText=Text;
	LvItem.cchTextMax=256;
	LvItem.iItem=Button;
					
	for(int Step = 0;Step < step_max[ButtonNameIndex];Step++)
	{
		LvItem.iSubItem=Step;
		m_HeroStatsDlg->SendDlgItemMessage(IDC_HERO_STATS_LIST,LVM_GETITEMTEXT, Button, (LPARAM)&LvItem);
		m_HeroStatsEditDlg->SetDlgItemText(GetHelpControlID(ButtonNameIndex,Step),GetControlHelpNames(ButtonNameIndex,Step));
		m_HeroStatsEditDlg->SetDlgItemText(GetEditControlID(ButtonNameIndex,0,Step),Text);
	}
	memset(&LvItem,0,sizeof(LvItem));

	m_HeroStatsEditDlg->ShowWindow(SW_SHOW);

	*pResult = 0;
}

// CHealing dialog

IMPLEMENT_DYNAMIC(CHealing, CDialogEx)

CHealing::CHealing(CWnd* pParent /*=NULL*/)
	: CDialogEx(CHealing::IDD, pParent)
{

}

CHealing::~CHealing()
{
}

void CHealing::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CHealing, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CHealing::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CHealing::OnBnClickedOk2)
END_MESSAGE_MAP()


// Healing message handlers

void CHealing::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(23,0,1,Str2CharArray(Text));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_HealingDlg->DestroyWindow();

	m_HealingDlg = NULL;
}

void CHealing::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_HealingDlg->DestroyWindow();

	m_HealingDlg = NULL;
}

BOOL CHealing::OnInitDialog()
{
	char * Value1 = GetArrayValue(23,0,0);
	SetDlgItemText(IDC_EDIT1,Value1);
	char * Value = GetArrayValue(23,0,1);
	SetDlgItemText(IDC_EDIT2,Value);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CHealing",GetSafeHwnd());

	return TRUE;
}

void CHealing::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CHealing",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CRetort dialog

IMPLEMENT_DYNAMIC(CRetort, CDialogEx)

CRetort::CRetort(CWnd* pParent /*=NULL*/)
	: CDialogEx(CRetort::IDD, pParent)
{

}

CRetort::~CRetort()
{
}

void CRetort::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CRetort, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CRetort::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CRetort::OnBnClickedOk2)
END_MESSAGE_MAP()


// Retort message handlers

void CRetort::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(24,0,1,Str2CharArray(Text));

	TCHAR Text1[255];
	GetDlgItemText(IDC_EDIT4,Text1,255);
	SetArrayValue(24,1,1,Str2CharArray(Text1));

	TCHAR Text2[255];
	GetDlgItemText(IDC_EDIT6,Text2,255);
	SetArrayValue(24,2,1,Str2CharArray(Text2));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_RetortDlg->DestroyWindow();

	m_RetortDlg = NULL;
}

void CRetort::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_RetortDlg->DestroyWindow();

	m_RetortDlg = NULL;
}

BOOL CRetort::OnInitDialog()
{
	char * Value = GetArrayValue(24,0,1);
	SetDlgItemText(IDC_EDIT2,Value);
	char * Value1 = GetArrayValue(24,1,1);
	SetDlgItemText(IDC_EDIT4,Value1);
	char * Value2 = GetArrayValue(24,2,1);
	SetDlgItemText(IDC_EDIT6,Value2);

	char * Value3 = GetArrayValue(24,0,0);
	SetDlgItemText(IDC_EDIT1,Value3);
	char * Value4 = GetArrayValue(24,1,0);
	SetDlgItemText(IDC_EDIT3,Value4);
	char * Value5 = GetArrayValue(24,2,0);
	SetDlgItemText(IDC_EDIT5,Value5);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CRetort",GetSafeHwnd());

	return TRUE;
}

void CRetort::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CRetort",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CGoldMana dialog

IMPLEMENT_DYNAMIC(CGoldMana, CDialogEx)

CGoldMana::CGoldMana(CWnd* pParent /*=NULL*/)
	: CDialogEx(CGoldMana::IDD, pParent)
{

}

CGoldMana::~CGoldMana()
{
}

void CGoldMana::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CGoldMana, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CGoldMana::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CGoldMana::OnBnClickedOk2)
END_MESSAGE_MAP()


// GoldMana message handlers

void CGoldMana::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(25,0,1,Str2CharArray(Text));

	TCHAR Text1[255];
	GetDlgItemText(IDC_EDIT4,Text1,255);
	SetArrayValue(25,1,1,Str2CharArray(Text1));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_GoldManaDlg->DestroyWindow();

	m_GoldManaDlg = NULL;
}

void CGoldMana::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_GoldManaDlg->DestroyWindow();

	m_GoldManaDlg = NULL;
}

BOOL CGoldMana::OnInitDialog()
{
	char * Value = GetArrayValue(25,0,1);
	SetDlgItemText(IDC_EDIT2,Value);
	char * Value1 = GetArrayValue(25,1,1);
	SetDlgItemText(IDC_EDIT4,Value1);

	char * Value2 = GetArrayValue(25,0,0);
	SetDlgItemText(IDC_EDIT1,Value2);
	char * Value3 = GetArrayValue(25,1,0);
	SetDlgItemText(IDC_EDIT3,Value3);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CGoldMana",GetSafeHwnd());

	return TRUE;
}

void CGoldMana::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CGoldMana",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

IMPLEMENT_DYNAMIC(CSettings, CDialogEx)

CSettings::CSettings(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSettings::IDD, pParent)
{

}

CSettings::~CSettings()
{
}

void CSettings::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSettings, CDialogEx)
	ON_EN_CHANGE(IDC_WIZARD_FOLDER, &CSettings::OnEnChangeWizardFolder)
	ON_EN_CHANGE(IDC_TEXT_FOLDER, &CSettings::OnEnChangeTextFolder)
	ON_BN_CLICKED(IDC_EXTRACT, &CSettings::OnBnClickedExtract)
	ON_BN_CLICKED(IDC_WRITE, &CSettings::OnBnClickedWrite)
	ON_BN_CLICKED(IDC_LOAD_TEXT, &CSettings::OnBnClickedLoadText)
	ON_BN_CLICKED(IDC_SAVE_TEXT, &CSettings::OnBnClickedSaveText)
	ON_BN_CLICKED(IDOK, &CSettings::OnBnClickedOk)
	ON_WM_WINDOWPOSCHANGED()
END_MESSAGE_MAP()


// CSettings message handlers

void CSettings::OnEnChangeWizardFolder()
{

	//ZeroMemory( &ofn , sizeof( ofn));
	//ofn.lStructSize = sizeof ( ofn );
	//ofn.hwndOwner = NULL;
	//ofn.lpstrFile = szFile;
	//ofn.lpstrFile[0] = '\0';
	//ofn.nMaxFile = sizeof( szFile );
	//ofn.lpstrFilter = "exe\0*.exe\0txt\0*.txt\0all\0*.*";
	//ofn.nFilterIndex =1;
	//ofn.lpstrFileTitle = NULL;
	//ofn.nMaxFileTitle = 0;
	//ofn.lpstrInitialDir=NULL;
	//ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

	//GetOpenFileName( &ofn );
	//
 //  if (Extention == "txt\0*.txt\0exe\0*.exe\0all\0*.*") {
 //     SetDlgItemText(hSettings,IDC_TEXT_NAME,ofn.lpstrFile);
 //  } else if (Extention == ) {
 //     SetDlgItemText(hSettings,IDC_EXECUTABLE_NAME,ofn.lpstrFile);
 //  }
	TCHAR Value[255];
	GetDlgItemText(IDC_WIZARD_FOLDER,Value,255);
	AfxGetApp()->WriteProfileString("MoM Settings","Wizard Folder",Value);
}

void CSettings::OnEnChangeTextFolder()
{
	TCHAR Value[255];
	GetDlgItemText(IDC_TEXT_FOLDER,Value,255);
	txt_fname = CharArray2Str(Value);
	AfxGetApp()->WriteProfileString("MoM Settings","Text File",Value);
}


void CSettings::OnBnClickedExtract()
{
	m_progress = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS);
	m_progress->SetRange(0, rec_t_cnt);
	m_progress->SetStep(1);
	extract();
	Loaded = 1;
	m_progress->SetPos(0);

}


void CSettings::OnBnClickedWrite()
{
	if (strcmp(GetArrayValue(0,0,0),"Not Set") == 0) {
		CallMessageBox("You Must Load Or Extract A File Before Writting.");
	} else {
		m_progress = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS);
		m_progress->SetRange(0, rec_t_cnt);
		m_progress->SetStep(1);
		translate();
		m_progress->SetPos(0);
	}
}


void CSettings::OnBnClickedLoadText()
{
	m_progress = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS);
	m_progress->SetRange(0, rec_t_cnt);
	m_progress->SetStep(1);
	LoadDataFileToArray_i();
	Loaded = 1;
	m_progress->SetPos(0);
}


void CSettings::OnBnClickedSaveText()
{
	m_progress = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS);
	m_progress->SetRange(0, rec_t_cnt);
	m_progress->SetStep(1);
	SaveArrayToDataFile();
	m_progress->SetPos(0);
}


void CSettings::OnBnClickedOk()
{
	CDialogEx::OnOK();

	m_SettingsDlg->DestroyWindow();

	m_SettingsDlg = NULL;
}


BOOL CSettings::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CSettings",GetSafeHwnd());

	CString Wizard = AfxGetApp()->GetProfileString("MoM Settings","Wizard Folder","");
	CString Text = AfxGetApp()->GetProfileString("MoM Settings","Text File","");
	SetDlgItemText(IDC_WIZARD_FOLDER,(LPTSTR)(LPCTSTR)Wizard);
	SetDlgItemText(IDC_TEXT_FOLDER,(LPTSTR)(LPCTSTR)Text);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CSettings::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CSettings",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CSection dialog

IMPLEMENT_DYNAMIC(CSection, CDialogEx)

CSection::CSection(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSection::IDD, pParent)
{

}

CSection::~CSection()
{
}

void CSection::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SECTION_BUTTONS, m_SectionButtons);
}


BEGIN_MESSAGE_MAP(CSection, CDialogEx)
	ON_LBN_DBLCLK(IDC_SECTION_BUTTONS, &CSection::OnLbnDblclkSectionButtons)
	ON_BN_CLICKED(IDOK, &CSection::OnBnClickedOk)
	ON_WM_WINDOWPOSCHANGED()
END_MESSAGE_MAP()


// CSection message handlers
int SelectedButton()
{
	//CallMessageBox("Button Number : ",Int2Str(ButtonNameIndex));
	if (ButtonNameIndex == 0) {
		if (!m_ItemPwrDlg) {
			m_ItemPwrDlg = new CItemPwr();
			m_ItemPwrDlg->Create(IDD_ITEM_POWERS);
		}
		m_ItemPwrDlg->ShowWindow(SW_SHOW);
		m_ItemPwrDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);

	}
	if (ButtonNameIndex == 1) {
		if (!m_BuildingDlg) {
			m_BuildingDlg = new CBuilding();
			m_BuildingDlg->Create(IDD_BUILDINGS);
		}
		m_BuildingDlg->ShowWindow(SW_SHOW);
		m_BuildingDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
	}
	if (ButtonNameIndex == 2) {
		if (!m_SpellDlg) {
			m_SpellDlg = new CSpell();
			m_SpellDlg->Create(IDD_SPELLS);
		}
		m_SpellDlg->ShowWindow(SW_SHOW);
		m_SpellDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
	}
	if (ButtonNameIndex == 3) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
	}
	if (ButtonNameIndex == 4) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
	}
	if (ButtonNameIndex == 5) {
 		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
	}
	if (ButtonNameIndex == 6) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
	}
	if (ButtonNameIndex == 7) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
	}
   if (ButtonNameIndex == 8) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 9) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 10) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 11) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 12) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 13) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 14) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 15) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 16) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 17) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 18) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 19) {
		if (!m_UnitsDlg) {
			m_UnitsDlg = new CUnits();
			m_UnitsDlg->Create(IDD_UNITS);
		}
		m_UnitsDlg->ShowWindow(SW_SHOW);
		m_UnitsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 20) {
		if (!m_RaceDataDlg) {
			m_RaceDataDlg = new CRaceData();
			m_RaceDataDlg->Create(IDD_RACE_DATA);
		}
		m_RaceDataDlg->ShowWindow(SW_SHOW);
		m_RaceDataDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 21) {
		if (!m_UpkeepDlg) {
			m_UpkeepDlg = new CUpkeepCost();
			m_UpkeepDlg->Create(IDD_UPKEEP);
		}
		m_UpkeepDlg->ShowWindow(SW_SHOW);
		m_UpkeepDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 22) {
		if (!m_HeroStatsDlg) {
			m_HeroStatsDlg = new CHeroStats();
			m_HeroStatsDlg->Create(IDD_HERO_UNIQUE_STATS);
		}
		m_HeroStatsDlg->ShowWindow(SW_SHOW);
		m_HeroStatsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 23) {
		if (!m_HealingDlg) {
			m_HealingDlg = new CHealing();
			m_HealingDlg->Create(IDD_HEALING);
		}
		m_HealingDlg->ShowWindow(SW_SHOW);
		m_HealingDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 24) {
		if (!m_RetortDlg) {
			m_RetortDlg = new CRetort();
			m_RetortDlg->Create(IDD_RETORT);
		}
		m_RetortDlg->ShowWindow(SW_SHOW);
		m_RetortDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 25) {
		if (!m_GoldManaDlg) {
			m_GoldManaDlg = new CGoldMana();
			m_GoldManaDlg->Create(IDD_GOLD);
		}
		m_GoldManaDlg->ShowWindow(SW_SHOW);
		m_GoldManaDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 26) {
		if (!m_WizardPicksDlg) {
			m_WizardPicksDlg = new CWizardPicks();
			m_WizardPicksDlg->Create(IDD_PICKS);
		}
		m_WizardPicksDlg->ShowWindow(SW_SHOW);
		m_WizardPicksDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 27) {
		if (!m_ItemRewardsDlg) {
			m_ItemRewardsDlg = new CItemRewards();
			m_ItemRewardsDlg->Create(IDD_REWARD_VALUE);
		}
		m_ItemRewardsDlg->ShowWindow(SW_SHOW);
		m_ItemRewardsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 28) {
		if (!m_CityDistanceDlg) {
			m_CityDistanceDlg = new CCityDistance();
			m_CityDistanceDlg->Create(IDD_CITY_DISTANCE);
		}
		m_CityDistanceDlg->ShowWindow(SW_SHOW);
		m_CityDistanceDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 29) {
		if (!m_RetortEffectsDlg) {
			m_RetortEffectsDlg = new CRetortEffects();
			m_RetortEffectsDlg->Create(IDD_RETORT_EFFECTS);
		}
		m_RetortEffectsDlg->ShowWindow(SW_SHOW);
		m_RetortEffectsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 30) {
		if (!m_SpellChargesDlg) {
			m_SpellChargesDlg = new CSpellCharges();
			m_SpellChargesDlg->Create(IDD_SPELL_CHARGES);
		}
		m_SpellChargesDlg->ShowWindow(SW_SHOW);
		m_SpellChargesDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 31) {
		if (!m_CreateItemDlg) {
			m_CreateItemDlg = new CCreateItem();
			m_CreateItemDlg->Create(IDD_ENCHANT_BASE_COST);
		}
		m_CreateItemDlg->ShowWindow(SW_SHOW);
		m_CreateItemDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 32) {
		if (!m_ItemMaximumDlg) {
			m_ItemMaximumDlg = new CItemMaximum();
			m_ItemMaximumDlg->Create(IDD_ENCHANT_ITEM_MAX);
		}
		m_ItemMaximumDlg->ShowWindow(SW_SHOW);
		m_ItemMaximumDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 33) {
		if (!m_DestroyedItemsDlg) {
			m_DestroyedItemsDlg = new CDestroyedItems();
			m_DestroyedItemsDlg->Create(IDD_DESTROY_ITEM);
		}
		m_DestroyedItemsDlg->ShowWindow(SW_SHOW);
		m_DestroyedItemsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 34) {
		if (!m_SpellsPerBookDlg) {
			m_SpellsPerBookDlg = new CSpellsPerBook();
			m_SpellsPerBookDlg->Create(IDD_SPELLS_PER_BOOK);
		}
		m_SpellsPerBookDlg->ShowWindow(SW_SHOW);
		m_SpellsPerBookDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 35) {
		if (!m_RandomEventsDlg) {
			m_RandomEventsDlg = new CRandomEvents();
			m_RandomEventsDlg->Create(IDD_RANDOM_EVENTS);
		}
		m_RandomEventsDlg->ShowWindow(SW_SHOW);
		m_RandomEventsDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 36) {
		if (!m_MapGenerationDlg) {
			m_MapGenerationDlg = new CMapGeneration();
			m_MapGenerationDlg->Create(IDD_MAP_GENERATION);
		}
		m_MapGenerationDlg->ShowWindow(SW_SHOW);
		m_MapGenerationDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 37) {
		if (!m_BookResearchDlg) {
			m_BookResearchDlg = new CBookResearch();
			m_BookResearchDlg->Create(IDD_RESEARCH_FROM_BOOKS);
		}
		m_BookResearchDlg->ShowWindow(SW_SHOW);
		m_BookResearchDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 38) {
		if (!m_HireHeroDlg) {
			m_HireHeroDlg = new CHireHero();
			m_HireHeroDlg->Create(IDD_HIRE_HERO);
		}
		m_HireHeroDlg->ShowWindow(SW_SHOW);
		m_HireHeroDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 39) {
		if (!m_HireMercDlg) {
			m_HireMercDlg = new CHireMerc();
			m_HireMercDlg->Create(IDD_HIRE_MERC);
		}
		m_HireMercDlg->ShowWindow(SW_SHOW);
		m_HireMercDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 40) {
		if (!m_ItemBuyChanceDlg) {
			m_ItemBuyChanceDlg = new CItemBuyChance();
			m_ItemBuyChanceDlg->Create(IDD_BUY_ITEM);
		}
		m_ItemBuyChanceDlg->ShowWindow(SW_SHOW);
		m_ItemBuyChanceDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 41) {
		if (!m_MiscDlg) {
			m_MiscDlg = new CMisc();
			m_MiscDlg->Create(IDD_MISC);
		}
		m_MiscDlg->ShowWindow(SW_SHOW);
		m_MiscDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
   if (ButtonNameIndex == 42) {
		if (!m_FoodBonusesDlg) {
			m_FoodBonusesDlg = new CFoodBonuses();
			m_FoodBonusesDlg->Create(IDD_FOOD_BONUS);
		}
		m_FoodBonusesDlg->ShowWindow(SW_SHOW);
		m_FoodBonusesDlg->SetWindowText(ListBoxButtons[ButtonNameIndex]);
   }
	return 0;
}

void CSection::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CSection",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

void CSection::OnLbnDblclkSectionButtons()
{
	ButtonNameIndex = m_SectionButtons.GetCurSel();
	SelectedButton();
}

void CSection::OnBnClickedOk()
{
	CDialogEx::OnOK();

	m_SectionDlg->DestroyWindow();

	m_SectionDlg = NULL;
}


BOOL CSection::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	LoadDialogRect("CSection",GetSafeHwnd());

	for (int i = 0; i < rec_t_cnt;i++) {
		if (ReturnViableSections(i)) {
			m_SectionButtons.AddString(ListBoxButtons[i]);
			SendDlgItemMessage(IDC_SECTION_BUTTONS,LB_SETITEMHEIGHT,(WPARAM)i,(LPARAM)25);
		}
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

// CWizardPicks dialog

IMPLEMENT_DYNAMIC(CWizardPicks, CDialogEx)

CWizardPicks::CWizardPicks(CWnd* pParent /*=NULL*/)
	: CDialogEx(CWizardPicks::IDD, pParent)
{

}

CWizardPicks::~CWizardPicks()
{
}

void CWizardPicks::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CWizardPicks, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CWizardPicks::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CWizardPicks::OnBnClickedOk2)
END_MESSAGE_MAP()


// WizardPicks message handlers

void CWizardPicks::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[26];j++) {
		for(int Step = 0;Step < step_max[26];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Wizard_Picks_EditControlID[j][Step],Text,255);
			SetArrayValue(26,j,Step,Text);
		}
	}

	CDialogEx::OnOK();

	ButtonNameIndex = -1;

	m_WizardPicksDlg->DestroyWindow();

	m_WizardPicksDlg = NULL;
}

void CWizardPicks::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_WizardPicksDlg->DestroyWindow();

	m_WizardPicksDlg = NULL;
}

BOOL CWizardPicks::OnInitDialog()
{
	for (int j = 0;j < rec_count[26];j++) {
		for(int Step = 0;Step < step_max[26];Step++) {
			SetDlgItemText(Wizard_Picks_EditControlID[j][Step],GetArrayValue(26,j,Step));
		}
	}

	CDialogEx::OnInitDialog();

	LoadDialogRect("CWizardPicks",GetSafeHwnd());

	return TRUE;
}

void CWizardPicks::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CWizardPicks",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);
}

// CItemRewards dialog

IMPLEMENT_DYNAMIC(CItemRewards, CDialogEx)

CItemRewards::CItemRewards(CWnd* pParent /*=NULL*/)
	: CDialogEx(CItemRewards::IDD, pParent)
{

}

CItemRewards::~CItemRewards()
{
}

void CItemRewards::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CItemRewards, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CItemRewards::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CItemRewards::OnBnClickedOk2)
END_MESSAGE_MAP()


// ItemRewards message handlers

void CItemRewards::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(27,0,1,Str2CharArray(Text));

	TCHAR Text1[255];
	GetDlgItemText(IDC_EDIT4,Text1,255);
	SetArrayValue(27,1,1,Str2CharArray(Text1));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_ItemRewardsDlg->DestroyWindow();

	m_ItemRewardsDlg = NULL;
}

void CItemRewards::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_ItemRewardsDlg->DestroyWindow();

	m_ItemRewardsDlg = NULL;
}

BOOL CItemRewards::OnInitDialog()
{
	char * Value = GetArrayValue(27,0,1);
	SetDlgItemText(IDC_EDIT2,Value);
	char * Value1 = GetArrayValue(27,1,1);
	SetDlgItemText(IDC_EDIT4,Value1);

	char * Value2 = GetArrayValue(27,0,0);
	SetDlgItemText(IDC_EDIT1,Value2);
	char * Value3 = GetArrayValue(27,1,0);
	SetDlgItemText(IDC_EDIT3,Value3);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CItemRewards",GetSafeHwnd());

	return TRUE;
}

void CItemRewards::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CItemRewards",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CCityDistance dialog

IMPLEMENT_DYNAMIC(CCityDistance, CDialogEx)

CCityDistance::CCityDistance(CWnd* pParent /*=NULL*/)
	: CDialogEx(CCityDistance::IDD, pParent)
{

}

CCityDistance::~CCityDistance()
{
}

void CCityDistance::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CCityDistance, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CCityDistance::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CCityDistance::OnBnClickedOk2)
END_MESSAGE_MAP()


// CityDistance message handlers

void CCityDistance::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(28,0,1,Str2CharArray(Text));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_CityDistanceDlg->DestroyWindow();

	m_CityDistanceDlg = NULL;
}

void CCityDistance::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_CityDistanceDlg->DestroyWindow();

	m_CityDistanceDlg = NULL;
}

BOOL CCityDistance::OnInitDialog()
{
	char * Value = GetArrayValue(28,0,0);
	SetDlgItemText(IDC_EDIT1,Value);
	char * Value1 = GetArrayValue(28,0,1);
	SetDlgItemText(IDC_EDIT2,Value1);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CCityDistance",GetSafeHwnd());

	return TRUE;
}

void CCityDistance::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CCityDistance",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CRetortEffects dialog

IMPLEMENT_DYNAMIC(CRetortEffects, CDialogEx)

CRetortEffects::CRetortEffects(CWnd* pParent /*=NULL*/)
	: CDialogEx(CRetortEffects::IDD, pParent)
{

}

CRetortEffects::~CRetortEffects()
{
}

void CRetortEffects::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CRetortEffects, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CRetortEffects::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CRetortEffects::OnBnClickedOk2)
END_MESSAGE_MAP()


// RetortEffects message handlers

void CRetortEffects::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[29];j++) {
		for(int Step = 0;Step < step_max[29];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Wizard_Picks_EditControlID[j][Step],Text,255);
			SetArrayValue(29,j,Step,Text);
		}
	}
	CDialogEx::OnOK();

	ButtonNameIndex = -1;

	m_RetortEffectsDlg->DestroyWindow();

	m_RetortEffectsDlg = NULL;
}

void CRetortEffects::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_RetortEffectsDlg->DestroyWindow();

	m_RetortEffectsDlg = NULL;
}

BOOL CRetortEffects::OnInitDialog()
{
	for (int j = 0;j < rec_count[29];j++) {
		for(int Step = 0;Step < step_max[29];Step++) {
			SetDlgItemText(Wizard_Picks_EditControlID[j][Step],GetArrayValue(29,j,Step));
		}
	}

	CDialogEx::OnInitDialog();

	LoadDialogRect("CRetortEffects",GetSafeHwnd());

	return TRUE;
}

void CRetortEffects::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CRetortEffects",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);
}

// CSpellCharges dialog

IMPLEMENT_DYNAMIC(CSpellCharges, CDialogEx)

CSpellCharges::CSpellCharges(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSpellCharges::IDD, pParent)
{

}

CSpellCharges::~CSpellCharges()
{
}

void CSpellCharges::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSpellCharges, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CSpellCharges::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CSpellCharges::OnBnClickedOk2)
END_MESSAGE_MAP()


// SpellCharges message handlers

void CSpellCharges::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(30,0,1,Str2CharArray(Text));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_SpellChargesDlg->DestroyWindow();

	m_SpellChargesDlg = NULL;
}

void CSpellCharges::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_SpellChargesDlg->DestroyWindow();

	m_SpellChargesDlg = NULL;
}

BOOL CSpellCharges::OnInitDialog()
{
	char * Value = GetArrayValue(30,0,0);
	SetDlgItemText(IDC_EDIT1,Value);
	char * Value1 = GetArrayValue(30,0,1);
	SetDlgItemText(IDC_EDIT2,Value1);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CSpellCharges",GetSafeHwnd());

	return TRUE;
}

void CSpellCharges::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CSpellCharges",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CCreateItem dialog

IMPLEMENT_DYNAMIC(CCreateItem, CDialogEx)

CCreateItem::CCreateItem(CWnd* pParent /*=NULL*/)
	: CDialogEx(CCreateItem::IDD, pParent)
{

}

CCreateItem::~CCreateItem()
{
}

void CCreateItem::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CCreateItem, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CCreateItem::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CCreateItem::OnBnClickedOk2)
END_MESSAGE_MAP()


// CreateItem message handlers

void CCreateItem::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[31];j++) {
		for(int Step = 0;Step < step_max[31];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Create_Base_Costs_EditControlID[j][Step],Text,255);
			SetArrayValue(31,j,Step,Text);
		}
	}

	CDialogEx::OnOK();

	ButtonNameIndex = -1;

	m_CreateItemDlg->DestroyWindow();

	m_CreateItemDlg = NULL;
}

void CCreateItem::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_CreateItemDlg->DestroyWindow();

	m_CreateItemDlg = NULL;
}

BOOL CCreateItem::OnInitDialog()
{
	for (int j = 0;j < rec_count[31];j++) {
		for(int Step = 0;Step < step_max[31];Step++) {
			SetDlgItemText(Create_Base_Costs_EditControlID[j][Step],GetArrayValue(31,j,Step));
		}
	}

	CDialogEx::OnInitDialog();

	LoadDialogRect("CCreateItem",GetSafeHwnd());

	return TRUE;
}

void CCreateItem::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CCreateItem",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);
}

// CItemMaximum dialog

IMPLEMENT_DYNAMIC(CItemMaximum, CDialogEx)

CItemMaximum::CItemMaximum(CWnd* pParent /*=NULL*/)
	: CDialogEx(CItemMaximum::IDD, pParent)
{

}

CItemMaximum::~CItemMaximum()
{
}

void CItemMaximum::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CItemMaximum, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CItemMaximum::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CItemMaximum::OnBnClickedOk2)
END_MESSAGE_MAP()

// ItemMaximum message handlers

void CItemMaximum::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(32,0,1,Str2CharArray(Text));

	TCHAR Text1[255];
	GetDlgItemText(IDC_EDIT4,Text1,255);
	SetArrayValue(32,1,1,Str2CharArray(Text1));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_ItemMaximumDlg->DestroyWindow();

	m_ItemMaximumDlg = NULL;
}

void CItemMaximum::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_ItemMaximumDlg->DestroyWindow();

	m_ItemMaximumDlg = NULL;
}

BOOL CItemMaximum::OnInitDialog()
{
	char * Value = GetArrayValue(32,0,1);
	SetDlgItemText(IDC_EDIT2,Value);
	char * Value1 = GetArrayValue(32,1,1);
	SetDlgItemText(IDC_EDIT4,Value1);

	char * Value2 = GetArrayValue(32,0,0);
	SetDlgItemText(IDC_EDIT1,Value2);
	char * Value3 = GetArrayValue(32,1,0);
	SetDlgItemText(IDC_EDIT3,Value3);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CItemMaximum",GetSafeHwnd());

	return TRUE;
}

void CItemMaximum::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CItemMaximum",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CDestroyedItems dialog

IMPLEMENT_DYNAMIC(CDestroyedItems, CDialogEx)

CDestroyedItems::CDestroyedItems(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDestroyedItems::IDD, pParent)
{

}

CDestroyedItems::~CDestroyedItems()
{
}

void CDestroyedItems::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDestroyedItems, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CDestroyedItems::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CDestroyedItems::OnBnClickedOk2)
END_MESSAGE_MAP()


// DestroyedItems message handlers

void CDestroyedItems::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	if (Str2Int(Text) != 50 && Str2Int(Text) != 25) {
		CallMessageBox("Value Must Be Either 25 or 50.");
	} else {
		SetArrayValue(33,0,1,Str2CharArray(Text));

		ButtonNameIndex = -1;

		CDialogEx::OnOK();

		m_DestroyedItemsDlg->DestroyWindow();

		m_DestroyedItemsDlg = NULL;
	}
}

void CDestroyedItems::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_DestroyedItemsDlg->DestroyWindow();

	m_DestroyedItemsDlg = NULL;
}

BOOL CDestroyedItems::OnInitDialog()
{
	char * Value1 = GetArrayValue(33,0,0);
	SetDlgItemText(IDC_EDIT1,Value1);
	char * Value = GetArrayValue(33,0,1);
	SetDlgItemText(IDC_EDIT2,Value);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CDestroyedItems",GetSafeHwnd());

	return TRUE;
}

void CDestroyedItems::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CDestroyedItems",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}


// CSpellsPerBook dialog

IMPLEMENT_DYNAMIC(CSpellsPerBook, CDialogEx)

CSpellsPerBook::CSpellsPerBook(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSpellsPerBook::IDD, pParent)
{

}

CSpellsPerBook::~CSpellsPerBook()
{
}

void CSpellsPerBook::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSpellsPerBook, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CSpellsPerBook::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CSpellsPerBook::OnBnClickedOk2)
END_MESSAGE_MAP()


// SpellsPerBook message handlers

void CSpellsPerBook::OnBnClickedOk()
{
	for(int Step = 0;Step < step_max[34];Step++) {
		TCHAR Text[255];
		GetDlgItemText(Spells_Per_Book_EditControlID[Step],Text,255);
		SetArrayValue(34,0,Step,Text);
	}

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_SpellsPerBookDlg->DestroyWindow();

	m_SpellsPerBookDlg = NULL;
}

void CSpellsPerBook::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_SpellsPerBookDlg->DestroyWindow();

	m_SpellsPerBookDlg = NULL;
}

BOOL CSpellsPerBook::OnInitDialog()
{
	for(int Step = 0;Step < step_max[34];Step++) {
		SetDlgItemText(Spells_Per_Book_EditControlID[Step],GetArrayValue(34,0,Step));
		SetDlgItemText(Spells_Per_Book_HelpControlID[Step],Spells_Per_Book_Help[Step]);
	}

	CDialogEx::OnInitDialog();

	LoadDialogRect("CSpellsPerBook",GetSafeHwnd());

	return TRUE;
}

void CSpellsPerBook::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CSpellsPerBook",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CRandomEvents dialog

IMPLEMENT_DYNAMIC(CRandomEvents, CDialogEx)

CRandomEvents::CRandomEvents(CWnd* pParent /*=NULL*/)
	: CDialogEx(CRandomEvents::IDD, pParent)
{

}

CRandomEvents::~CRandomEvents()
{
}

void CRandomEvents::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CRandomEvents, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CRandomEvents::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CRandomEvents::OnBnClickedOk2)
END_MESSAGE_MAP()


// RandomEvents message handlers

void CRandomEvents::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(35,0,1,Str2CharArray(Text));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_RandomEventsDlg->DestroyWindow();

	m_RandomEventsDlg = NULL;
}

void CRandomEvents::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_RandomEventsDlg->DestroyWindow();

	m_RandomEventsDlg = NULL;
}

BOOL CRandomEvents::OnInitDialog()
{
	char * Value = GetArrayValue(35,0,0);
	SetDlgItemText(IDC_EDIT1,Value);
	char * Value1 = GetArrayValue(35,0,1);
	SetDlgItemText(IDC_EDIT2,Value1);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CRandomEvents",GetSafeHwnd());

	return TRUE;
}

void CRandomEvents::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CRandomEvents",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CMapGeneration dialog

IMPLEMENT_DYNAMIC(CMapGeneration, CDialogEx)

CMapGeneration::CMapGeneration(CWnd* pParent /*=NULL*/)
	: CDialogEx(CMapGeneration::IDD, pParent)
{

}

CMapGeneration::~CMapGeneration()
{
}

void CMapGeneration::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CMapGeneration, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CMapGeneration::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CMapGeneration::OnBnClickedOk2)
END_MESSAGE_MAP()


// MapGeneration message handlers

void CMapGeneration::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[36];j++) {
		for(int Step = 0;Step < step_max[36];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Map_Generation_EditControlID[j][Step],Text,255);
			SetArrayValue(36,j,Step,Text);
		}
	}

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_MapGenerationDlg->DestroyWindow();

	m_MapGenerationDlg = NULL;
}

void CMapGeneration::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_MapGenerationDlg->DestroyWindow();

	m_MapGenerationDlg = NULL;
}

BOOL CMapGeneration::OnInitDialog()
{
	for (int j = 0;j < rec_count[36];j++) {
		for(int Step = 0;Step < step_max[36];Step++) {
			SetDlgItemText(Map_Generation_EditControlID[j][Step],GetArrayValue(36,j,Step));
		}
	}

	CDialogEx::OnInitDialog();

	LoadDialogRect("CMapGeneration",GetSafeHwnd());

	return TRUE;
}

void CMapGeneration::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CMapGeneration",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CBookResearch dialog

IMPLEMENT_DYNAMIC(CBookResearch, CDialogEx)

CBookResearch::CBookResearch(CWnd* pParent /*=NULL*/)
	: CDialogEx(CBookResearch::IDD, pParent)
{

}

CBookResearch::~CBookResearch()
{
}

void CBookResearch::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CBookResearch, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CBookResearch::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CBookResearch::OnBnClickedOk2)
END_MESSAGE_MAP()


// BookResearch message handlers

void CBookResearch::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[37];j++) {
		for(int Step = 0;Step < step_max[37];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Research_From_Books_EditControlID[j][Step],Text,255);
			SetArrayValue(37,j,Step,Text);
		}
	}

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_BookResearchDlg->DestroyWindow();

	m_BookResearchDlg = NULL;
}

void CBookResearch::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_BookResearchDlg->DestroyWindow();

	m_BookResearchDlg = NULL;
}

BOOL CBookResearch::OnInitDialog()
{
	for (int j = 0;j < rec_count[37];j++) {
		for(int Step = 0;Step < step_max[37];Step++) {
			SetDlgItemText(Research_From_Books_EditControlID[j][Step],GetArrayValue(37,j,Step));
		}
	}

	CDialogEx::OnInitDialog();

	LoadDialogRect("CBookResearch",GetSafeHwnd());

	return TRUE;
}

void CBookResearch::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CBookResearch",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CHireHero dialog

IMPLEMENT_DYNAMIC(CHireHero, CDialogEx)

CHireHero::CHireHero(CWnd* pParent /*=NULL*/)
	: CDialogEx(CHireHero::IDD, pParent)
{

}

CHireHero::~CHireHero()
{
}

void CHireHero::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CHireHero, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CHireHero::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CHireHero::OnBnClickedOk2)
END_MESSAGE_MAP()


// HireHero message handlers

void CHireHero::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[38];j++) {
		for(int Step = 0;Step < step_max[38];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Hero_Join_EditControlID[j][Step],Text,255);
			SetArrayValue(38,j,Step,Text);
		}
	}

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_HireHeroDlg->DestroyWindow();

	m_HireHeroDlg = NULL;
}

void CHireHero::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_HireHeroDlg->DestroyWindow();

	m_HireHeroDlg = NULL;
}

BOOL CHireHero::OnInitDialog()
{
	for (int j = 0;j < rec_count[38];j++) {
		for(int Step = 0;Step < step_max[38];Step++) {
			SetDlgItemText(Hero_Join_EditControlID[j][Step],GetArrayValue(38,j,Step));
		}
	}

	//SetDlgItemText(Hero_Join_HelpControlID[0],Hero_Join_Help[0]);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CHireHero",GetSafeHwnd());

	return TRUE;
}

void CHireHero::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CHireHero",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}


// CHireMerc dialog

IMPLEMENT_DYNAMIC(CHireMerc, CDialogEx)

CHireMerc::CHireMerc(CWnd* pParent /*=NULL*/)
	: CDialogEx(CHireMerc::IDD, pParent)
{

}

CHireMerc::~CHireMerc()
{
}

void CHireMerc::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CHireMerc, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CHireMerc::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CHireMerc::OnBnClickedOk2)
END_MESSAGE_MAP()


// HireMerc message handlers

void CHireMerc::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[39];j++) {
		for(int Step = 0;Step < step_max[39];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Merc_Join_EditControlID[j][Step],Text,255);
			SetArrayValue(39,j,Step,Text);
		}
	}

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_HireMercDlg->DestroyWindow();

	m_HireMercDlg = NULL;
}

void CHireMerc::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_HireMercDlg->DestroyWindow();

	m_HireMercDlg = NULL;
}

BOOL CHireMerc::OnInitDialog()
{
	for (int j = 0;j < rec_count[39];j++) {
		for(int Step = 0;Step < step_max[39];Step++) {
			SetDlgItemText(Merc_Join_EditControlID[j][Step],GetArrayValue(39,j,Step));
		}
	}

	//SetDlgItemText(Merc_Join_HelpControlID[0],Merc_Join_Help[0]);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CHireMerc",GetSafeHwnd());

	return TRUE;
}

void CHireMerc::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CHireMerc",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}


// CMisc dialog

IMPLEMENT_DYNAMIC(CMisc, CDialogEx)

CMisc::CMisc(CWnd* pParent /*=NULL*/)
	: CDialogEx(CMisc::IDD, pParent)
{

}

CMisc::~CMisc()
{
}

void CMisc::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CMisc, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CMisc::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CMisc::OnBnClickedOk2)
END_MESSAGE_MAP()


// Misc message handlers

void CMisc::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[41];j++) {
		for(int Step = 0;Step < step_max[41];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Misc_EditControlID[j][Step],Text,255);
			SetArrayValue(41,j,Step,Text);
		}
	}

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_MiscDlg->DestroyWindow();

	m_MiscDlg = NULL;
}

void CMisc::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_MiscDlg->DestroyWindow();

	m_MiscDlg = NULL;
}

BOOL CMisc::OnInitDialog()
{
	for (int j = 0;j < rec_count[41];j++) {
		for(int Step = 0;Step < step_max[41];Step++) {
			SetDlgItemText(Misc_EditControlID[j][Step],GetArrayValue(41,j,Step));
		}
	}

	//SetDlgItemText(Merc_Join_HelpControlID[0],Merc_Join_Help[0]);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CMisc",GetSafeHwnd());

	return TRUE;
}

void CMisc::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CMisc",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}

// CFoodBonuses dialog

IMPLEMENT_DYNAMIC(CFoodBonuses, CDialogEx)

CFoodBonuses::CFoodBonuses(CWnd* pParent /*=NULL*/)
	: CDialogEx(CFoodBonuses::IDD, pParent)
{

}

CFoodBonuses::~CFoodBonuses()
{
}

void CFoodBonuses::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CFoodBonuses, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CFoodBonuses::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CFoodBonuses::OnBnClickedOk2)
END_MESSAGE_MAP()


// FoodBonuses message handlers

void CFoodBonuses::OnBnClickedOk()
{
	for (int j = 0;j < rec_count[42];j++) {
		for(int Step = 0;Step < step_max[42];Step++) {
			TCHAR Text[255];
			GetDlgItemText(Food_Bonuses_EditControlID[j][Step],Text,255);
			SetArrayValue(42,j,Step,Text);
		}
	}

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_FoodBonusesDlg->DestroyWindow();

	m_FoodBonusesDlg = NULL;
}

void CFoodBonuses::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_FoodBonusesDlg->DestroyWindow();

	m_FoodBonusesDlg = NULL;
}

BOOL CFoodBonuses::OnInitDialog()
{
	for (int j = 0;j < rec_count[42];j++) {
		for(int Step = 0;Step < step_max[42];Step++) {
			SetDlgItemText(Food_Bonuses_EditControlID[j][Step],GetArrayValue(42,j,Step));
		}
	}

	//SetDlgItemText(Merc_Join_HelpControlID[0],Merc_Join_Help[0]);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CFoodBonuses",GetSafeHwnd());

	return TRUE;
}

void CFoodBonuses::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CFoodBonuses",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}


// CItemBuyChance dialog

IMPLEMENT_DYNAMIC(CItemBuyChance, CDialogEx)

CItemBuyChance::CItemBuyChance(CWnd* pParent /*=NULL*/)
	: CDialogEx(CItemBuyChance::IDD, pParent)
{

}

CItemBuyChance::~CItemBuyChance()
{
}

void CItemBuyChance::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CItemBuyChance, CDialogEx)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDOK, &CItemBuyChance::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &CItemBuyChance::OnBnClickedOk2)
END_MESSAGE_MAP()


// ItemBuyChance message handlers

void CItemBuyChance::OnBnClickedOk()
{
	TCHAR Text[255];
	GetDlgItemText(IDC_EDIT2,Text,255);
	SetArrayValue(40,0,1,Str2CharArray(Text));

	ButtonNameIndex = -1;

	CDialogEx::OnOK();

	m_ItemBuyChanceDlg->DestroyWindow();

	m_ItemBuyChanceDlg = NULL;
}

void CItemBuyChance::OnBnClickedOk2()
{
	CDialogEx::OnOK();

	m_ItemBuyChanceDlg->DestroyWindow();

	m_ItemBuyChanceDlg = NULL;
}

BOOL CItemBuyChance::OnInitDialog()
{
	char * Value1 = GetArrayValue(40,0,0);
	SetDlgItemText(IDC_EDIT1,Value1);
	char * Value = GetArrayValue(40,0,1);
	SetDlgItemText(IDC_EDIT2,Value);

	CDialogEx::OnInitDialog();

	LoadDialogRect("CItemBuyChance",GetSafeHwnd());

	return TRUE;
}

void CItemBuyChance::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
	SaveDialogRect("CItemBuyChance",GetSafeHwnd());
	CDialogEx::OnWindowPosChanged(lpwndpos);

	// TODO: Add your message handler code here
}
