whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

30 Visitors Online


 
...add items to the Application's Windows System Menu?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (8):  
     




  private
    procedure 
OnMessageHandler(var Msg: TMsg; var Handled: Boolean);
  public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;

implementation

{$R *.dfm}

// Identifiers of the new menu items
// Konstanten, welche einen Menüpunkt eindeutig identifizieren
const
  
SC_MyMenuItem1 = WM_USER + $101;
  SC_MyMenuItem2 = WM_USER + $102;

procedure TForm1.FormCreate(Sender: TObject);
var
  
hSysMenu: THandle;
begin
  
// Get Systemmenu Handle
  // Handle zum Systemmenü ermitteln
  
hSysMenu := GetSystemMenu(Application.Handle, False);
  // Add own menu items
  // Eigene Menüitems einfügen
  
AppendMenu(hSysMenu, MF_SEPARATOR, 0, #0);
  AppendMenu(hSysMenu, MF_STRING, SC_MyMenuItem1, '&My Menuitem 1');
  AppendMenu(hSysMenu, MF_STRING or MF_CHECKED , SC_MyMenuItem2, '&My Menuitem 2');
  // Assign a own OnMessage event handler
  // OnMessage event handler festlegen
  
Application.OnMessage := OnMessageHandler;
end;

// OnMessage event handler
procedure TForm1.OnMessageHandler;
begin
  if 
Msg.message = WM_SYSCOMMAND then
  begin
    case 
Msg.wParam of
      
// Which item selected?
      // Welches Menitem wurde ausgewählt?
      
SC_MyMenuItem1:
        begin
          
ShowMessage('SC_MyMenuItem1');
          Handled := True;
        end;
      SC_MyMenuItem2:
        begin
          
ShowMessage('SC_MyMenuItem2');
          Handled := True;
        end;
    end;
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners