home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / VCL / SYSMENU.PAS < prev   
Pascal/Delphi Source File  |  1997-02-15  |  3KB  |  96 lines

  1. {*********************************************************}
  2. {                                                         }
  3. {    Calmira Visual Component Library 1.0                 }
  4. {    by Li-Hsin Huang,                                    }
  5. {    released into the public domain January 1997         }
  6. {                                                         }
  7. {*********************************************************}
  8.  
  9. unit Sysmenu;
  10.  
  11. { TSystemMenu provides a thin wrapper for the Windows API menu functions,
  12.   and is used to change a form's system menu.  It's most useful in the
  13.   OnCreate handler, when you can modify the menu before the form appears.
  14.   Mainly, it saves you having to remember (or look up) the multitude of
  15.   parameters. }
  16.  
  17. interface
  18.  
  19. uses
  20.   SysUtils, WinTypes, WinProcs, Messages, Classes, Controls, Forms;
  21.  
  22. type
  23.   TSystemMenu = class(TComponent)
  24.   private
  25.     { Private declarations }
  26.     FHandle : HMenu;
  27.   protected
  28.     { Protected declarations }
  29.     procedure Loaded; override;
  30.   public
  31.     { Public declarations }
  32.     procedure Reset;
  33.     procedure Add(Caption: PChar; Command: Word);
  34.     procedure Insert(Index: Integer; Caption: PChar; Command: Word);
  35.     procedure AddSeparator;
  36.     procedure Delete(Index: Integer);
  37.     procedure DeleteCommand(Command: Word);
  38.     procedure Rename(Command: Word; Caption: PChar);
  39.     property Handle: HMenu read FHandle;
  40.   published
  41.     { Published declarations }
  42.   end;
  43.  
  44. procedure Register;
  45.  
  46. implementation
  47.  
  48. procedure TSystemMenu.Loaded;
  49. begin
  50.   inherited Loaded;
  51.   FHandle := GetSystemMenu((Owner as TForm).Handle, False);
  52. end;
  53.  
  54. procedure TSystemMenu.Reset;
  55. begin
  56.   FHandle := GetSystemMenu((Owner as TForm).Handle, True);
  57. end;
  58.  
  59. procedure TSystemMenu.Add(Caption: PChar; Command: Word);
  60. begin
  61.   AppendMenu(FHandle, MF_ENABLED, Command, Caption);
  62. end;
  63.  
  64. procedure TSystemMenu.AddSeparator;
  65. begin
  66.   AppendMenu(FHandle, MF_SEPARATOR, 0, nil);
  67. end;
  68.  
  69.  
  70. procedure TSystemMenu.Delete(Index: Integer);
  71. begin
  72.   DeleteMenu(FHandle, Index, MF_BYPOSITION);
  73. end;
  74.  
  75. procedure TSystemMenu.DeleteCommand(Command: Word);
  76. begin
  77.   DeleteMenu(FHandle, Command, MF_BYCOMMAND);
  78. end;
  79.  
  80. procedure TSystemMenu.Rename(Command: Word; Caption: PChar);
  81. begin
  82.   ModifyMenu(FHandle, Command, MF_BYCOMMAND, Command, Caption);
  83. end;
  84.  
  85. procedure TSystemMenu.Insert(Index: Integer; Caption: PChar; Command: Word);
  86. begin
  87.   InsertMenu(FHandle, Index, MF_BYPOSITION, Command, Caption);
  88. end;
  89.  
  90. procedure Register;
  91. begin
  92.   RegisterComponents('Gadgets', [TSystemMenu]);
  93. end;
  94.  
  95. end.
  96.