#include <Symbol.h>
#include <MyFrame.h>
#include <NewMath.h>
#include <barcode.h>
#include <Relay.h>
#include <Foxpro.h>

extern int nAfxLanguageVersion;
extern int nAfxCompanyVersion;

static int nAfxTestSystem = 0;


BOOL bAfxClickOther = FALSE;


//#include "Public.h"

//extern unsigned _stklen = 60u * 1024u;
//int FAR TransrateKey(CObject* pObj)
//{
//	return (0);
//}


extern char FAR AfxString[][GROBAL_CHARACTER_MAX];
extern BOOL bAfxManager;


static DWORD __MicroSeconds_Welcomm = 20lu * 1000lu;


BOOL bAfxManufaUser = FALSE;



BOOL FAR JudgePassword(char* pStrPassword, BOOL bManufa, BOOL bSuper)
{
	if (!bAfxManager)
	{
//		return(FALSE);
	}

#if defined(LANGUAGE_VERSION_ENGLISH)
	char bufCaption[80]= "Authority";
	if (bManufa)
	{
		::_fstrcpy(bufCaption, "Manufactor Authority");
	}
	else if (bSuper)
	{
		::_fstrcpy(bufCaption, "Super Authority");
	}
	else
	{
		::_fstrcpy(bufCaption, "Normal Authority");
	}
#else
	char bufCaption[80]= "权限";
	if (bManufa)
	{
		::_fstrcpy(bufCaption, "供应商权限");
	}
	else if (bSuper)
	{
		::_fstrcpy(bufCaption, "超级用户权限");
	}
	else
	{
		::_fstrcpy(bufCaption, "一般用户权限");
	}
#endif

	char password[80] = {'\0'};

	BOOL bPass = FALSE;

#if defined(LANGUAGE_VERSION_ENGLISH)
	while (::AfxInputDialog (bufCaption, "Input Authority Password:",
		(const char *)password, password, 18, TRUE))
#else
	while (::AfxInputDialog (bufCaption, "输入权限密码:",
		(const char *)password, password, 18, TRUE))
#endif
	{

		if (::_fstricmp (password, "13560730316") == 0 ||
			::_fstricmp (password, "firstsail") == 0)
		{
			bPass = TRUE;
			//bAfxManufaUser = TRUE;
			break;
		}


		if (::_fstricmp (password, pStrPassword) == 0)
		{
			bPass = TRUE;
			break;
		}



		if (!bManufa)
		{
			if (password[0] == '8' && pStrPassword[0] == '8')
			{
				bPass = TRUE;
				break;
			}
		}

	}

	if (bPass && bManufa)
	{
		bAfxManufaUser = TRUE;
	}

	return (bPass);
}

BOOL FAR ManufaJudge()
{
	return (::JudgePassword("FirstSail", TRUE, TRUE));
}

BOOL FAR SuperJudge()
{
	return (::JudgePassword("8", FALSE, TRUE));
}

BOOL FAR NormalJudge()
{
	return (::JudgePassword("8", FALSE, FALSE));
}

static int LoadCompanyString(int nCompany, char* pStr1, char* pStr2, char* pStr3, char* pStr4, char* pStr5)
{

	char buf[260];
	CRegister* pRegister = new CRegister("sys\\Company.Sys", TRUE);

	char strSegment[128];

	::sprintf(strSegment, "Company-1");

	if (nCompany == 0)
	{
		::sprintf(strSegment, "Company-1");
	}
	else if (nCompany == 1)
	{
		::sprintf(strSegment, "Company-1");
	}
	else
	{
		::sprintf(strSegment, "Company-%d", nCompany);
	}

	::_fstrcpy(pStr1, pRegister->GetProfileString(strSegment, "str1", ""));
	::_fstrcpy(pStr2, pRegister->GetProfileString(strSegment, "str2", ""));
	::_fstrcpy(pStr3, pRegister->GetProfileString(strSegment, "str3", ""));
	::_fstrcpy(pStr4, pRegister->GetProfileString(strSegment, "str4", ""));
	::_fstrcpy(pStr5, pRegister->GetProfileString(strSegment, "str5", ""));


	DELETE(pRegister);

	int nLength1 = ::_fstrlen(pStr1);
	int nLength2 = ::_fstrlen(pStr2);
	int nLength3 = ::_fstrlen(pStr3);
	int nLength4 = ::_fstrlen(pStr4);
	int nLength5 = ::_fstrlen(pStr5);

	int nMax = nLength1;
	if (nMax < nLength2) nMax = nLength2;
	if (nMax < nLength3) nMax = nLength3;
	if (nMax < nLength4) nMax = nLength4;
	if (nMax < nLength5) nMax = nLength5;

	return (nMax);
}


