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

void far ClickLoadFile_DemoMultiEditDialog(CObject* pCurObj)
{
	CDialog *pDialog = (CDialog *)pCurObj->GetParent();
	CMultiEdit* pEdit1 = (CMultiEdit *)pDialog->ObjectFromID(EDITBASE + 1 - 1);

	char strFullPathName[MAXPATH];
	if (!::AfxOpenFileDialog(TRUE, strFullPathName))
    {
    	return;
    }

    pEdit1->LoadFile(strFullPathName);

	pEdit1->Show();
}

void far ClickSaveFile_DemoMultiEditDialog(CObject* pCurObj)
{
	CDialog *pDialog = (CDialog *)pCurObj->GetParent();
	CMultiEdit* pEdit1 = (CMultiEdit *)pDialog->ObjectFromID(EDITBASE + 1 - 1);


	char strFullPathName[MAXPATH];
	if (!::AfxOpenFileDialog(FALSE, strFullPathName))
    {
    	return;
    }

    pEdit1->SaveFile(strFullPathName);
}


void far DemoMultiEditDialog()
{
	//Create a Dialog On the Center of Desktop
	CDialog* pDialog = new CDialog;//分配实例
	pDialog->CreateWindow(0, 0, 547, 321, "多行编辑框演示");//建立窗口
	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(396, 269, 121, 24, "退出(\x3\C\x3)");
	pButton1->SetShortcutKey(VK_ALT_C);
	pButton1->SetFc(ClickCancelButton);
	pButton1->SetID(BUTTONBASE + 1 - 1);

	//Create a Button Control
	CButton* pButton2 = new CButton(pDialog);
	pButton2->CreateObject(396, 226, 121, 24, "另存为(\x3S\x3)");
	pButton2->SetShortcutKey(VK_ALT_S);
	pButton2->SetID(BUTTONBASE + 2 - 1);

	//Create a Button Control
	CButton* pButton3 = new CButton(pDialog);
	pButton3->CreateObject(396, 184, 121, 24, "装入文件(\x3L\x3)");
	pButton3->SetShortcutKey(VK_ALT_L);
	pButton3->SetID(BUTTONBASE + 3 - 1);
        pButton3->SetDefaultFlags(TRUE);

	//Create MultiEdit Control
	CMultiEdit* pEdit1 = new CMultiEdit(pDialog);
	pEdit1->CreateObject(10, 29, 367, 278, NULL);
	pEdit1->SetID(EDITBASE + 1 - 1);


    pButton2->SetFc(ClickSaveFile_DemoMultiEditDialog);
    pButton3->SetFc(ClickLoadFile_DemoMultiEditDialog);

	pEdit1->SetWindowText("《天龙八布》\n《新闻联播》\n《我爱我家》");

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

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

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


	return;

}

