全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
对于一些特殊的菜单项,如Help菜单项,放在窗口的最右边比较好。我们可以用Windows的API函数ModifyMenu来实现,它完成对已存在菜单的菜单项设置的改变。函数ModifyMenu的原型为:Bool ModifyMenu( HMENU hMnu , UINT uPosition , UINT uFlags ,UINT uIDNEWItem , LPCTSTR lpNewItem );其中hMnu :指得是要修改菜单的句柄uPosition:指得是要修改菜单的菜单项索引,其值从零开始到菜单项的总数减一uFlags:指得是新菜单项的状态和uPosition的类型uIDNewItem:指得是新菜单的句柄lpNewItem:指得是修改后菜单的标题如果设置第四个参数为新菜单的句柄,程序运行时就会把菜单项改成我们重新设计的模式。用Borland C+Builder6进行讲解。1、通过File|New Application创建一个新工程2、在窗体Form1中添加MainMenu组件,通过右键弹出菜单的Menu Designer命令设计一个简单的菜单,包含两个菜单项,其Caption分别为&File和&Help.此时菜单Help的名称为Help1。3、在Form1的OnCreate事件的处理过程中添加如下代码void _fastcall TForm1:FormCreate( TObject *Sender )ModifyMenu( MainMenu1-Handle , 1 , MF_BYPOSITION|MF_POPUP|MF_HELP, UINT(Help1-Handle ) , 帮助(&H);/菜单的其他性质int i; TMenuItem *xx; i = MainMenu1-Items-Count; Application-MessageBoxA(IntToStr( i ).c_str() , , MB_OK); xx = MainMenu1-Items-Items0; Application-MessageBoxA(xx-Caption.c_str() , , MB_OK); i = xx-Count; Application-MessageBoxA(IntToStr( i ).c_str() , , MB_OK); Application-MessageBoxA(xx-Items1-Caption.c_str() , , MB_OK); ModifyMenu( MainMenu1-Handle , 1 , MF_BYPOSITION|MF_POPUP|MF_HELP , UINT(Help1-Handle ),帮助(&H);The ModifyMenu function changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item. The ModifyMenu function has been superseded by the SetMenuItemInfo function. You can still use ModifyMenu, however, if you do not need any of the extended features of SetMenuItemInfo.BOOL ModifyMenu( HMENU hMnu,/ handle of menu UINT uPosition,/ menu item to modify UINT uFlags,/ menu item flags UINT uIDNewItem,/ menu item identifier or handle of drop-down menu or submenu LPCTSTR lpNewItem/ menu item content );ParametershMnuIdentifies the menu to be changed. uPositionSpecifies the menu item to be changed, as determined by the uFlags parameter. uFlagsSpecifies flags that control the interpretation of the uPosition parameter and the content, appearance, and behavior of the menu item. This parameter must be a combination of one of the following required values and at least one of the values listed in the following Remarks section. ValueMeaningMF_BYCOMMANDIndicates that the uPosition parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified.MF_BYPOSITIONIndicates that the uPosition parameter gives the zero-based relative position of the menu item. uIDNewItemSpecifies either the identifier of the modified menu item or, if the uFlags parameter has the MF_POPUP flag set, the handle of the drop-down menu or submenu. lpNewItemPoints to the content of the changed menu item. The interpretation of this parameter depends on whether the uFlags parameter includes the MF_BITMAP, MF_OWNERDRAW, or MF_STRING flag. ValueMeaningMF_BITMAPContains a bitmap handle. MF_OWNERDRAWContains a 32-bit value supplied by an application that is used to maintain additional data related to the menu item. The value is in the itemData member of the structure pointed to by the lparam parameter of the WM_MEASUREITEM or WM_DRAWITEM messages sent when the menu item is created or its appearance is updated. MF_STRINGContains a pointer to a null-terminated string (the default). Return ValuesIf the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError. RemarksIf ModifyMenu replaces a menu item that opens a drop-down menu or submenu, the function destroys the old drop-down menu or submenu and frees the memory used by it. The application must call the DrawMenuBar function whenever a menu changes, whether or not the menu is in a displayed window. To change the attributes of existing menu items, it is much faster to use the CheckMenuItem and EnableMenuItem functions. The following list describes the flags that may be set in the uFlags parameter: Value MeaningMF_BITMAP Uses a bitmap as the menu item. The lpNewItem parameter contains the handle of the bitmap. MF_BYCOMMAND Indicates that the uPosition parameter specifies the identifier of the menu item (the default). MF_BYPOSITIONIndicates that the uPosition parameter specifies the zero-based relative position of the new menu item. MF_CHECKED Places a check mark next to the item. If your application provides check mark bitmaps (see the SetMenuItemBitmaps function), this flag displays a checked bitmap next to the menu item. MF_DISABLED Disables the menu item so that it cannot be selected, but this flag does not gray it. MF_ENABLED Enables the menu item so that it can be selected and restores it from its grayed state. MF_GRAYED Disables the menu item and grays it so that it cannot be selected. MF_MENUBARBREAKFunctions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is separated from the old column by a vertical line. MF_MENUBREAK Places the item on a new line (for menu bars) or in a new column (for a drop-down menu, submenu, or shortcut menu) without separating columns. MF_OWNERDRAWSpecifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the window procedure of the owner window whenever the appearance of the menu item must be updated. MF_POPUPSpecifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies the handle of the drop-down menu or submenu. This flag is used to add a menu name to a menu bar or a menu item that opens a submenu to a drop-down menu, submenu, or shortcut menu. MF_SEPARATORDraws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be gra
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年及未来5年中国汽车用齿轮油行业市场调查研究及投资战略咨询报告
- 2025年社区矫正考试试题及答案
- 2020年一级注册建筑师考试建筑材料与构造真题(部分)
- 2020-2025年药学类之药学(师)考前冲刺模拟试卷B卷含答案
- 江苏银行校招笔试题及答案
- 2025年原杉木市场环境分析
- 2025年喷气织机项目投资分析及可行性报告
- 2025年地热用耐热潜水电泵项目投资分析及可行性报告
- 广西贵港市覃塘区2024-2025学年九年级上学期期中检测英语试题(含答案)
- 《民族理论和民族政策(本科必修)》2024-2025期末试题及答案
- 浙江赞生药业有限公司年产20亿片(粒)中成药口服固体制剂项目环评报告
- 国家生态安全课件
- 师生交通安全教育:筑牢校园平安防线
- 2025-2030中国酸枣市场供需格局与营销渠道发展趋势报告
- 股骨粗隆间骨折护理疑难病例讨论
- 《资治通鉴》与为将之道知到课后答案智慧树章节测试答案2025年春武警指挥学院
- 2024年广东春季高考语文试题及答案
- T-QASE 005-2024 岸边集装箱起重机设备使用管理和维护保养作业规范
- 2024年金钥匙科技知识竞赛试题及答案
- 皮瓣手术治疗褥疮
- 物理光学课件-叶玉堂
评论
0/150
提交评论