#include <Conio.h>
#include <Bios.h>
#include <dir.h>
#include <direct.h>

#include <Symbol.h>
#include <MyFrame.h>

#include <Relay.h>
#include <Socket3.h>
#include <Socket4.h>

#include <New_Disk.h>

void far BarCodeDemo();
void far ArpDialog();
void far MenuInstance();
void far NetcardSetting();
void far DemoSliderAndProcess();
void far DemoMultiEditDialog();
void far DemoFileOpenDialog();
void far VirtualKeyboardDemo(CObject* pCurObj);
void far DialDemoDialog();
void far GraphDemoDialog();
void far LedDemoDialog();
void DemoWizard();
void far Demo_NumberKeyboard();
void far QQ_Workstation();
int Welcome(int argc, char** argv);


extern BOOL bAfxNetcard;
extern BOOL bAfxManager;
extern BOOL far bAfxGotoMonitor;
extern unsigned   _stklen=(60u*1024u);
extern CWindow*   pAfxWindow;


//该函数是用户必须实现的所有窗口默认的"附加键盘回调函数"；内核代码创建窗口时，自动默认注册该函数。
int far TransrateKey(CObject*)
{
    return(0);
}

BOOL bAfxAgain = FALSE;

BOOL GetAgain()
{
	return(bAfxAgain);
}


void  SetAgain(BOOL bAgain)
{
	bAfxAgain = bAgain;
}


