Hidden Main Menu in a delphi program, automatically shown using Alt key

前端 未结 1 1705
闹比i
闹比i 2021-02-01 04:36

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.

1条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 04:49

    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'.)

    0 讨论(0)
提交回复
热议问题