TESTMAP_STRUCT mAfxTestMapStruct;

BOOL LoadTestMap()
{
	char* pByte = "\nTestMap.Map Err!";

	FILE *pFile = NULL;
	if(!(pFile = ::fopen("TestMap.Map","rb")))
	{
		printf(pByte);
		return(FALSE);
	}
	long lgLength = ::filelength(fileno(pFile));

	if (lgLength <= 1L*sizeof(TESTMAP_STRUCT))
	{
		::fclose(pFile);
		::printf(pByte);
		return(FALSE);
	}

	::fread(&mAfxTestMapStruct, sizeof(TESTMAP_STRUCT), 1,pFile);
	if (lgLength != mAfxTestMapStruct.dwTotalLength)
	{
		::fclose(pFile);
		::printf(pByte);
		return(FALSE);
	}


	if (lgLength - mAfxTestMapStruct.dwMapOffset != 4L*sizeof(DWORD)*mAfxTestMapStruct.wItemCount)
	{
		::fclose(pFile);
		::printf(pByte);
		return(FALSE);
	}

	if (*(((BYTE *)&mAfxTestMapStruct.dwFlags) + 0) != 'M' ||
		*(((BYTE *)&mAfxTestMapStruct.dwFlags) + 1) != 'A' ||
		*(((BYTE *)&mAfxTestMapStruct.dwFlags) + 2) != 'P' ||
		*(((BYTE *)&mAfxTestMapStruct.dwFlags) + 3) != '\0')
	{
		::fclose(pFile);
		::printf(pByte);
		return(FALSE);
	}

	::fclose(pFile);
	return(TRUE);
}

void FAR KeyF5_Welcome(CObject* pObj)
{
	//CWindow* pWindow = (CWindow *)pObj->GetSafeTopParent();

	if (pObj != NULL)
	{
		if (!::ManufaJudge())
		{
			return;
		}
	}

    int nResult  = ::AfxMessageBox("需要拷机吗？", MB_OKNOCANCEL);
    if (nResult == IDCANCEL || nResult == IDCLOSE)
    {
        return;
    }

    CRegister* pRegister =  new CRegister("Config.sys");

    if (nResult == IDOK)
    {
        pRegister->WriteProfileString("Debug", "DebugState", "On");
    }
    else if (nResult == IDNO)
    {
        pRegister->WriteProfileString("Debug", "DebugState", "Off");
    }
    DELETE(pRegister);

}