void FAR DisplayAttribSetting()
{
	char buf[256];

	//if (!::SuperJudge())
	//{
	//	return;
	//}

	//Create a Dialog On the Center of Desktop
	CDialog* pDialog = new CDialog;//分配实例
	pDialog->CreateWindow(0, 0, 313, 135, "显示属性");//建立窗口
	pDialog->Center();//窗口对中

	//Create Close's Button Control
	new CCloseButton(pDialog);//分配和建立关闭按钮

	//Create Combo Control
	CComboBox* pComboBox1 = new CComboBox(pDialog);
	pComboBox1->CreateCombo(9, 103, 195, 24, NULL);
	//pComboBox1->SetID(COMBOBASE + 1 - 1);

	//Create a Button Control
	CButton* pButton1 = new CButton(pDialog);
	pButton1->CreateObject(222, 58, 75, 24, "确定(\x3\E\x3)");
	pButton1->SetShortcutKey(VK_ALT_E);
	pButton1->SetFc(ClickEnterButton);
	//pButton1->SetID(BUTTONBASE + 1 - 1);

	//Create a Button Control
	CButton* pButton2 = new CButton(pDialog);
	pButton2->CreateObject(222, 103, 75, 24, "取消(\x3\C\x3)");
	pButton2->SetShortcutKey(VK_ALT_C);
	pButton2->SetFc(ClickCancelButton);
	//pButton2->SetID(BUTTONBASE + 2 - 1);

	//Create a Label Control
	CLabel* pLabel1 = new CLabel(pDialog);
	pLabel1->CreateObject(7, 77, 85, 12, "请选择显示属性");
	//pLabel1->SetID(LABELBASE + 1 - 1);


	//Create a ICON Control
	CLabel* pLabel2 = new CLabel(pDialog);
	pLabel2->CreateObject(24, 37, 31, 31, NULL);
	pLabel2->SetBitmapFlags(TRUE);
	pLabel2->SetBackColorDisplay(TRUE);
	pLabel2->SetBitmapFile("Bmp\\Display.ico");
	//pLabel2->SetID(LABELBASE + 2 - 1);

	//Create Check Control
	CRadio* pCheck1 = new CRadio(pDialog);
	pCheck1->CreateObject(141, 77, 57, 24, "单色");
	pCheck1->SetBox(TRUE);
	//pCheck1->SetID(CHECKBASE + 1 - 1);

    pComboBox1->SetCount(10);
	pComboBox1->SetSel(0,"VGA_640*480*16色");

	pComboBox1->SetSel(1, "VESA_640*400*256色");
	pComboBox1->SetSel(2, "VESA_640*480*256色");
	pComboBox1->SetSel(3, "VESA_800*600*256色");
	pComboBox1->SetSel(4, "VESA_1024*768*256色");
	pComboBox1->SetSel(5, "VESA_1280*1024*256色");

	pComboBox1->SetSel(6, "VESA_640*480*16位色");
	pComboBox1->SetSel(7, "VESA_800*600*16位色");
	pComboBox1->SetSel(8, "VESA_1024*768*16位色");
	pComboBox1->SetSel(9, "VESA_1280*1024*16位色");
	
	if( GetDisplayDevice() == VESA)
	{
		if (GetDisplayMode() == VESA640_400_256 ||
			GetDisplayMode() == VESA640_400_8B)
		{
			pComboBox1->SetIndex(1);
		}
		else if (GetDisplayMode() == VESA640_480_256 ||
			GetDisplayMode() == VESA640_480_8B)
		{
			pComboBox1->SetIndex(2);
		}
		else if (GetDisplayMode() == VESA800_600_256 ||
			GetDisplayMode() == VESA800_600_8B)
		{
			pComboBox1->SetIndex(3);
		}
		else if (GetDisplayMode() == VESA1024_768_256 ||
			GetDisplayMode() == VESA1024_768_8B)
		{
			pComboBox1->SetIndex(4);
		}
		else if (GetDisplayMode() == VESA1280_1024_256 ||
			GetDisplayMode() == VESA1280_1024_8B)
		{
			pComboBox1->SetIndex(5);
		}
		else if (GetDisplayMode() == VESA640_480_16B)
		{
			pComboBox1->SetIndex(6);
		}
		else if (GetDisplayMode() == VESA800_600_16B)
		{
			pComboBox1->SetIndex(7);
		}
		else if (GetDisplayMode() == VESA1024_768_16B)
		{
			pComboBox1->SetIndex(8);
		}
		else if (GetDisplayMode() == VESA1280_1024_16B)
		{
			pComboBox1->SetIndex(9);
		}
		else
		{
			pComboBox1->SetIndex(0);
		}
	}
	else
	{
		pComboBox1->SetIndex(0);
	}

	pCheck1->SetRadio(AfxGetMonoAttrib());

	//Show Window
	pDialog->ShowWindow();//显示窗口


	if (pDialog->DoModal() == IDOK)
	{
    	BOOL bMono = pCheck1->GetRadio();
		int nIndex = pComboBox1->GetIndex();
		delete pDialog;


		CRegister* pRegister = new CRegister("Config.Sys");
		char* pStrSegment = "Display";
		if (nIndex == 0)
		{
			pRegister->WriteProfileInt(pStrSegment, "Device",VGA);
			pRegister->WriteProfileInt(pStrSegment, "Mode",VGAHI);
		}
		else
		{

			int nMode = 0;

			if (nIndex == 1) nMode = VESA640_400_8B;
			if (nIndex == 2) nMode = VESA640_480_8B;
			if (nIndex == 3) nMode = VESA800_600_8B;
			if (nIndex == 4) nMode = VESA1024_768_8B;
			if (nIndex == 5) nMode = VESA1280_1024_8B;
			if (nIndex == 6) nMode = VESA640_480_16B;
			if (nIndex == 7) nMode = VESA800_600_16B;
			if (nIndex == 8) nMode = VESA1024_768_16B;
			if (nIndex == 9) nMode = VESA1280_1024_8B;

			pRegister->WriteProfileInt(pStrSegment, "Device",VESA);
			sprintf(buf, "%X", nMode);
			pRegister->WriteProfileString(pStrSegment, "Mode", buf);

		}
        pRegister->WriteProfileString(pStrSegment, "Mono",
			((bMono)?"True":"False"));


		delete pRegister;

		::CloseWindow(pDialog) ; ::ClearKeyboard();
		::SetAgain(TRUE); ::AddKeyboardString("Sail2000 觞\xd");
	}
	else
	{
		delete pDialog;
	}
	return;
}

void far ClickNetcardSetting_Desktop(CObject* pObj)
{
	::NetcardSetting();

	::CloseWindow(pObj) ; ::ClearKeyboard();
	::SetAgain(TRUE); ::AddKeyboardString("Sail2000 觞\xd");

}




