怎么把一个窗口置于最顶层?(50分)

  • 主题发起人 主题发起人 qsdl
  • 开始时间 开始时间
Q

qsdl

Unregistered / Unconfirmed
GUEST, unregistred user!
将formstyle改为fsStayOnTop或者SetWindowPosHandle,hwnd_TopMost,0,0,0,0,swp_NoMove or swp_NoSize);
我都只能将他放在自己程序所有窗口的顶层,怎么能让他在所有windows的最顶?
 
Public
procedure Createparams(Var Params:TCreateParams);override;
...

procedure TFormDrop.Createparams(var Params:TCreateParams);
begin
Inherited CreateParams(Params);
With Params do
begin
EXStyle:=ExStyle or WS_EX_TOPMOST ;
wndParnet:=GetDesktopWindow; //关键一行,用SetParent都不行!!
end;
end;
 
SetWindowPos(Application.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE or SWP_NOMOVE);SetWindowPos(Self.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE or SWP_NOMOVE);
在你的窗体中执行以上两个命令。
 
SetWindowPos(Application.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE or SWP_NOMOVE);SetWindowPos(Self.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE or SWP_NOMOVE);
怎么觉得只对主form有作用
 
哦,应该是时灵时不灵,第一个那个看不大明白,呵呵,不好意思
 
function ForceForegroundWindow(hwnd: THandle): boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
ForegroundThreadID: DWORD;
ThisThreadID : DWORD;
timeout : DWORD;
begin
if IsIconic(hwnd) then
ShowWindow(hwnd, SW_RESTORE);

if GetForegroundWindow = hwnd then
Result := true
else begin
if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4))
or ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and ((Win32MajorVersion > 4)
or ((Win32MajorVersion = 4)and (Win32MinorVersion > 0)))) then
begin
Result := false;
ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow,nil);
ThisThreadID := GetWindowThreadPRocessId(hwnd,nil);
if AttachThreadInput(ThisThreadID, ForegroundThreadID, true) then
begin
BringWindowToTop(hwnd); // IE 5.5 related hack
SetForegroundWindow(hwnd);
AttachThreadInput(ThisThreadID, ForegroundThreadID, false);
Result := (GetForegroundWindow = hwnd);
end;
if not Result then begin
// Code by Daniel P. Stasinski
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0),SPIF_SENDCHANGE);
BringWindowToTop(hwnd); // IE 5.5 related hack
SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,TObject(timeout), SPIF_SENDCHANGE);
end;
end
else begin
BringWindowToTop(hwnd); // IE 5.5 related hack
SetForegroundWindow(hwnd);
end;
Result := (GetForegroundWindow = hwnd);
end;
end;
..........
ForceForegroundWindow(form1.Handle):


 
zzb1984兄可否解释一下??小弟学delphi没几个月,看不懂,麻烦你了
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部