All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
深入探讨PHP中的内存管理问题_php资料_编程技术
SQL Server 2005下的分页SQL_[SQL Server教程]
在ASP.NET应用程序中上传文件_[Asp.Net教程]
PHP一些常用的正则表达式_[PHP教程]
PHP的十个高级技巧(中)_[PHP教程]
delphi弹出菜单组件(TPopMenu)
你必须知道的.NET之恩怨情仇:is和as_.net资料_编程技术
PHP日常开发小技巧_[PHP教程]
ASP.NET&Spring.NET&NHibernate最佳实践(六)——第3章人事子系统(3)_[Asp.Net教程]
入门:PHP与MYSQL的结合操作_php资料_编程技术
Reading number is top 10 pictures
陪睡门马睿菈自曝写真 称首拍大尺度照片1
王艳写真温柔如水1
30 beautiful school beauty6
NeedWallpaper11
为什么别人说你是疯子
Is said to be a Chinese female artist fame explicit pictures before1
yy365网站上的美女1
Absolutely shocked. National geographic 50 animal photographys5
毕姥爷事件,告诉你6条真理
The woman fight much more than men
Download software ranking
Rio big adventure
apache-tomcat-6.0.33
VC++6.0培训教程
Visual C++界面编程技术
White deer villiage
The cock of the Grosvenor LTD handsome
linux高级编程
美女游泳记
Professional killers2 data package
I for your crazy
qq published in(发表于) 2014/7/9 22:39:02 Edit(编辑)
visual c++中制作弹出式菜单

visual c++中制作弹出式菜单

visual c++中制作弹出式菜单

visual c++中制作弹出式菜单

菜单一般分两类,除了前面介绍的依附于框架窗口的一般菜单,另一类是浮动的弹出式菜单,也称为快捷菜单或上下文菜单。

在Visual C++中,弹出式菜单主要是通过CMenu类实现的。

请看下面的实例,为程序增加一个帮助、关于快捷菜单。


void CMyDlg::OnContextMenu(CWnd* pWnd, CPoint point)

{

CMenu mnu;

if(mnu.CreatePopupMenu())

{

mnu.AppendMenu(MF_STRING,ID_MYHELP,"帮助(&H)");

mnu.AppendMenu(MF_STRING,ID_MYABOUT,"关于(&A)…");

mnu.TrackPopupMenu(TPM_CENTERALIGN,point.x,point.y ,this);

}

}

运行结果如图1所示。


图1 快捷菜单实例运行结果

除了上面的方法,Visual C++还提供了更简便的方法。

(1)单击系统主菜单“Project”/“Add to Project”/“Components and Controls”,在弹出的“Components and Controls Gallery”对话框中选择“Visual C++ Components”文件夹,然后选择“Pop-up Menu”,如图2所示。


图2 “Components and Contrals Gallery”对话框

(2)单击“Insert”按钮,系统会要求用户确认,单击“确定”按钮,弹出“Pop-up Menu”对话框。

(3)在此对话框中,将“Add Pop-up Menu to”组合框的内容改为“CMyView”。单击“OK”按钮,将此快捷菜单添加到项目中。

(4)此时,在“Workspace”工作区中,“ResourceView”选项卡里会添加一个菜单资源,按照上面讲述的编辑普通菜单的方法编辑此快捷菜单。

(5)实际上,这种方法只是让系统自动为程序添加显示快捷菜单的代码,其OnContextMenu成员函数中会自动添加如下代码:


void CAboutDlg::OnContextMenu(CWnd*, CPoint point)

{

{

if (point.x == -1 && point.y == -1){

//keystroke invocation

CRect rect;

GetClientRect(rect);

ClientToScreen(rect);

point = rect.TopLeft();

point.Offset(5, 5);

}

CMenu menu;

VERIFY(menu.LoadMenu(CG_IDR_POPUP_ABOUT_DLG));

CMenu* pPopup = menu.GetSubMenu(0);

ASSERT(pPopup != NULL);

CWnd* pWndPopupOwner = this;

while (pWndPopupOwner->GetStyle() & WS_CHILD)

pWndPopupOwner = pWndPopupOwner->GetParent();

pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,

pWndPopupOwner);

}

}


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.