//"开始菜单"的下一级菜单"附件菜单"的功能函数
void    far ClickSystemMenu_FrameWindow(int nUserLeft,int nUserTop,CBar* pBar)
{
    //死循环直到鼠标左键不再按下
	while(::IsMouseDown(MOUSE_LEFT)){};
   
    //分配"弹出菜单"实例
	CBar *pBar1 = new CBar(NULL);
     //建立"弹出菜单"
	pBar1->CreateObject(nUserLeft,nUserTop,120,60,NULL);

     //往"弹出菜单"中加入"菜单项"
	pBar1->AddItem("用户登录",NULL);//(void (*)(CObject*))::UserRegister);
	pBar1->AddItem("修改权限",NULL);//(void (*)(CObject*))::ModifyPriviledge);
    pBar1->AddSeparator();

//	pBar1->AddItem("网络属性",(void (*)(CObject*))::CommSetting);
	pBar1->AddItem("显示属性" ,(void (*)(CObject*))::DisplayAttribSetting);
    pBar1->AddSeparator();
	pBar1->AddItem("驱动程序",(void (*)(CObject*))::AfxDeviceDialog);
	pBar1->AddItem("任务列表",(void (*)(CObject*))::AfxTaskDialog);
    pBar1->AddItem("对话框脚本",(void (*)(CObject*))::AfxLoadDialog);
    pBar1->AddSeparator();

	pBar1->AddItem("关于系统",(void (*)(CObject*))::AboutDialog, NULL);

    //重新修改菜单的位置
	int nLength = pBar1->GetScreenHeight();
	pBar1->SetLocation(pBar1->m_ScreenRect.left,
		pBar1->m_ScreenRect.top-nLength+1,
		pBar1->m_ScreenRect.right,
		pBar1->m_ScreenRect.top);

     //往其上一级菜单注册自己
	pBar->SetItemBar( pBar->GetIndex() , pBar1);
     //将"弹出菜单"的"父窗口"强置成"主窗口"
	pBar1->SetParent(pAfxWindow);

     //显示该"弹出菜单"
	pBar1->Show();
    //返回
	return;
}

// "开始菜单"功能
void    far ClickMenuButton_FrameWindow(CObject* pCurObj)
{
    //死循环，直至鼠标左键不再按下
	while(::IsMouseDown(MOUSE_LEFT)){};
     
	int nKey=VK_ESC;
	void far (*pFc)(CObject*)=NULL;
    //分配一个弹出菜单
	CBar *pBar1 = new CBar(NULL);
    //建立弹出菜单
	pBar1->CreateObject( 0 ,GetMaxY() + 1-25,120,60,NULL);

    //往弹出菜单中加入菜单条
    //   其中BAR_ATTRIB_NORMAL 表示不再有下一级弹出菜单
     //       BAR_ATTRIB_DIR     表示还有一级弹出菜单
	pBar1->AddItem("附  件",(void (*)(CObject*))ClickSystemMenu_FrameWindow,NULL,BAR_ATTRIB_DIR);
	pBar1->AddItem("查  找...",NULL,NULL,BAR_ATTRIB_NORMAL);
    pBar1->AddSeparator();
	pBar1->AddItem("运  行...",NULL,NULL,BAR_ATTRIB_NORMAL);
	pBar1->AddItem("退  出...",(void (*)(CObject*))CloseSystemDialog,NULL,BAR_ATTRIB_NORMAL);
    
    //修正弹出菜单的位置
	int nLength = pBar1->GetScreenHeight();
	pBar1->SetLocation(pBar1->m_ScreenRect.left,
		pBar1->m_ScreenRect.top-nLength+1,
		pBar1->m_ScreenRect.right,
		pBar1->m_ScreenRect.top);

     //将"弹出菜单"的"父窗口"与"主窗口"关联；这样，进入"弹出菜单"消息循环后仍然能执行"主窗口"的"定时器"
	pBar1->SetParent(pAfxWindow);
    //显示"弹出菜单"
	pBar1->Show();
    //循环，直至结束
	do
	{
		nKey = pBar1->Swapping();
	}while(nKey != VK_ENTER && nKey!=VK_ESC &&
		nKey!=VK_MOUSE_SCREEN_OUT && nKey!=VK_ALT_F4);

     //获得需执行的函数
	pFc = pBar1->GetFc();
     //"弹出菜单"不再需要，将其从内存中删除。
	DELETE(pBar1);
     //若注册的回调函数合法且需要执行，则运行它
	if( nKey == VK_ENTER && pFc != NULL)
	{
		pFc(pCurObj);
	}
    //返回
	return;
}