void FAR KeyF6_Welcome(CObject* pObj)
{
	char buf[260];
        char buf1[250], buf2[256], buf3[256], buf4[256];

	CWindow* pWindow = (CWindow *)pObj->GetSafeTopParent();

	if (!::ManufaJudge())
	{
		return;
	}


	CRegister* pRegister = new CRegister("sys\\adjust.sys", TRUE);

	_fstrcpy(buf, pRegister->GetProfileString("Sample", "SampleCard", "0,3000"));
	int  nCardAD    = (int)(WORD)::atol(pRegister->GetString(0, ',', buf));
	WORD wDelayTime = (WORD)::atol(pRegister->GetString(1, ',', buf));


	_fstrcpy(buf, pRegister->GetProfileString("Hardware", "ArmatureBei", "11.6f,330.0f"));
	float  fBei1    = ::atof(pRegister->GetString(0, ',', buf));
	float  fBei2    = ::atof(pRegister->GetString(1, ',', buf));


	DELETE(pRegister);


	::sprintf(buf1, "%d", nCardAD);
        ::sprintf(buf2, "%u", wDelayTime);
        ::sprintf(buf3, "%.3f", fBei1);
        ::sprintf(buf4, "%.3f", fBei2);


/*
A200.cx转子机老版本:CAD1----------(+0.001f, 0.000f), (4.718f, 482.0f)， 放大11倍
                    CAD8----------(-0.009f, 0.000f), (4.889f, 14.59f)， 放大330=11X33倍
S400.cx定子机老版本:CAD1----------(+0.001f, 0.000f), (4.815f, 2426.0f)，放大2倍
		    CAD8----------(+0.001f, 0.000f), (4.675f, 23.40f)， 放大200=2X100倍
*/


/*
A200.cx转子机新版本:CAD1----------(-0.001f, 0.000f), (4.718f, 79.15f)， 放大50倍
                    CAD8----------(-0.001f, 0.000f), (4.889f, 20.27f)， 放大200=50X4倍
S400.cx定子机新版本:CAD1----------(-0.007f, 0.000f), (4.902f, 2482.0f)，放大2倍
                    CAD8----------(-0.026f, 0.000f), (4.903f, 48.57f)， 放大100=2X50倍
*/


	if (!::AfxInputDialog4("高级设置",
           "请输入AD卡的类型[0-8]", buf1, buf1, 3, FALSE,
           "AD卡软件采样延时[1000-30000]", buf2, buf2, 6, FALSE,
           "电阻低放大倍数", buf3, buf3, 10, FALSE,
           "电阻高放大倍数", buf4, buf4, 10, FALSE))
	{
		return;
	}

	nCardAD = ::atoi(buf1);
        wDelayTime = (WORD)(DWORD)atol(buf2);
        fBei1   = ::atof(buf3);
        fBei2   = ::atof(buf4);

	pRegister = new CRegister("sys\\adjust.sys", FALSE);

	::sprintf(buf, "%d,%u", nCardAD, wDelayTime);
	pRegister->WriteProfileString("Sample", "SampleCard", buf);

	::sprintf(buf, "%.3f,%.3f", fBei1, fBei2);
	pRegister->WriteProfileString("Hardware", "ArmatureBei", buf);

	DELETE(pRegister);


	return;

}


void FAR KeyF7_Welcome(CObject* pObj)
{
	char buf[260];
	CWindow* pWindow = (CWindow *)pObj->GetSafeTopParent();

	if (!::ManufaJudge())
	{
		return;
	}


	CRegister* pRegister = new CRegister("config.sys", TRUE);
	
	int nXmsStyle = pRegister->GetProfileInt("Boot", "XmsStyle", 0);

	DELETE(pRegister);


	::sprintf(buf, "%d", nXmsStyle);

	if (!::AfxInputDialog("转变", "请输入Xms内存类型", buf, buf, 5, FALSE))
	{
		return;
	}

	nXmsStyle = ::atoi(buf);

	pRegister = new CRegister("config.sys", FALSE);

	pRegister->WriteProfileInt("Boot", "XmsStyle", nXmsStyle);

	DELETE(pRegister);


	return;

}

void FAR KeyF8_Welcome(CObject* pObj)
{
	char buf[260];
	CWindow* pWindow = (CWindow *)pObj->GetSafeTopParent();

	if (!::ManufaJudge())
	{
		return;
	}

	::sprintf(buf, "%d", nAfxCompanyVersion);

	if (::AfxInputDialog("Company", "Inpuse Company Name", buf, buf, 5, FALSE))
	{
		return;
	}

	int nNewCompanyVersion = ::atoi(buf);

	CRegister* pRegister = new CRegister("config.sys", FALSE);
	pRegister->WriteProfileInt("Boot", "Company", nNewCompanyVersion);

	if (nNewCompanyVersion == 0) //Firstsail
	{
		pRegister->WriteProfileString("Boot", "Authorization", "深圳市先航电子技术有限公司");
	}
	else if (nNewCompanyVersion == 1) //firstsail
	{
		pRegister->WriteProfileString("Boot", "Authorization", "深圳市先航电子技术有限公司");
	}
	else if (nNewCompanyVersion == 2) //Fusing
	{
		pRegister->WriteProfileString("Boot", "Authorization", "炘冠科技(深圳)有限公司");
	}
	else if (nNewCompanyVersion == 3) //Xmjco
	{
		pRegister->WriteProfileString("Boot", "Authorization", "深圳市金岷江机电设备有限公司");
	}
	else if (nNewCompanyVersion == 4) //Juli
	{
		pRegister->WriteProfileString("Boot", "Authorization", "浙江巨力电机成套设备有限公司");
	}
	else if (nNewCompanyVersion == 5) //Julong
	{
		pRegister->WriteProfileString("Boot", "Authorization", "浙江巨龙自动化设备有限公司");
	}
	else if (nNewCompanyVersion == 7) //Firstep
	{
		pRegister->WriteProfileString("Boot", "Authorization", "广州嘉能自动化设备有限公司");
	}

	DELETE(pRegister);

	return;
}


