Delphi主窗口任务栏菜单的问题

Delphi的VCL框架在创建应用时TApplication是一个自动创建的隐藏窗口,其它创建的窗口是自动以该窗口为窗口,这就导致创始的主窗口在任务栏的系统菜单只有三项,只要在主窗口的Create事件中将系统菜单用Application的系统菜单替换,并将SysCommand消息转发到主窗口就正常了。

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    procedure OnMessage(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  GetSystemMenu(Application.Handle,True);
  Application.OnMessage:=OnMessage;
end;

procedure TForm1.OnMessage(var Msg: TMsg; var Handled: Boolean);
begin
  case Msg.message of
    WM_SYSCOMMAND:
      begin
        SendMessage(Handle,Msg.message,Msg.wParam,Msg.lParam);
        Handled:=True;
      end;
  end;
end;

end.

你可能感兴趣的:(Delphi,相关技术)