void far ChangeSlider(CSliderCtrl* pSliderCtrl)
{
	long dwMin ,dwMax, dwPos;
	pSliderCtrl->GetRange(&dwMin, &dwMax);
	dwPos = pSliderCtrl->GetPos();
}

//主窗口的定时回调函数
void  far OnTime_MainFrame(CObject* pCurObj)
{
   //显示日期和时间
//	::DisplaySystemDateAndTime(pCurObj);
}


//主窗口的窗口显示回调函数
void  far Draw_MainFrame(CObject *pObject)
{
	CWindow* pWindow = (CWindow *)pObject;


	char buf[256];
	int nLengthEx = 22;
	int nWidthEx = 0;

	strcpy(buf,"B69.5f,15.0f,12.5f,End");
	if( GetMaxX() + 1 == 800)
	{
		strcpy(buf,"B75.5f,12.0f,10.0f,End");
		nWidthEx = 1;
	}
	else if( GetMaxX() + 1 == 1024)
	{
		strcpy(buf,"B81.2f,9.4f,7.6f,End");
		nWidthEx = 1;
	}
	else if( GetMaxX() + 1 == 1280)
	{
		strcpy(buf,"B81.2f,9.4f,7.6f,End");

	}
	::ShowState(0,GetMaxY() + 1 - 24,GetMaxX() + 1 + 2,24,LIGHTGRAY,4,buf,TRUE);

	::sprintf(buf,"%s",::AfxGetSystemString(0));
	::ChPrintf(90 + 3 + ((16+6) * 4) + 3,22+(GetMaxY()+1-65)+nLengthEx,BLACK,LIGHTGRAY,1,0,buf);//"需帮助,请按Ctrl+H ；激活菜单ALT＋F");

	::DisplayIcon(pWindow->m_ScreenRect.right -16 - 3 - 6 + nWidthEx,
		pWindow->m_ScreenRect.bottom - (16 + 3 + 1 + 8),
		"Bmp\\Books14.Ico",
		1, TRUE, FALSE);

}
//桌面用户功能函数
void far DesktopFun1(CObject* pCurObj) {AfxMessageBox("调试","你单击了DesktopFun1",MB_OK) ;}
void far DesktopFun2(CObject* pCurObj) {AfxMessageBox("调试","你单击了DesktopFun2",MB_OK) ;}
void far DesktopFun3(CObject* pCurObj) {AfxMessageBox("调试","你单击了DesktopFun3",MB_OK) ;}
void far DesktopFun4(CObject* pCurObj) {AfxMessageBox("调试","你单击了DesktopFun4",MB_OK) ;}
void far DesktopFun5(CObject* pCurObj) {AfxMessageBox("调试","你单击了DesktopFun5",MB_OK) ;}
void far DesktopFun6(CObject* pCurObj) {AfxMessageBox("调试","你单击了DesktopFun6",MB_OK) ;}
//工具条用户功能函数
void far ToolsFun1(CObject* pCurObj) {AfxMessageBox("调试","你单击了ToolsFun1",MB_OK) ;}
void far ToolsFun2(CObject* pCurObj) {AfxMessageBox("调试","你单击了ToolsFun2",MB_OK) ;}
void far ToolsFun3(CObject* pCurObj) {AfxMessageBox("调试","你单击了ToolsFun3",MB_OK) ;}


