#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();


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()
{
	if (!bAfxManager)
	{
		return;
	}

    char buf[256];

	//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(1 + 9 + 6 + 5);
	pComboBox1->SetSel(0,"VGA_640*480*16N");
	pComboBox1->SetSel(1, "VESA_800*600*16N");
	pComboBox1->SetSel(2, "VESA_640*400*256");
	pComboBox1->SetSel(3, "VESA_640*480*256");
	pComboBox1->SetSel(4, "VESA_800*600*16S");
	pComboBox1->SetSel(5, "VESA_800*600*256");
	pComboBox1->SetSel(6, "VESA_1024*768*16");
	pComboBox1->SetSel(7, "VESA_1024*768*256");
	pComboBox1->SetSel(8, "VESA_1280*1024*16");
	pComboBox1->SetSel(9, "VESA_1280*1024*256");

	pComboBox1->SetSel(10, "SVGA_320*200*16");
	pComboBox1->SetSel(11, "SVGA_640*200*16");
	pComboBox1->SetSel(12, "SVGA_640*350*16");
    pComboBox1->SetSel(13, "SVGA_640*480*16");
	pComboBox1->SetSel(14, "SVGA_800*600*16");
	pComboBox1->SetSel(15, "SVGA_1024*768*16");

	pComboBox1->SetSel(16, "SVGA_320*200*256");
	pComboBox1->SetSel(17, "SVGA_640*350*256");
    pComboBox1->SetSel(18, "SVGA_640*480*256");
	pComboBox1->SetSel(19, "SVGA_800*600*256");
	pComboBox1->SetSel(20, "SVGA_1024*768*256");


  	if (AfxGetBGIDevice() == VESA)
	{
		pComboBox1->SetIndex(1 + GetDisplayMode());
	}
  	else if (AfxGetBGIDevice() == SVGA16)
	{
		pComboBox1->SetIndex(10 + GetDisplayMode());
	}
  	else if (AfxGetBGIDevice()== SVGA256)
	{
		pComboBox1->SetIndex(16 + GetDisplayMode());
	}
	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";
		char* pStrDevice = "Device";
		char* pStrMode = "Mode";
		char* pStrBGI = "BGI";

        if (nIndex >= 1 && nIndex < 10) //VESA
        {
			pRegister->WriteProfileInt(pStrSegment, pStrDevice, VESA);
			pRegister->WriteProfileInt(pStrSegment, pStrMode, nIndex - 1);

			pRegister->WriteProfileString(pStrSegment, pStrBGI, "");
        }
		else if(nIndex >= 10 && nIndex < 16) //SVGA16
		{
			pRegister->WriteProfileInt(pStrSegment, pStrDevice, SVGA16);
			pRegister->WriteProfileInt(pStrSegment, pStrMode, nIndex - 10);

            ::sprintf(buf, "%d,%d,16,SVGA16", SVGA16, nIndex - 10);
			pRegister->WriteProfileString(pStrSegment, pStrBGI, buf);
		}
		else if(nIndex >= 16 && nIndex < 21) //SVGA256
		{
			pRegister->WriteProfileInt(pStrSegment, pStrDevice, SVGA16);
			pRegister->WriteProfileInt(pStrSegment, pStrMode, nIndex - 10);

            ::sprintf(buf, "%d,%d,256,SVGA256", SVGA256, nIndex - 16);
			pRegister->WriteProfileString(pStrSegment, pStrBGI, buf);
		}
        else
		{
			pRegister->WriteProfileInt(pStrSegment, "Device",VGA);
			pRegister->WriteProfileInt(pStrSegment, "Mode",VGAHI);

			pRegister->WriteProfileString(pStrSegment, pStrBGI, "");
		}


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


		delete pRegister;

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


//"开始菜单"的下一级菜单"附件菜单"的功能函数
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("用户登录",(void (*)(CObject*))::UserRegister);
	pBar1->AddItem("修改权限",(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*))NetcardSetting);

	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->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

extern long nAfxScreenWidth;
extern long nAfxScreenHeight;




float Bei(float fR)
{
    return (1.0f + (50.0f * 1000.0f) / fR);
}

float BeiEx(float fR, float fRx)
{
    return (Bei(fR) * fRx);
}

int Abc()

