#include "Symbol.h"
#include "MyFrame.h"
#include "Conio.h"
#include "Bios.h"
#include <Socket3.h>

extern BOOL bAfxManager;
extern BOOL far bAfxGotoMonitor;
extern CWindow*   pAfxWindow;
//菜单函数一
void far ClickMenu_Open(CObject* pCurObj)
{
    char buf[300];
    char bufFile[256];
    if (!AfxOpenFileDialog (TRUE, bufFile, "abc.txt"))
    {
        return;
    }

    ::sprintf (buf, "你选择了打开文件---\n    %s", bufFile);
	AfxMessageBox("打开文件", buf, MB_OK);
}
//菜单函数二
void far ClickMenu_Save(CObject* pCurObj)
{
    char buf[300];
    char bufFile[256];
    if (!AfxOpenFileDialog (FALSE, bufFile, "abc2.txt"))
    {
        return;
    }

    ::sprintf (buf, "你选择了另存为文件---\n    %s", bufFile);
	AfxMessageBox("打开文件", buf, MB_OK);
}

//功能
void far MenuInstance()
{
	//分配对话框实例
	CWindow *pWindow = new CWindow;
	//建立一个600*300的分辨率的窗口
	pWindow->CreateWindow(0, 0, GetMaxX() + 1, GetMaxY() + 1 ,"窗口实例");
	//将窗口居中
	pWindow->Center();

	//建立关闭按钮
	new CCloseButton(pWindow);

	//建立一个窗口菜单
	CMenu *pMenu=new CMenu(pWindow);

	//建立二个弹出菜单
	CBar   *pBar1=new CBar(pMenu);//弹出菜单1
	CBar   *pBar2=new CBar(pMenu); //弹出菜单2
	CBar   *pBar3=new CBar(pMenu); //弹出菜单2
	CBar   *pBar4=new CBar(pMenu); //弹出菜单2

	pMenu->AddItem("文件",pBar1, NULL); //"窗口菜单"增加"弹出菜单1"
	pMenu->AddItem("编辑",pBar2, NULL); //"窗口菜单"增加"弹出菜单2"
	pMenu->AddItem("窗口",pBar3, NULL); //"窗口菜单"增加"弹出菜单2"
	pMenu->AddItem("帮助",pBar4, NULL); //"窗口菜单"增加"弹出菜单2"
	pMenu->AddItem("关闭",NULL, ( void far (*)(CObject*))CloseWindow); // CloseWindow是内核API

	pBar1->AddItem("新  建", NULL); //"弹出菜单1"增加一菜单条
	pBar1->AddItem("打  开", (void far (*)(CObject*))ClickMenu_Open); //"弹出菜单1"增加一菜单条
	pBar1->AddItem("另存为", (void far (*)(CObject*))ClickMenu_Save); //"弹出菜单1"增加一菜单条
    pBar1->AddSeparator();
	pBar1->AddItem("退  出", (void far (*)(CObject*))CloseWindow); //"弹出菜单1"增加一菜单条

    //----------------------------------------------------------
	pBar2->AddItem("取  消",NULL); //"弹出菜单2"增加一菜单条
	pBar2->AddItem("拷贝",NULL); //"弹出菜单2"增加一菜单条
	pBar2->AddItem("粘贴",NULL); //"弹出菜单2"增加一菜单条

	pBar3->AddItem("最大化",NULL); //"弹出菜单2"增加一菜单条
	pBar3->AddItem("移动",NULL); //"弹出菜单2"增加一菜单条
	pBar3->AddItem("复原",NULL); //"弹出菜单2"增加一菜单条

	pBar4->AddItem("上下文",NULL); //"弹出菜单2"增加一菜单条
	pBar4->AddItem("索引",NULL); //"弹出菜单2"增加一菜单条
	pBar4->AddItem("主题查询",NULL); //"弹出菜单2"增加一菜单条


    CButton* pButton = new CButton(pWindow);
    pButton->CreateObject(100,100,100,24, "abc");

	//显示窗口
	pWindow->ShowWindow();
    //进入窗口消息循环
	pWindow->PurseMessage();
	//删除窗口对象
	delete pWindow;
    return;
}