BOOL	far InitFrameWindow()
{
    //建立窗口实例
	pAfxWindow = new CWindow;
    //建立窗口
	pAfxWindow->CreateWindow(0-3,0-30,GetMaxX() + 1 + 10,GetMaxY() + 1 + 40,::AfxGetSystemString(0));
    //设置OnDraw回调函数
	pAfxWindow->SetDrawFc(Draw_MainFrame);
    //设置窗口背景色
	pAfxWindow->SetBackColor(CYAN);
    //设置无须保留窗口桌面（因它是永远最底的窗口）
	pAfxWindow->SetSaveScreen(FALSE);
    //将窗口置成不可显示
	pAfxWindow->SetVisible(FALSE);
    //设置帮助回调函数
	pAfxWindow->SetHelpFc(NULL);
    //设置定时器回调函数为"OnTime_MainFrame"函数
	pAfxWindow->SetTimeFc(OnTime_MainFrame);
    //设置窗口显示回调函数为"Draw_MainFrame"函数
    pAfxWindow->SetDrawFc(Draw_MainFrame);
    //设置附加键盘回调函数
	pAfxWindow->SetKeyboardFc(NULL);

    //分配一个关闭按钮
	CCloseButton *pCloseButton = new CCloseButton(pAfxWindow);
    //"关闭按钮"与" CloseSystemDialog"函数关联。
	pCloseButton->SetFc((void (*)(CObject*))CloseSystemDialog);
    
    //建立一个桌面类
	CDesktop *pDesktop = new CDesktop(pAfxWindow);
    //桌面的尺寸
	pDesktop->CreateObject(0,19 + 5, 460, 450,NULL);
    //桌面上的"某图标"没有被"选中"时，文字显示的颜色
	pDesktop->SetForeColor(BLACK);//LIGHTBLUE);
    //桌面上的"某图标"被"选中"时，文字显示的颜色
	pDesktop->SetLightColor(BLUE);//LIGHTBLUE);
    //往桌面加入一个图标，图标文件是"Bmp\BookS01.Ico"，文字是"我的电脑"，单击时调用函数DesktopFun1
    pDesktop->AddLink("Bmp\\BookS01.Ico","我的电脑",DesktopFun1);
    //往桌面加入一个图标，图标文件是"Bmp\BookS02.Ico"，文字是"回收站"，单击时调用函数DesktopFun2
    pDesktop->AddLink("Bmp\\BookS02.Ico","回收站",DesktopFun2);
    //往桌面加入一个图标，图标文件是"Bmp\Net.Ico"，文字是"网上领居"，单击时调用函数DesktopFun3
    pDesktop->AddLink("Bmp\\Net.Ico","网上邻居",DesktopFun3);
    //往桌面加入一个图标，图标文件是"Bmp\BookS03.Ico"，文字是"四大刚"，单击时调用函数DesktopFun4
    pDesktop->AddLink("Bmp\\BookS03.Ico","四大金刚",DesktopFun4);
    //往桌面加入一个图标，图标文件是"Bmp\BookS04.Ico"，文字是"东方快车"，单击时调用函数DesktopFun5
    pDesktop->AddLink("Bmp\\BookS04.Ico","东方快车",DesktopFun5);
    //往桌面加入一个图标，图标文件是"Bmp\BookS05.Ico"，文字是"金山词霸"，单击时调用函数DesktopFun6
    pDesktop->AddLink("Bmp\\BookS05.Ico","金山词霸",DesktopFun6);
	pDesktop->AddLink("Bmp\\BookS06.Ico","网络设置",(void far (*)(CObject*))ClickNetcardSetting_Desktop);

	pDesktop->AddLink("Bmp\\BookS07.Ico","向导属性演示",(void far (*)(CObject*))DemoWizard);
	pDesktop->AddLink("Bmp\\BookS07.Ico","滑块进度条演示",(void far (*)(CObject*))DemoSliderAndProcess);
	pDesktop->AddLink("Bmp\\BookS08.Ico","多行编缉框演示",(void far (*)(CObject*))DemoMultiEditDialog);
    pDesktop->AddLink("Bmp\\BookS09.Ico","文件打开框演示",(void far (*)(CObject*))DemoFileOpenDialog);
    pDesktop->AddLink("Bmp\\BookS10.Ico","窗口菜单演示",(void far (*)(CObject*))MenuInstance);
    pDesktop->AddLink("Bmp\\BookS11.Ico","触摸屏输入演示",(void far (*)(CObject*))VirtualKeyboardDemo);
    pDesktop->AddLink("Bmp\\BookS12.Ico","表盘制作演示",(void far (*)(CObject*))DialDemoDialog);
    pDesktop->AddLink("Bmp\\BookS01.Ico","示波器演示",(void far (*)(CObject*))GraphDemoDialog);
	pDesktop->AddLink("Bmp\\BookS02.Ico","Arp高速缓冲表",(void far (*)(CObject*))ArpDialog);
	pDesktop->AddLink("Bmp\\BookS03.Ico","QQ聊天室",(void far (*)(CObject*))QQ_Workstation);

	pDesktop->AddLink("Bmp\\BookS04.Ico","条码演示",(void far (*)(CObject*))BarCodeDemo);
	pDesktop->AddLink("Bmp\\BookS05.Ico","LED演示",(void far (*)(CObject*))LedDemoDialog);
	pDesktop->AddLink("Bmp\\BookS06.Ico","数字键盘演示",(void far (*)(CObject*))Demo_NumberKeyboard);


    //分配"开始"菜单的普通按钮的一个实例
	CButton *pButton1 = new CButton(pAfxWindow);
    //建立"开始"按钮
	pButton1->CreateObject(0,30+(GetMaxY() + 1 -27),90,16+7,"※开始※");
    //设置"按钮"与"ClickMenuButton_FrameWindow"函数关联
	pButton1->SetFc(ClickMenuButton_FrameWindow);
    //设置按钮的快捷键
	pButton1->SetShortcutKey(VK_ALT_F);
    //设置按钮的"ID号"是"2001"
	pButton1->SetID(2001);

    //分配工具条实例
	CToolsBar *pToolsBar = new CToolsBar(pAfxWindow);
    //建立工具条
	pToolsBar->CreateObject(3 + 90  , 30 + (GetMaxY() + 1-27), (16 + 6)*3 , 16 + 8,NULL);
    //工具条的背景色不需要显示，因为在"显示窗口回调函数"中有"状态条"在同一位置上显示了。
	pToolsBar->SetBackColorDisplay(FALSE);
    //往工具条上增加一个按钮，图标文件是"BookS01.Ico"，单击按钮时调用ToolsFun1
	pToolsBar->AddButton("Bmp\\BookS01.Ico",(void (*)(CObject*, WORD))ToolsFun1);
    //往工具条上增加一个按钮，图标文件是"BookS02.Ico"，单击按钮时调用ToolsFun2
	pToolsBar->AddButton("Bmp\\BookS02.Ico",(void (*)(CObject*, WORD))ToolsFun2);
    //往工具条上增加一个按钮，图标文件是"BookS03.Ico"，单击按钮时调用ToolsFun3
	pToolsBar->AddButton("Bmp\\BookS03.Ico",(void (*)(CObject*, WORD))ToolsFun3);



	CAnimalCtrl* pAnimalCtrl = new CAnimalCtrl(pAfxWindow);
	pAnimalCtrl->CreateObject(GetMaxX() - 85, 35,40,100, NULL);
	pAnimalCtrl->LoadFile("Bmp\\Earth3.gif");
//	pAnimalCtrl->CreateObject(GetMaxX() - 150, 35,40,100, NULL);

//	pAnimalCtrl->LoadFile("Bmp\\Dog.gif");

	pAnimalCtrl->SetID(ANIMALBASE + 1 - 1);

	return(TRUE);
}



