Delphi开发中子窗口不能置顶的问题
分类:Delphi, System
阅读 (4,047)
Add comments
1月 062015
在Delphi开发中,如果我们想让一个窗口始终置顶显示,则我们只需要把窗口FormStyle属性设置为fsStayOnTop就可以了,但是如果这个窗口不是主窗口,而是子窗口,那就有些麻烦了,设置FormStyle为fsStayOnTop后也无效。解决办法就是在子窗口中重载CreateParams函数,并将WndParent设置为0即可,具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm2 = class(TForm) Button1: TButton; Timer1: TTimer; private { Private declarations } public { Public declarations } protected procedure CreateParams(var Params: TCreateParams); override; end; var Form2: TForm2; implementation {$R *.dfm} { TForm2 } procedure TForm2.CreateParams(var Params: TCreateParams); begin inherited; Params.WndParent := 0; // Params.ExStyle := Params.ExStyle or WS_EX_TOOLWINDOW; //如果不想在任务栏显示窗口图标 end; end. |