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

void far ArpDialog()
{
	//Create a Dialog On the Center of Desktop
	CDialog* pDialog = new CDialog;//分配实例
	pDialog->CreateWindow(0, 0, 490, 330, "ARP 高速缓冲表");//建立窗口
	pDialog->Center();//窗口对中

	//Register Callback Function for Window
	pDialog->SetTimeFc(NULL);//注册定时器回调函数
	pDialog->SetDrawFc(NULL);//注册画图回调函数
	pDialog->SetHelpFc(NULL);//注册帮助回调函数
	pDialog->SetKeyboardFc(NULL);//注册虚拟键盘回调函数

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

	//Create a Button Control
	CButton* pButton1 = new CButton(pDialog);
	pButton1->CreateObject(25, 279, 90, 25, "修改(\x3M\x3)");
	pButton1->SetShortcutKey(VK_ALT_M);
	pButton1->SetID(BUTTONBASE + 1 - 1);

	//Create a Button Control
	CButton* pButton2 = new CButton(pDialog);
	pButton2->CreateObject(137, 279, 90, 25, "删除(\x3\D\x3)");
	pButton2->SetShortcutKey(VK_ALT_D);
	pButton2->SetID(BUTTONBASE + 2 - 1);

	//Create a Button Control
	CButton* pButton3 = new CButton(pDialog);
	pButton3->CreateObject(254, 279, 90, 25, "增加(\x3\A\x3)");
	pButton3->SetShortcutKey(VK_ALT_A);
	pButton3->SetID(BUTTONBASE + 3 - 1);

	//Create a Button Control
	CButton* pButton4 = new CButton(pDialog);
	pButton4->CreateObject(369, 279, 90, 25, "退出(\x3\C\x3)");
	pButton4->SetShortcutKey(VK_ALT_C);
	pButton4->SetFc(ClickCancelButton);
	pButton4->SetID(BUTTONBASE + 4 - 1);
	pButton4->SetDefaultFlags(TRUE);


	//Create Grid Control
	CGrid* pGrid1 = new CGrid(pDialog);
	pGrid1->CreateGridEx(4, 68, 475, 188, NULL);
	pGrid1->SetVolumnCaption(0,"A");
	pGrid1->SetVolumnCaption(1,"B");
	pGrid1->SetVolumnCaption(2,"C");
	pGrid1->SetVolumnWidth(0,80);
	pGrid1->SetVolumnWidth(1,80);
	pGrid1->SetVolumnWidth(2,80);
	pGrid1->SetVolumnCursor(1);
	pGrid1->SetNumberFlags(TRUE);
	pGrid1->SetOnlyRead(TRUE);
	pGrid1->SetItemCount(10);


	//Create a Label Control
	CLabel* pLabel1 = new CLabel(pDialog);
	pLabel1->CreateObject(10, 38, 67, 12, "ARP CACHE表");
	pLabel1->SetID(LABELBASE + 1 - 1);

	//Create Group Control
	CStatic* pGroup1 = new CStatic(pDialog);
	pGroup1->CreateObject(3, 261, 475, 54, "");
	pGroup1->SetID(GROUPBASE + 1 - 1);

    //============================================================
	pGrid1->SetVolumnCaption(0,"Orde");
	pGrid1->SetVolumnCaption(1,"IP地址");
	pGrid1->SetVolumnCaption(2,"NIC地址");
	pGrid1->SetVolumnCaption(3,"地址类型");
	pGrid1->SetVolumnWidth(0, 40);
	pGrid1->SetVolumnWidth(1, 155);
	pGrid1->SetVolumnWidth(2,155);
	pGrid1->SetVolumnWidth(3,80);
	pGrid1->SetItemCount(MAX_ARP_CACHE);

	extern ARPCACHE mAfxArpCache[];
	char buf[256];
	for (int i = 0; i < MAX_ARP_CACHE; i++)
	{
		::sprintf(buf, "P%02d", i + 1);
		pGrid1->SetSel(i, 0, buf);

		if (mAfxArpCache[i].wType == ARP_CACHE_EMPTY ||
			mAfxArpCache[i].wType == ARP_CACHE_ILLIGAL)
		{
			pGrid1->SetSel(i, 1, "000.000.000.000");
			pGrid1->SetSel(i, 2, "00.00.00.00.00.00");
			pGrid1->SetSel(i, 3, "空");

			continue;
		}


		_fstrcpy(buf, ::inet_ntoa(
			*((struct in_addr *)&mAfxArpCache[i].mIPAddr)));
		pGrid1->SetSel(i, 1, buf);

		_fstrcpy(buf, ::iphy_fromnic(mAfxArpCache[i].mEthernetAddr));
		pGrid1->SetSel(i, 2, buf);

		::sprintf(buf, "%s", (mAfxArpCache[i].wType ==
			ARP_CACHE_DYNAMIC)?"动态":"静态");
		pGrid1->SetSel(i, 3, buf);


//	ETHERNET_ADDRESS mEthernetAddr;


    }

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

	//go into Message Loop
	pDialog->DoModal();//进入窗口消息循环

	//Destroy Window 
	delete pDialog;//删除对话框

	return;
}