BOOL bAfxExitThread = FALSE;
int TaskFun1(DWORD dwParam)
{
	while (!bAfxExitThread)
    {
    	//asm sti
    	INTERRUPT_CLI
/*
        ::SetColor(WHITE);
        ::SetFillStyle(1, dwParam);
        int nX = ::random(GetMaxX());
        int nY = ::random(GetMaxY());

        if (nX >100 && nX < 500 && nY > 100 && nY < 300)
        {
        	::FillEllipse(nX, nY, 25, 25);
        }
*/
		//int nDelay = ::random(1000);
        INTERRUPT_STI
        ::KernelDelay(20);

        for (long i = 0; i < 30000L; i++)
        {
    	    double dbA = 3.5;
	        double dbB = 7.3 + dbA;
    	    double dbC = 3.5 + dbA + 4.5 + dbB;
    	    double dbD = 3.5 + dbB + 4.5 + dbC;
    	    double dbE = 3.5 + dbC + 4.5 + dbD;
    	    double dbF = 3.5 + dbD + 4.5 + dbE;

        }
        //AfxSwapProcess();
    }
	return(0);
}
extern WAVE_PROCESS_TCB msAfxWaveProcess[MAX_PROCESS_COUNT];

//#include "abc3.cpp"

double GetR1(double dbR1, double dbR2)
{
    return(dbR1* dbR2/(dbR1 + dbR2));
}

