按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
//处理机制不一样,其资源并不在此处装入。
return 0;
}
//以上省略代码用于调试,在程序的发行版中将被移去
// 。。。
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnViewLongmenu()
{
// TODO: Add your mand handler code here
SetMenu(&hLongMenu);
hLongMenu。Detach();
//以上部分代码用于实现至长菜单的切换
}
void CMainFrame::OnViewNormalmenu()
{
…………………………………………………………Page 225……………………………………………………………
// TODO: Add your mand handler code here
SetMenu(&hNormalMenu);
hNormalMenu。Detach();
//以上部分代码用于实现至普通菜单的切换
}
void CMainFrame::OnDrawLine()
{
// TODO: Add your mand handler code here
CClientDC ClientDC(this);//创建一客户区设备对象
ClientDC。MoveTo(120;120);//移动对象起点至 (120,120)
ClientDC。LineTo(260;260);//自 (120,120)至 (260,260)画直线
//以上部分代码用于在程序主窗口中作一起点
//为 (120,120),终点为 (260,260)的直线
}
void CMainFrame::OnDrawCircle()
{
// TODO: Add your mand handler code here
CClientDC ClientDC(this);
ClientDC。Arc(80;40;160;120;80;80;80;80);
//以上代码部分用于在屏幕内画圆,基本同上,只是最后作图调用函数Arc
}
void CMainFrame::OnDrawRectangle()
{
// TODO: Add your mand handler code here
CClientDC ClientDC(this);
ClientDC。MoveTo(120;120);
…………………………………………………………Page 226……………………………………………………………
ClientDC。LineTo(170;120);
ClientDC。LineTo(170;150);
ClientDC。LineTo(120;150);
ClientDC。LineTo(120;120);
//基本解释同上,使用设备对象画矩形
}
void CMainFrame::OnDyncmodifyInsert()
{
// TODO: Add your mand handler code here
if(bInsert)//控制重复加入变量为真时允许加入
{
CMenu *pMenu=GetMenu( );//取得程序主菜单指针
CMenu *pSubMenu=pMenu…》GetSubMenu(3);
//函数GetSubMenu()用于从0基取得菜单项指针
pSubMenu…》InsertMenu(ID_APP_ABOUT;
MF_BYMAND;ID_HELP_INSERT;〃&I'm inserted here!〃);
bInsert=FALSE;
}
//以上部分代码用于在HELP菜单中About…。项前
//加入一新菜单”I’m inserted here!”
}
void CMainFrame::OnHelpInsert()
{
// TODO: Add your mand handler code here
MessageBox(〃I'm inserted in the help menu!〃);
//显示一标准消息框,当然,此处对加入菜单的响应较简单,
…………………………………………………………Page 227……………………………………………………………
//仅仅是为了说明问题而已;在后面的函数实现中我们遵循同样的原则,
//读者如果有兴趣,尽可以以自己编写的函数响应代替之
//以上为新加入菜单的响应函数,请读者
//注意前面所讲的加入该响应函数的方法
}
void CMainFrame::OnAppExit()
{
// TODO: Add your mand handler code here
MessageBox(〃Thank you for using this programe!〃);
PostMessage(WM_CLOSE);//发送程序退出消息
//我们对程序退出进行控制,由于程序退出总会产生对该函数的调用,
//在这里,我们力图使我们的程序显得有礼貌些,这一部分读者也可以
//改写之以实现自己所期望的功能
}
void CMainFrame::OnDyncmodifyAppend()
{
// TODO: Add your mand handler code here
if(bAppend)//动态加菜单项至菜单末尾BOOL型控制变量
{
CMenu *pMenu=GetMenu();
CMenu *pSubMenu=pMenu…》GetSubMenu(3);
pSubMenu…》AppendMenu(MF_STRING;ID_HELP_APPEND;〃&I'm appended here!〃);
bAppend=FALSE;
}
//以上部分代码在Help菜单的最末尾加入一菜单项”I’m appended here!”
}
…………………………………………………………Page 228……………………………………………………………
void CMainFrame::OnHelpAppend()
{
// TODO: Add your mand handler code here
MessageBox(〃I'm appended in the help menu!〃);
//菜单项”I’m appended here!”的消息响应函数
}
void CMainFrame::OnDyncmodifyDelete()
{
// TODO: Add your mand handler code here
if(bDelete)//动态删除菜单项BOOL型控制变量
{
CMenu *pMenu=GetMenu();
CMenu *pSubMenu=pMenu…》GetSubMenu(0);
pSubMenu…》DeleteMenu(5;MF_BYPOSITION);
//这里我们采用用位置对菜单项定位,注意菜单项是0基的
//注意:菜单项分隔线也是菜单项
bDelete=FALSE;
}
//以上部分代码删除File中第六个菜单项
}
void CMainFrame::OnDyncmodifyModify()
{
// TODO: Add your mand handler code here
if(bModify)//动态修改菜单项BOOL型控制变量
{
CMenu *pMenu=GetMenu();
…………………………………………………………Page 229……………………………………………………………
CMenu *pSubMenu=pMenu…》GetSubMenu(3);
pSubMenu…》ModifyMenu(ID_APP_ABOUT;
MF_BYMAND;ID_APP_ABOUT;〃&Version information!〃);
bModify=FALSE;
}
//动态的改变Help菜单中显示程序版本信息对话框的菜单文本
//(这种改变后菜单项是不是更能较贴切的反应菜单项真实内容)?
}
void CMainFrame::OnDyncmodifyModifysystemmenu()
{
// TODO: Add your mand handler code here
CMenu *pSystemMenu=GetSystemMenu(FALSE);
//以FALSE调用系统菜单,以便对其进行修改,
//但请注意其消息响应函数的特殊性
pSystemMenu…》ModifyMenu(1;MF_BYPOSITION;ID_FILE_NEW;〃&I'll draw a rectangle!〃);
//改变系统菜单中 “移动”菜单项,以实现在程序窗口中画一矩形
//以上代码修改了系统菜单
}
void CMainFrame::OnDyncmodifyReset()
{
// TODO: Add your mand handler code here
CMenu *pSystemMenu=GetSystemMenu(TRUE);
//以上部分以TRUE为参数调用系统菜单,实现了系统菜单的复原
}
void CMainFrame::OnChange()
{
…………………………………………………………Page 230……………………………………………………………
// TODO: Add your mand handler code here
if(!bBitmap)//控制使用何种菜单的变量
{
bBitmap=TRUE;
CMenu *pMenu=GetMenu( );
CMenu *pSubMenu=pMenu…》GetSubMenu(3);
pSubMenu…》ModifyMenu