Recent

Author Topic: Menu In Title Bar Application Icon  (Read 4779 times)

guest60499

  • Guest
Menu In Title Bar Application Icon
« on: August 03, 2018, 07:22:06 pm »
Hello,

I'm afraid I don't really know what to call this. It is popular especially with terminal applications. The user clicks on the icon in the upper left of the application window in the title bar and there are various options.

How are those set, and what is this menu called?

Cheers,
    guest

Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: Menu In Title Bar Application Icon
« Reply #1 on: August 03, 2018, 07:31:50 pm »
PopupMenu, you can find it in the "Standard" tab on the component toolbar. It is the second item from the left.

How to use it?
Drop a TPopupMenu on the form, double click it and set items for it. Then link it to the form using Object Inspector. TForm has a property called "PopupMenu".

Try it, it's not hard.


Sorry, I was wrong.
I think what you meant is TForm.BorderIcons. You can remove some items but can't add your own items there (in Linux).
« Last Edit: August 03, 2018, 07:42:28 pm by Handoko »

guest60499

  • Guest
Re: Menu In Title Bar Application Icon
« Reply #2 on: August 03, 2018, 08:54:59 pm »
BorderIcons gave me the lead I needed. From the Delphi documentation, removing biSystemMenu removes the application icon from the title bar which is what contains the menu I am speaking of.

Searching for variations of "Windows system menu Delphi/FPC" isn't as helpful as one would hope.

ASerge

  • Hero Member
  • *****
  • Posts: 2240
Re: Menu In Title Bar Application Icon
« Reply #3 on: August 03, 2018, 09:11:41 pm »
How are those set, and what is this menu called?
System menu. Set by system. Can be changed by program. Example:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, LMessages;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     procedure FormCreate(Sender: TObject);
  13.   private
  14.     procedure WMSysCommand(var Msg: TLMSysCommand); message LM_SYSCOMMAND;
  15.   end;
  16.  
  17. var
  18.   Form1: TForm1;
  19.  
  20. implementation
  21.  
  22. {$R *.lfm}
  23.  
  24. uses Windows;
  25.  
  26. const
  27.   CMenuId = 100;
  28.  
  29. procedure TForm1.FormCreate(Sender: TObject);
  30. const
  31.   CInsertPosition = 0;
  32.   CNewMenuItem = 'New menu item';
  33. var
  34.   Mnu: HMENU;
  35.   R: TMenuItemInfoW;
  36. begin
  37.   Mnu := GetSystemMenu(Handle, False);
  38.   if Mnu <> 0 then
  39.   begin
  40.     ZeroMemory(@R, SizeOf(R));
  41.     R.cbSize := SizeOf(R);
  42.     R.fMask := MIIM_STRING or MIIM_ID;
  43.     R.wID := CMenuId;
  44.     R.dwTypeData := CNewMenuItem;
  45.     if InsertMenuItemW(Mnu, CInsertPosition, True, @R) then
  46.       DrawMenuBar(Mnu);
  47.   end;
  48. end;
  49.  
  50. procedure TForm1.WMSysCommand(var Msg: TLMSysCommand);
  51. begin
  52.   inherited;
  53.   if Msg.CmdType = CMenuId then
  54.   begin
  55.     Application.MessageBox('My menu item clicked. Menu reset to default.', 'Info');
  56.     GetSystemMenu(Handle, True);
  57.     Msg.Result := 0;
  58.   end;
  59. end;
  60.  
  61. end.

 

TinyPortal © 2005-2018