unit sysmenudemoUnit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ToolWin;
type
TForm1 =
class(TForm)
Button1: TButton;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ButNotepadMenu: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure ToolButton1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ButNotepadMenuClick(Sender: TObject);
private
{ Private declarations }
procedure ShowSysMenu(aWin: HWND; X,Y: Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ShowSysMenu(aWin: HWND; X,Y: Integer);
var aLPar : LPARAM;
begin
//hier ist der Fehler, das klappt wenn man aus IDE Startet für alle Fenster
//wenn man außerhalb wer IDE startet nur für eigene Fenster
aLPar:=(Y
shl 16) + X;
PostMessage(aWin, $0313,0,aLPar);
//send window showmenu message from: http://delphi.about.com/od/vclwriteenhance/a/ttaskbarmenu.htm
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//Eigene Systemmenü anzeigen
ShowSysMenu(
Handle,Mouse.CursorPos.X,Mouse.CursorPos.Y);
end;
procedure TForm1.ToolButton1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//Eigene Systemmenü anzeigen
ShowSysMenu(
Handle,Mouse.CursorPos.X,Mouse.CursorPos.Y);
end;
procedure TForm1.ButNotepadMenuClick(Sender: TObject);
var aWin: HWND;
begin
//Notepad(Editor) Systemmenü anzeigen
aWin := FindWindow('
notepad',
nil);
if aWin=0
then begin //Notepad Vielleicht nicht gestartet deshalb starten
WinExec('
notepad.exe',SW_SHOW);
aWin := FindWindow('
notepad',
nil);
end;
if aWin<>0
then ShowSysMenu(aWin,Mouse.CursorPos.X,Mouse.CursorPos.Y);
end;
end.