double GetR2(double dbR1, double dbR2)
{
    return(dbR1* dbR2/(dbR1 - dbR2));
}

//#define ABC3_DEBUG
#ifdef  ABC3_DEBUG
#include "Abc3.Cpp"
#endif


void DisplayData(void* pByte, DWORD dwData)
{
    static int i = 0;
    char buf[100];
    sprintf(buf, "%04X:%04X-->%08lX",
        (WORD)SAIL_HIWORD((DWORD)pByte),
        (WORD)SAIL_LOWORD((DWORD)pByte),
		dwData);
    ChPrintf(0,(i++) * 16, WHITE,BLACK, 1, 0, buf);
}

void DisplayVideo()
{
    BYTE* pbyData;


    //Mode
	pbyData = (BYTE *)MK_FP(0x40,0x49);
    DisplayData(pbyData, *pbyData);

    //Col
    pbyData++;
    DisplayData(pbyData, *((WORD *)pbyData));

    //Len
    pbyData+=2;
    DisplayData(pbyData, *((WORD *)pbyData));

    //Start
    pbyData+=2;
    DisplayData(pbyData, *((WORD *)pbyData));

    //Page 1 ~8
    for (int p = 0; p < 8; p++)
    {
    	pbyData+=2;
	    DisplayData(pbyData, *((WORD *)pbyData));
    }

    //Cursor Style
    pbyData+=2;
	DisplayData(pbyData, *((WORD *)pbyData));

    //Visible Page
    pbyData+=2;
	DisplayData(pbyData, *((BYTE *)pbyData));

    //Crt Base
    pbyData+=1;
	DisplayData(pbyData, *((WORD *)pbyData));

    //3*8
    pbyData+=2;
	DisplayData(pbyData, *((BYTE *)pbyData));


    //3*9
    pbyData+=1;
	DisplayData(pbyData, *((BYTE *)pbyData));

	//=========================================
    //Row-1
	pbyData = (BYTE *)MK_FP(0x40,0x84);
    DisplayData(pbyData, *((BYTE *)pbyData));

    //Character Length
    pbyData+=1;
	DisplayData(pbyData, *((WORD *)pbyData));

    //Control
    pbyData+=2;
	DisplayData(pbyData, *((BYTE *)pbyData));

    //Control
    pbyData+=1;
	DisplayData(pbyData, *((BYTE *)pbyData));

    //Reserve
    pbyData+=1;
	DisplayData(pbyData, *((BYTE *)pbyData));

    //Reserve
    pbyData+=1;
	DisplayData(pbyData, *((BYTE *)pbyData));

	getch();
}





#define WINSAIL_NETCARD_USER


#ifdef WINSAIL_NETCARD_USER
BOOL RemoteContorlClient(int nSeek);
BOOL User_EthernetEntry(BOOL bSingle, BOOL bSend, BOOL bIcmp)
{
	::EthernetEntry(bSingle, bSend, bIcmp);
	::RemoteContorlClient(1);
	return(TRUE);
}
#endif

//#define ABC3_DEBUG

#ifdef ABC3_DEBUG
#include "abc3.cpp"
#endif