{
    printf("\n\n\n");
    float fVol = 2770.0f;
    float fRa  = 20.0f;

    float fR1 = 100.0f,   fScale1 = 1.0f;
    float fR2 = 1000.0f,  fScale2 = 1.0f;
    float fR3 = 10000.0f, fScale3 = 1.0f;
    float fR4 = 240.0f,   fScale4 = 131.6f / 133.9f;

    float fR = fR4, fScale = fScale4;

    float fRx = 2.938f * 1000.0f / Bei(fR) / (fVol / fRa);

    printf("\nfRx =  %8.5f", fRx);
    printf ("\nfR1 = %09.3f, Bei = %10.4f, BeiEx=%10.4f", fR1, Bei(fR1), BeiEx(fR1, fRx) * 10.0f * fScale);
    printf ("\nfR2 = %09.3f, Bei = %10.4f, BeiEx=%10.4f", fR2, Bei(fR2), BeiEx(fR2, fRx) * 10.0f * fScale);
    printf ("\nfR3 = %09.3f, Bei = %10.4f, BeiEx=%10.4f", fR3, Bei(fR3), BeiEx(fR3, fRx) * 10.0f * fScale);
    printf ("\nfR4 = %09.3f, Bei = %10.4f, BeiEx=%10.4f", fR4, Bei(fR4), BeiEx(fR4, fRx) * 10.0f * fScale);
    getch();

}

void DisplayA210Pane(int nX, int nY, int nRadius,
	int nBar, int *pnPole, int nCount)
{
	::SetColor(WHITE);
	::SetFillStyle(1, LIGHTGRAY);
	::FillEllipse(nX, nY, nRadius, nRadius);

	::SetColor(YELLOW);

	int nsColor[]  ={BLACK, WHITE, YELLOW, RED, GREEN};
	int* pnData = pnPole;
	for (int i = 0; i < nCount; i++)
	{

		 double dbAngle = 2.0 * CONST_DOUBLE_T * (*pnData)/ nBar;
		 int nY2 = nY - nRadius * ::sin(dbAngle);
		 int nX2 = nX + nRadius * ::cos(dbAngle);

		 if (i < 5)
		 {
			::SetColor (nsColor[i]);
		 }
		 else
		 {
			::SetColor(nsColor[4]);
		 }

		 ::Line(nX, nY, nX2 + 0, nY2 + 0);

		 ::Line(nX, nY - 2, nX2 + 0, nY2 - 2);
		 ::Line(nX, nY - 1, nX2 + 0, nY2 - 1);
		 ::Line(nX, nY + 1, nX2 + 0, nY2 + 1);
		 ::Line(nX, nY + 2, nX2 + 0, nY2 + 2);

		 ::Line(nX - 2, nY, nX2 - 2, nY2 + 0);
		 ::Line(nX - 1, nY, nX2 - 1, nY2 + 0);
		 ::Line(nX + 1, nY, nX2 + 1, nY2 + 0);
		 ::Line(nX + 2, nY, nX2 + 2, nY2 + 0);

		 pnData++;

	}
	::SetColor(WHITE);
	for (i = 0; i < 3; i++)
	{
		::Circle(nX, nY, nRadius + i);
	}

}

int nAfxFillColor2 = RED;
int nAfxFrameColor2 = WHITE;

void FillSeek(int nX, int nY, DWORD dwFlags)
{

	int nColor;
	int nMaxX = ::GetMaxX();
	int nMaxY = ::GetMaxY();


	if (nX < 0 || nY < 0 ||
		nX > nMaxX || nY > nMaxY ||
		::GetPixel(nX, nY) == nAfxFrameColor2)
	{
		return;
	}

	::PutPixel(nX, nY, nAfxFillColor2);

	if (LOBYTE(LOWORD(dwFlags)) != 0 &&
		nY - 1 >= 0 &&
		(nColor = ::GetPixel(nX, nY - 1)) != nAfxFrameColor2 &&
		nColor != nAfxFillColor2)
	{
		::FillSeek(nX, nY  - 1, 0xFFFF00FFlu);
	}

	if (HIBYTE(LOWORD(dwFlags)) != 0 &&
		nY + 1 <= nMaxY &&
		(nColor = ::GetPixel(nX, nY + 1)) != nAfxFrameColor2 &&
		nColor != nAfxFillColor2)

	{
		::FillSeek(nX, nY  + 1, 0xFFFFFF00lu);
	}


	if (LOBYTE(HIWORD(dwFlags)) != 0 &&
		nX - 1 >= 0 &&
		(nColor = ::GetPixel(nX - 1, nY)) != nAfxFrameColor2 &&
		nColor != nAfxFillColor2)

	{
		::FillSeek(nX - 1, nY, 0x00FFFFFFlu);
	}


	if (HIBYTE(HIWORD(dwFlags)) != 0 &&
		nX + 1 <= nMaxX &&
		(nColor = ::GetPixel(nX + 1, nY)) != nAfxFrameColor2 &&
		nColor != nAfxFillColor2)

	{
		::FillSeek(nX + 1, nY, 0xFF00FFFFlu);
	}


}

