简单的问题,窗口显示在最前面(50)

  • 主题发起人 主题发起人 wlyft
  • 开始时间 开始时间
W

wlyft

Unregistered / Unconfirmed
GUEST, unregistred user!
form的属性如下borderstyle 是bsNoneformstyle fsStayOnTopwindowstate wsNormalprocedure TForm2.FormCreate(Sender: TObject);begin SetWindowPos(Handle,HWND_TOPMOST,Left,Top,Width,Height,0); end;都不能使他最前端显示呢,哪里设错了?
 
procedure TForm1.FormCreate(Sender: TObject);//设定窗口的属性,使其保持在最前var temp: Integer;begin SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, @temp, 0); //限制功能键 formstyle:=fsStayOnTop; windowstate:=wsMaximized;end;
 
这个方法不行我不要windowstate:=wsMaximized;我这个程序有form1`form2,form1,formstyle:=fsStayOnTop;就能保持最前面form2怎么不行?奇怪得很,是不是哪个属性设不对造成的?
 
Form2.ShowModal
 
放哪里?
 
不管用是因为Form2不是程序的主窗体,而是从属窗体。因此改一下,它的父窗体就可以了。type TForm2 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } procedure CreateParams(var Params: TCreateParams); override; public { Public declarations } end;var Form2: TForm2;implementation{$R *.dfm}procedure TForm2.CreateParams(var Params: TCreateParams);begin inherited; Params.WndParent := GetDesktopWindow;end;procedure TForm2.FormCreate(Sender: TObject);begin SetWindowPos(Self.Handle,HWND_TOPMOST,Left,Top,Width,Height,0);end;
 
可以了,但,下面变成两个程序栏了
 
procedure TForm2.Createparams(var params: TCreateParams); begin inherited CreateParams(Params); with params do begin ExStyle := WS_EX_TOOLWINDOW or WS_EX_TOPMOST; WndParent := GetDesktopWindow; end; end;
 
不好意思,再问在用上面的方式前端显示后怎么取消前端显示呢呵呵
 
unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm2 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } FOnTop: Boolean; public { Public declarations } procedure CreateParams(var Params: TCreateParams); override; end;var Form2: TForm2;implementation{$R *.dfm}procedure TForm2.CreateParams(var Params: TCreateParams);begin inherited CreateParams(Params); with params do begin ExStyle := WS_EX_TOOLWINDOW; WndParent := GetDesktopWindow; end;end;procedure TForm2.FormCreate(Sender: TObject);begin FOnTop := False;end;procedure TForm2.Button1Click(Sender: TObject);begin if FOnTop then begin //取消置顶 SetWindowPos(Self.Handle,HWND_NOTOPMOST,Left,Top,Width,Height,0); FOnTop := False; end else begin //置顶 FOnTop := True; SetWindowPos(Self.Handle,HWND_TOPMOST,Left,Top,Width,Height,0); end;end;
 
后退
顶部