//main函数
int main(int argc,char **argv)
{
	asm mov eax, 0

	#ifdef   ABC3_DEBUG
	//return(main3(argc, argv));
	#endif

#ifdef WINSAIL_NETCARD_USER
	::AfxRegisterNetcardEntry(::GlobalInitSocket,
		::GlobalCloseSocket, ::EthernetEntry);
#endif

   ::AfxRegisterIme(::GlobalImeManager);


    //为函数的"重入"作准备
	BOOL bEntryAgain = FALSE;
	if (argc == 2)
	{
		WORD wFormat = *((WORD *)(argv[1]));
		if (wFormat == ::GetEntryAgainFormat())
		{
			bEntryAgain = TRUE;
		}
	}
	//::SetWindowCenterEnable(FALSE);

	char* pByte = "现在可安全关闭计算机了!";
	//初始化WinSail系统内核
	if( !::InitSystem(argc,argv))
	{
		::CloseSystem();
		::printf("\nSystem Source Not Enough!");
		return(0);
	}



#ifdef WINSAIL_NETCARD_USER
	::AfxRegisterNetcardEntry(::GlobalInitSocket,
		::GlobalCloseSocket, ::User_EthernetEntry);
	::RemoteContorlClient(0);
#endif


	::Welcome(argc, argv);

	::SetActivePage(0);
	::SetVisualPage(0);

	::AfxClearScreen(CYAN);

	//::Abcd();
	::SetFillStyle(1, DARKGRAY);
	::Bar(0,  GetMaxY()  - 16 + 1, GetMaxX(),GetMaxY());

	ChPrintf(40, GetMaxY()- 16 * 1 + 1, WHITE, DARKGRAY, 1, 1,
			"*********温馨提示*********      "
			"用户名--- super    密  码--- ( 空 )");


	//DisplayVideo();

	  //如果是函数"重入"或直接进入"监控界面"，则读入以前登陆的"用户名"
	if (bEntryAgain || bAfxGotoMonitor)
	{
		CRegister *pRegister = new CRegister("Sys\\Manager.Sys");
		::_fstrcpy(AfxGetSystemUserName() , pRegister->GetProfileString("Priviledge","User","Super"));
		DELETE(pRegister);

		PASSWORD *pPassword = ::GetPassword(AfxGetSystemUserName());
		::_fstrcpy(AfxGetSystemUserName(),pPassword->strUser);
		::_fstrcpy(AfxGetSystemPassword(),pPassword->strPassword);
		::AfxSetSystemManager((BOOL)pPassword->wPriviledge);
	}
	/*
	//即不是函数"重入"，与不是直接进入"监控界面"，则需要显示"密码框"
	else if (!ShowAdvertistment(0))
	{
		//若在"Config.Sys"文件中的Switch=On，则显示"现在可安全关闭计算机了"的文字
		if (::AfxGetSystemSwitch())
		{
			DELETE(pAfxWindow);

			::CloseMouse();
			::ClearViewPort();
			::ChPrintf((GetMaxX()-3*strlen(pByte)*8)/2,GetMaxY()/2-30,RED,0,3,0,pByte);
              //进入死循环,直至按下"CTRL+F1"键
			while(!kbhit()||bioskey(0)!=0x5E00)
			{
			}
		}
		::CloseSystem();
		return(0);
	}
	*/



	//初始化窗口
	if (!::InitFrameWindow())
	{
		::CloseSystem();
		::printf("\nCan't Build Frame!");
		::exit(1);
	}
    //直接进入"监控程序","监控程序"是"某一应用系统"桌面的第一个"图标"
    if(!bEntryAgain && bAfxGotoMonitor)
    {
        asm cli
        ::ClearKeyboard();//清键盘缓冲区
        ::AddKeyboard(VK_DOWN);//仿真按下了"DOWN"方向键
        ::AddKeyboard(VK_ENTER); //仿真按下了"ENTER"回车键
        asm sti
    }


    //将窗口重新置成可显示
	pAfxWindow->SetVisible(TRUE);
	//显示主窗口
	pAfxWindow->ShowWindow(0);


	//int nsPoles[5]= {11 - 1, 1 - 1, 20 - 1, 10 - 1, 29 - 1};
	//::DisplayA210Pane(480, 300, 100, 29, &nsPoles[0], 5);

    //进入主窗口消息循环
	pAfxWindow->PurseMessage();
	//显示"现在可关闭计算机了"
	if (!::GetAgain() && ::AfxGetSystemSwitch())
	{
		if (pAfxWindow != NULL)
        {
            DELETE(pAfxWindow);
        }
		::CloseMouse();
		::ClearViewPort();
		::ChPrintf((GetMaxX()-3*strlen(pByte)*8)/2,GetMaxY()/2-30,RED,0,3,0,pByte);
		//进入死循环,直至按下"CTRL+F1"键
        while (!kbhit() || bioskey(0) != 0x5E00)
		{
		}
	}

#ifdef WINSAIL_NETCARD_USER
	::RemoteContorlClient(2);
#endif

	//关闭WinSail系统内核
	::CloseSystem();
	return(1);

}
//log2