How to make a window like Windows 7 Notifications Flyouts, (WS_THICKFRAME but NOT-RESIZABLE)
I just made a small app here in Delphi 7 that simulates the default system icons, like Volume, Battery, Clock, Network.
I'm trying to follow all Microsoft recomendations here http://msdn.microsoft.com/en-us/library/aa511448.aspx#f开发者_JAVA百科lyouts
To make a window look like a flyout, i'm using this code:
//declaration
TForm1 = class(TForm)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
implementation
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := WS_POPUP or WS_THICKFRAME;
Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST;
end;
My problem is the WS_THICKFRAME allows user to resize the window. How can I fix this?
You can prevent resizing by handling WM_GETMINMAXINFO.
However, this won't prevent the resize cursor from being used. For that, you can handle WM_NCHITTEST
.
Just handle the WM_NCHITTEST
message and always return HTCLIENT
value.
Which will mean for OS that it is over the client area of the app. It will not then show the resize cursor.
I'm using this approach in WPF app.
Try this style: WS_DLGFRAME (0x00400000)
Use the following code and you will get rid of the resize mouse cursor.
unit Unit1;
interface
uses
Windows, Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or WS_THICKFRAME;
end;
procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
begin
inherited;
with Message do begin
Result := HTCLIENT;
end;
end;
end.
精彩评论