void FAR OnTime_Welcome(CObject* pObj)
{
	char buf[256];
	static long gLoop = 0;

	CWindow* pWindow = (CWindow *)pObj;


	DWORD dwCount = (DWORD)(0.5f + __MicroSeconds_Welcomm / (1000.0f / 18.2f));


	if ((++gLoop)  >= dwCount || ::IsMouseDown(MOUSE_LEFT))
	{
		gLoop = 0;

	::CloseWindow(NULL);
		::SetKeyboard(VK_ALT_F);
	}



	char *pStr6 = "DOS-技术";


	if ((gLoop % 5) == 0)
	{

		int nTextBei = 2;

		static int nCounter = 0;
		static int nCounter2 = 0;

		int nLeft  = ::GetMaxX() - nTextBei * 8 * _fstrlen(pStr6);
		int nTop   = 5;

		::ChPrintf(nLeft, nTop, WHITE, BLACK, nTextBei, 0, pStr6);

		int nColor = RED;

		if ((nCounter2 % 3) == 0) nColor = RED;
		if ((nCounter2 % 3)== 1) nColor = GREEN;
		if ((nCounter2 % 3)== 2) nColor = BLUE;

		if (nAfxCompanyVersion == COMPANY_NAME_EX_FUSING ||
		    nAfxCompanyVersion == COMPANY_NAME_EX_JULI ||
		    nAfxCompanyVersion == COMPANY_NAME_EX_EASTJL)
		{
			buf[0] = *(pStr6 + 2 * nCounter + 0);
			buf[1] = *(pStr6 + 2 * nCounter + 1);
			buf[2] = '\0';

			::ChPrintf(nLeft + nTextBei * 2 * nCounter * 8,
				nTop, nColor, BLACK, nTextBei, 0, buf);

			nCounter %= 4;

		}
		else if (nAfxCompanyVersion == COMPANY_NAME_EX_XMJCO)
		{
			if (nCounter == 0)
			{
				buf[0] = *(pStr6 + 0);
				buf[1] = *(pStr6 + 1);
				buf[2] = '\0';
			}
			else if (nCounter == 1)
			{
				buf[0] = *(pStr6 + 3);
				buf[1] = *(pStr6 + 4);
				buf[2] = '\0';
			}
			else
			{
				buf[0] = *(pStr6 + 6);
				buf[1] = *(pStr6 + 7);
				buf[2] = '\0';
			}

			if (nCounter == 0)
			{
				::ChPrintf(nLeft + nTextBei * 0 * 8,
					nTop, nColor, BLACK, nTextBei, 0, buf);
			}
			else if (nCounter == 1)
			{
				::ChPrintf(nLeft + nTextBei * 3 * 8,
					nTop, nColor, BLACK, nTextBei, 0, buf);

			}
			else
			{
				::ChPrintf(nLeft + nTextBei * 6 * 8,
					nTop, nColor, BLACK, nTextBei, 0, buf);

			}

			nCounter %= 3;

		}
		else
		{
			buf[0] = *(pStr6 + 2 * nCounter + 0);
			buf[1] = *(pStr6 + 2 * nCounter + 1);
			buf[2] = '\0';

			::ChPrintf(nLeft + nTextBei * 2 * nCounter * 8,
				nTop, nColor, BLACK, nTextBei, 0, buf);

			nCounter %= 4;

		}

		nCounter++;

		if (nCounter == 0) nCounter2++;

		return;


		static int nLoc = 0;
		static int nColorCounter = 0;
		static int nTextColor = RED;

		ChPrintf(nLoc, 5, BLACK, BLACK, nTextBei, 0, pStr6);


		if (nLoc == 0)
		{
			if ((nColorCounter % 3) == 0) nTextColor = RED;
			if ((nColorCounter % 3) == 1) nTextColor = GREEN;
			if ((nColorCounter % 3) == 2) nTextColor = BLUE;

		}

		if (::GetMaxX() + 1 == 1280) {nLoc += 256 ; nLoc %= 1024;}
		if (::GetMaxX() + 1 == 1024) {nLoc += 256 ; nLoc %= 1024;}
		if (::GetMaxX() + 1 == 800)  {nLoc += 100 ; nLoc %= 800;}
		if (::GetMaxX() + 1 == 640)  {nLoc += 128 ; nLoc %= 640;}

		if (nLoc == 0)
		{
			nColorCounter++;
		}

		ChPrintf(nLoc, 5, nTextColor, BLACK, nTextBei, 0, pStr6);
	}


}

