delphi 程序中隐藏的主菜单,使用 Alt 键自动显示

编程入门 行业动态 更新时间:2024-10-27 12:24:44
本文介绍了delphi 程序中隐藏的主菜单,使用 Alt 键自动显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

首先,让我说我讨厌 Windows Vista 和 Windows 7 中的此功能.其次,我想这样做..(隐藏菜单.zip)

解决方案

像往常一样使用 TMainMenu 和 TActionList.

然后做

procedure TForm1.FormShow(Sender: TObject);开始Self.Menu := nil;结尾;

(或在设计时简单地删除 Menu 关联)和

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;移位:TShiftState);开始如果 (Key = VK_MENU) 或 (Key = VK_F10) 那么菜单 := MainMenu1;结尾;

procedure TForm1.WndProc(var Message: TMessage);开始遗传;case Message.Msg ofWM_EXITMENULOOP:设置菜单(句柄,0);结尾;结尾;

不要忘记将表单的 KeyPreview 设置为 true.

(请注意,由于快捷方式由 TActionList 处理,因此即使菜单消失",它们也能工作.)

First, let me say that I abominate this feature in Windows Vista and Windows 7. Second, I want to do it. Here is a question asking how to do what I want here, in WPF.

I want to do the same thing, but in Delphi, using VCL stock components, TMainMenu or Action Manager menus, or some available third party components, even Toolbar2000 or some other library.

Feature of Windows Vista/Windows 7 explorer main-menus:

  • it's not visible when the app starts
  • pressing and releasing Alt makes it visible
  • pressing and releasing Alt again makes it invisible again
  • repeatable.
  • hotkeys work on menu items, even when menu is invisible*

(* Windows Explorer Hotkeys Example: Ctrl+A in Microsoft Windows Explorer selects all even when the menus are invisible, Alt+T = bring up Tools popup menu, even when the whole menu is hidden).

Update: Demo using accepted answer can be downloaded here. (HiddenMenu.zip)

解决方案

Use a TMainMenu with a TActionList as usual.

Then do

procedure TForm1.FormShow(Sender: TObject); begin Self.Menu := nil; end;

(or simply remove the Menu association at design time) and

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = VK_MENU) or (Key = VK_F10) then Menu := MainMenu1; end;

and

procedure TForm1.WndProc(var Message: TMessage); begin inherited; case Message.Msg of WM_EXITMENULOOP: SetMenu(Handle, 0); end; end;

Don't forget to set the form's KeyPreview to true.

(Notice that, since the shortcuts are handled by the TActionList, they work even if the menu is 'gone'.)

更多推荐

delphi 程序中隐藏的主菜单,使用 Alt 键自动显示

本文发布于:2023-07-17 03:42:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1129056.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主菜   程序   delphi   Alt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!