void Abcd()
{
	int nMouse = ::GetMouse();
	::CloseMouse();

	::SetColor(WHITE);
	::Circle(320, 240, 20);

	::FillSeek(320,240, 0xFFFFFFFFlu);

	::SetMouse(nMouse);

	getch();
}
int Abcd3()
{
	double dbFreq = 1000000.0 / (4.0 * 1.2 / 0.9);
	double dbL    = 0.1 / 1000000.0;

	double dbW    = 2.0 * CONST_DOUBLE_T * dbFreq;

	double dbC = 1.0 / (dbW * dbW * dbL);

	printf("\nF    = %20.6e", dbFreq);
	printf("\nL    = %20.6e", dbL);
	printf("\nC    = %20.6e", dbC);



	return(0);
}

void Demo_DisplayBmp()
{

	char bufFile[256];

	while (1)
	{
		//
		if (!::AfxOpenFileDialog(TRUE, bufFile, NULL))
		{
			break;
		}


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

		::ClearViewPort();
		::DisplayBmpFile(0, 0, bufFile);

		::SetMouse(nMouse);
	}

	return;
}

BOOL Kernel_ReadSecotrs(int nStartSector, int nDriver,
		int nHeader, int nMian, BYTE* pBuffer, int nSecotrs)
{
	BOOL bResult = FALSE;
	int nEx  = ((nMian >> 8) << 5);

	_asm
	{
		//加载数据缓冲区的段地址
		asm mov ax, word ptr pBuffer + 2
		asm mov es, ax
		//加载数据缓冲区编移地址
		asm mov bx, WORD ptr pBuffer + 0

		asm mov dh, byte ptr nHeader
		asm mov dl, byte ptr nDriver //驱动器号
		asm mov ch, byte ptr nMian //10位柱面号的低8位
		asm mov cl, byte ptr nStartSector//B0~B5为起始扇号
		asm mov ax, word ptr nEx
		asm or  cl, al //10位柱面号的B8~B9位
		asm mov ah, 02H //功能号
		asm mov al, byte ptr nSecotrs //扇区数
		asm int 13h
		asm mov byte ptr bResult, ah
	};

	return (bResult);
}

BOOL Kernel_WriteSecotrs(int nStartSector, int nDriver,
		int nHeader, int nMian, BYTE* pBuffer, int nSecotrs)
{
	return (TRUE);
}

struct SECTOR_CY
{
	BYTE byHeader;
	WORD wSector:6;
	WORD wCy:10;
};

typedef struct tagDPT
{
	BYTE  byActiveFlag; //80->Active,0->Not Active

	SECTOR_CY mStart;

	BYTE  byStyle;    //82H->Linux Native       83H->Linux Swap
					  //0BH->FAT32              04H->FAT16
					  //07H->NTFS

	SECTOR_CY mEnd;

	DWORD dwFirst;
	DWORD dwSectorNumbers;

}DPT, *LPDPT;

typedef struct tagMBR
{
	BYTE byCode[446];
	DPT  sDPT[4];
	BYTE byFlags1;//0x55
	BYTE byFlags2;//0xAA
}MBR, *LPMBR;

void Abcde()
{
	BYTE* pBuffer = new BYTE[512 * 40];
	_fmemset(pBuffer, 0, 512 * 40);

	BOOL bResult = ::Kernel_ReadSecotrs(1,
		0x80 + 0, 0, 0, pBuffer, 40);

	FILE* pFile = fopen("abc.dat", "w+b");
	fwrite(pBuffer, 1, 512 * 40, pFile);
	fclose(pFile);

	char buf[256], buf1[256];
	MBR* pMBR = (MBR *)pBuffer;


	buf[0] = '\0';
	for (int i = 0; i < 4; i++)
	{
		sprintf(buf1, "%02XH,%02XH,%02XH,%03XH,%02XH,%02XH,%02XH,%03XH,F:%08LX,T:%08lXH",
			(WORD)pMBR->sDPT[i].byActiveFlag,
			(WORD)pMBR->sDPT[i].mStart.byHeader,
			(WORD)pMBR->sDPT[i].mStart.wSector,
			(WORD)pMBR->sDPT[i].mStart.wCy,
			(WORD)pMBR->sDPT[i].byStyle,
			(WORD)pMBR->sDPT[i].mEnd.byHeader,
			(WORD)pMBR->sDPT[i].mEnd.wSector,
			(WORD)pMBR->sDPT[i].mEnd.wCy,
			(DWORD)pMBR->sDPT[i].dwFirst,
			(DWORD)pMBR->sDPT[i].dwSectorNumbers);

		_fstrcat(buf, buf1);
		_fstrcat(buf,"\n");
	}

	AfxMessageBox(buf);




	delete pBuffer;


}

//main函数
int main(int argc,char **argv)
{

	#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

	::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