static void FAR ClickButton_Welcome(CObject* pObj)
{
	CWindow* pWindow = (CWindow *)pObj->GetParent();
	int nIndex = pObj->GetID() - (BUTTONBASE + 1 - 1);

	if (nIndex > 5) nIndex = 5;
	if (nIndex < 0) nIndex = 0;

	nAfxLanguageVersion = nIndex;

    /*
	if (nIndex == 5)
	{
		if (::AfxIsExistFile("Sail2008.Exe"))
		{

			bAfxClickOther = TRUE;
		}
	}
    */

	::ClickEnterButton(pObj);
	return;
}

void FAR AfxWelcome(DWORD dwMicroSecond)
{
	char buf[256];
	int nOldLanguage = nAfxLanguageVersion;
	BOOL bsLanguage[5] = {1, 1, 0, 0,0};
	if (1)
	{
		CRegister* pRegister = new CRegister("config.sys", TRUE);
		nAfxLanguageVersion = pRegister->GetProfileInt("Boot", "Language", 0);
		::_fstrcpy(buf, pRegister->GetProfileString("Boot", "LanguageMask", "1, 1, 1, 1, 1"));
		 bsLanguage[0] = ::atoi(pRegister->GetString(0, ',', buf));
		 bsLanguage[1] = ::atoi(pRegister->GetString(1, ',', buf));
		 bsLanguage[2] = ::atoi(pRegister->GetString(2, ',', buf));
		 bsLanguage[3] = ::atoi(pRegister->GetString(3, ',', buf));
		 bsLanguage[4] = ::atoi(pRegister->GetString(4, ',', buf));

		DELETE(pRegister);

		nOldLanguage = nAfxLanguageVersion;
	}
	__MicroSeconds_Welcomm = dwMicroSecond;


	CWindow* pWindow = new CWindow;
	pWindow->CreateWindow(0, 0, GetMaxX() + 50, GetMaxY() + 50, NULL);
	pWindow->Center();




	pWindow->SetTimeFc(OnTime_Welcome);

	pWindow->SetBackColor(BLACK);

	CButton* pButton = new CButton(pWindow);
	pButton->CreateObject(-30,-30, -5,-5,"");
	pButton->SetFc(::ClickCloseButton);





	pWindow->SetSaveScreen(FALSE);
	pWindow->ShowWindow();

	int nMouse = ::GetMouse();
	::CloseMouse();

	::DisplayJpgFile(0, 0, "bmp\\Desktop.jpg", 1);

	int nImageWidth  = 76;
	int nImageHeight = 76;
	int nBitmapLeft2 = 0;

	CAnimalCtrl* pAnimalCtrl1 = new CAnimalCtrl(pWindow);
	pAnimalCtrl1->CreateObject(GetMaxX() / 2 - nImageWidth /2 + nBitmapLeft2,
		GetMaxY() / 2 - nImageHeight/2 - 50, 40,100, NULL);

//	pAnimalCtrl->CreateObject(GetMaxX() / 2 - nImageWidth /2,
//		GetMaxY()  - nImageHeight/2 - 160, 40,100, NULL);

	pAnimalCtrl1->LoadFile("Bmp\\Earth3.gif");
	pAnimalCtrl1->SetID(ANIMALBASE + 1 - 1);
	pAnimalCtrl1->Show();


	/*
	CAnimalCtrl* pAnimalCtrl2 = new CAnimalCtrl(pWindow);
	pAnimalCtrl2->CreateObject(GetMaxX() - 150,
		GetMaxY()  - 100, 40,100, NULL);
	pAnimalCtrl2->LoadFile("Bmp\\a.gif");
	pAnimalCtrl2->SetID(ANIMALBASE + 2 - 1);
	pAnimalCtrl2->Show();
          */

	int nLeft, nTop;


	char pGlobal_Adv_Str1[260];
	char pGlobal_Adv_Str2[260];
	char pGlobal_Adv_Str3[260];
	char pGlobal_Adv_Str4[260];
	char pGlobal_Adv_Str5[260];

	*pGlobal_Adv_Str1 = 0;
	*pGlobal_Adv_Str2 = 0;
	*pGlobal_Adv_Str3 = 0;
	*pGlobal_Adv_Str4 = 0;
	*pGlobal_Adv_Str5 = 0;

	int nMaxLength = ::LoadCompanyString(nAfxCompanyVersion,
		pGlobal_Adv_Str1,
		pGlobal_Adv_Str2,
		pGlobal_Adv_Str3,
		pGlobal_Adv_Str4,
		pGlobal_Adv_Str5);

	int nBei = 2;

	nLeft = GetMaxX() / 2 -  nBei * 8 * _fstrlen(AfxString[0])/2;
	nTop  = GetMaxY() / 2 - nBei * 16 / 2;
	::ChPrintf(nLeft , nTop + nImageHeight / 2 + 20 - 50 + nBitmapLeft2 / 2,
		WHITE, BLACK, 2, 0, AfxString[0]);


	int nTextBei = 1;

	::ChPrintf(5, GetMaxY() - nTextBei * 16 * 5 - 5, WHITE, BLACK, nTextBei, 0, pGlobal_Adv_Str1);
	::ChPrintf(5, GetMaxY() - nTextBei * 16 * 4 - 5, WHITE, BLACK, nTextBei, 0, pGlobal_Adv_Str2);
	::ChPrintf(5, GetMaxY() - nTextBei * 16 * 3 - 5, WHITE, BLACK, nTextBei, 0, pGlobal_Adv_Str3);
	::ChPrintf(5, GetMaxY() - nTextBei * 16 * 2 - 5, WHITE, BLACK, nTextBei, 0, pGlobal_Adv_Str4);
	::ChPrintf(5, GetMaxY() - nTextBei * 16 * 1 - 5, WHITE, BLACK, nTextBei, 0, pGlobal_Adv_Str5);
	//------------------------------------------------------------

	::sprintf(buf, "简体中文(Chinese simplied)");
	CButton* pButton1 = new CButton(pWindow);
	pButton1->CreateObject(GetMaxX() - 240, GetMaxY() - 330 + 60 * 0, 240, 50, buf);
	pButton1->SetBackColor((nAfxLanguageVersion == 1 - 1) ? YELLOW:GREEN);
	pButton1->SetID(BUTTONBASE + 1 - 1);

	::sprintf(buf, "英语(English)");
	CButton* pButton2 = new CButton(pWindow);
	pButton2->CreateObject(GetMaxX() - 240, GetMaxY() - 330 + 60 * 1, 240, 50, buf);
	pButton2->SetBackColor((nAfxLanguageVersion == 2 - 1) ? YELLOW:GREEN);
	pButton2->SetID(BUTTONBASE + 2 - 1);

	::sprintf(buf, "中华台湾(Chinese Taiwan)");
	CButton* pButton3 = new CButton(pWindow);
	pButton3->CreateObject(GetMaxX() - 240, GetMaxY() - 330 + 60 * 2, 240, 50, buf);
	pButton3->SetBackColor((nAfxLanguageVersion == 3 - 1) ? YELLOW:GREEN);
	pButton3->SetID(BUTTONBASE + 3 - 1);


	::sprintf(buf, "GBK中文(chinese GBK)");
	CButton* pButton4 = new CButton(pWindow);
	pButton4->CreateObject(GetMaxX() - 240, GetMaxY() - 330 + 60 * 3, 240, 50, buf);
	pButton4->SetBackColor((nAfxLanguageVersion == 4 - 1) ? YELLOW:GREEN);
	pButton4->SetID(BUTTONBASE + 4 - 1);

	::sprintf(buf, "日本(Janpanese)");
	CButton* pButton5 = new CButton(pWindow);
	pButton5->CreateObject(GetMaxX() - 240, GetMaxY() - 330 + 60 * 4, 240, 50, buf);
	pButton5->SetBackColor((nAfxLanguageVersion == 5 - 1) ? YELLOW:GREEN);
	pButton5->SetID(BUTTONBASE + 5 - 1);

	::sprintf(buf, "Other");

	CButton* pButton6 = new CButton(pWindow);
	pButton6->CreateObject(GetMaxX() - 240, GetMaxY() - 330 + 60 * 5, 240, 50, buf);
	pButton6->SetBackColor((nAfxLanguageVersion == 6 - 1) ? YELLOW:GREEN);
	pButton6->SetID(BUTTONBASE + 6 - 1);


	pButton1->SetFc(::ClickButton_Welcome);
	pButton2->SetFc(::ClickButton_Welcome);
	pButton3->SetFc(::ClickButton_Welcome);
	pButton4->SetFc(::ClickButton_Welcome);
	pButton5->SetFc(::ClickButton_Welcome);
	pButton6->SetFc(::ClickButton_Welcome);

	if (!bsLanguage[0]) pButton1->SetBackColor(BROWN);
	if (!bsLanguage[1]) pButton2->SetBackColor(BROWN);
	if (!bsLanguage[2]) pButton3->SetBackColor(BROWN);
	if (!bsLanguage[3]) pButton4->SetBackColor(BROWN);
	if (!bsLanguage[4]) pButton5->SetBackColor(BROWN);

	if (!bsLanguage[0]) pButton1->SetEnable(FALSE);
	if (!bsLanguage[1]) pButton2->SetEnable(FALSE);
	if (!bsLanguage[2]) pButton3->SetEnable(FALSE);
	if (!bsLanguage[3]) pButton4->SetEnable(FALSE);
	if (!bsLanguage[4]) pButton5->SetEnable(FALSE);

	pButton1->Show();
	pButton2->Show();
	pButton3->Show();
	pButton4->Show();
	pButton5->Show();
	pButton6->Show();

	::SetMouse(nMouse);
	//-
	pWindow->AddCommandKey(VK_F5, ::KeyF5_Welcome); //拷机
	pWindow->AddCommandKey(VK_F6, ::KeyF6_Welcome); //AD卡类型
	pWindow->AddCommandKey(VK_F7, ::KeyF7_Welcome); //Xms内存类型
	pWindow->AddCommandKey(VK_F8, ::KeyF8_Welcome); //公司名字

	pWindow->PurseMessage();
	delete pWindow;


	if (nOldLanguage != nAfxLanguageVersion)
	{
		CRegister* pRegister = new CRegister("config.sys", FALSE);
		pRegister->WriteProfileInt("Boot", "Language", nAfxLanguageVersion);

		BOOL bWriteChineseCaption = TRUE;
		if (0 ==  nAfxLanguageVersion) //Chinse
		{
            bWriteChineseCaption =  TRUE;
			pRegister->WriteProfileString("Display", "Font", "Display.Fon");
		}
		else if (1 ==  nAfxLanguageVersion) //English
		{
			bWriteChineseCaption = FALSE;
			pRegister->WriteProfileString("Display", "Font", "Display.Fon");
		}
		else if (2 ==  nAfxLanguageVersion)//Chinese Taiwan
		{
            bWriteChineseCaption =  TRUE;
			pRegister->WriteProfileString("Display", "Font", "DisplayF.Fon");
		}
		else if (3 ==  nAfxLanguageVersion)//Chinese GBK
		{
            bWriteChineseCaption =  TRUE;
			pRegister->WriteProfileString("Display", "Font", "Font\\GBK_K.Fon");
		}
		else if (4 ==  nAfxLanguageVersion)//Janpanse
		{
            bWriteChineseCaption =  TRUE;
			pRegister->WriteProfileString("Display", "Font", "DisplayF.Fon");
		}
		//======================================================================================


		if (bWriteChineseCaption)
		{
			switch (mAfxTestMapStruct.wStyle)
			{
				case TESTMAP_ARMATURE_200:
				{
					pRegister->WriteProfileString("Boot", "Caption", "FS-200/CX型智能电枢测试系统");
					break;
				}
				case TESTMAP_STATOR_400:
				{
					pRegister->WriteProfileString("Boot", "Caption", "FS-400/CX型智能定子测试系统");
					break;
				}
				case TESTMAP_FS_300_CX:
				{
					pRegister->WriteProfileString("Boot", "Caption", "FS-300/CX型智能电机测试系统");
					break;
				}
				case TESTMAP_ARMATURE_210:				
				case TESTMAP_FS_750_CX2:
				case TESTMAP_FS_750:
				case TESTMAP_FS_750_CX:
				case TESTMAP_VBTIONFF_700:
				case TESTMAP_VBTIONFF_500:
				case TESTMAP_FS_900_CX:
				default:
				{
					break;
				}
			}
		}
		else
		{
			switch (mAfxTestMapStruct.wStyle)
			{
				case TESTMAP_ARMATURE_200:
				{
					pRegister->WriteProfileString("Boot", "Caption", "FS-200/CX Armauture Test System");
					break;
				}
				case TESTMAP_STATOR_400:
				{
					pRegister->WriteProfileString("Boot", "Caption", "FS-400/CX Stator Test System");
					break;
				}
				case TESTMAP_FS_300_CX:
				{
					pRegister->WriteProfileString("Boot", "Caption", "FS-300/CX Motor Test System");
					break;
				}
				case TESTMAP_ARMATURE_210:				
				case TESTMAP_FS_750_CX2:
				case TESTMAP_FS_750:
				case TESTMAP_FS_750_CX:
				case TESTMAP_VBTIONFF_700:
				case TESTMAP_VBTIONFF_500:
				case TESTMAP_FS_900_CX:
				default:
				{
					break;
				}
			}
		}


		DELETE(pRegister);
		//-------------------------------------------------------------
	}



	return;
}

#if defined(FUSING_COMPANY)
DWORD dwAfxWelcomeTime = 10lu * 1000lu;

#elif defined(XMJCO_COMPANY)
DWORD dwAfxWelcomeTime = 10lu * 1000lu;

#else
DWORD dwAfxWelcomeTime = 8lu * 1000lu;
#endif

int Welcome(int argc, char** argv)
//int main(int argc, char** argv)
{
	//if (!::InitSystem(argc, argv))
	//{
	//	::CloseSystem();
	//	::printf("\nSystem Source Not Enough!");
	//	return(0);
	//}

	::LoadTestMap();

	char buf[256];

	CRegister* pRegister = new CRegister("Config.sys", TRUE);
	_fstrcpy(buf, pRegister->GetProfileString("Debug", "DebugState", "Off"));
	BOOL bDebug = CRegister::IsProfileBoolen(buf);
	DELETE(pRegister);

	if (bDebug)
	{
		::KeyF5_Welcome(NULL);

	}


	::AfxWelcome(dwAfxWelcomeTime);


	//Close System
	//::CloseSystem();
	//::nosound();

	//::KernelDelay(100);



	::ClearKeyboard();
	//::AfxRestoreMainExe(FALSE, TRUE, NULL);


	return(1);

}
