开发者

Delphi form without system menu but with close button

By default, a form ha开发者_JAVA技巧ving BorderStyle=bsSizeable has a system menu (on the left) and a close button ('X', on the right). I want to get rid of the system menu and keep the close button.

The BorderIcons property lets me remove the system menu (via biSystemmenu), but now the close button is gone too.

Is there a way to do this?

Using Delphi XE

PS: it should be possible as far as Windows is concerned: IE8's "InPrivate Filtering settings" window is sizeable, has a close button and has no system menu.


BorderStyle := bsSizeToolWin does what you want, with a slightly different appearance of the X button.


By "system menu" do you mean icon on the left of title bar? Or popup menu invoked via right click?

If it is icon that you want to remove - use this code:

const
  WM_ResetIcon = WM_APP - 1;

type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  protected
    procedure WMResetIcon(var Message: TMessage); message WM_ResetIcon;
  end;

implementation

procedure TForm1.FormShow(Sender: TObject);
begin
  PostMessage(Handle, WM_ResetIcon, 0, 0);
end;

procedure TForm1.WMResetIcon(var Message: TMessage);
const
  ICON_SMALL = 0;
  ICON_BIG   = 1;
begin
  DestroyIcon(SendMessage(Handle, WM_SETICON, ICON_BIG, 0));
  DestroyIcon(SendMessage(Handle, WM_SETICON, ICON_SMALL, 0));
end;


I don't think there is a way to do this without resorting to custom drawing your non-client area which is very difficult when glass is involved.

Consider this method.

procedure TMyForm.DeleteSystemMenu;
var
  SystemMenu: HMenu;
begin
  SystemMenu := GetSystemMenu(Handle, False);
  DeleteMenu(SystemMenu, SC_CLOSE, MF_BYCOMMAND);
end;

Yes it succeeds in getting rid of the close item from the system menu, but it also results in the close button being disabled. So it would seem that you can't have one without the other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