你的窗体如果是ShowModal出来的的话,就一定在最前端。
Myform.ShowModal;
Myform.ShowModal;
解决方案 »
- 字符串如何当成对象名呢?例如字符串Edit1当成对象Edit1
- 状态栏中加载图标
- 请看有关SQL动态参数的问题!!
- 关于websnap的服务器端脚本
- 用DELPHI把数据库中的数据导入excel时,如何使001不会变成1 ?就是如何用DELPHI在Excel的单元格中加入’ 号: sheet.cells[i,1]:=’’’+St
- 关于fastreport的一个简单的问题!!在线等!
- sql语句中整型变量怎么表达
- 各位大哥,程序写不下去了,帮帮我
- lfpsoft(聪聪) 请前来领分
- 请教VC++中的CMUTEX在Delphi中用什么来代替或取的作用与之相近?谢谢!
- 关于画ER图的问题,高手请进!
- 怎样能使窗体即是透明的又保持显示在所有窗体的最前面?
还可以当主窗体显示之后,进入其他的窗体后,将主窗体的visible设成false;然后调用api函数,将你想要放在最前的窗体设置一下!
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 // Windows 98/2000 doesn't want to foreground a window
//when some other
// window has keyboard focus 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 // Code from Karl E. Peterson,www.mvps.org/vb/sample.htm
// Converted to Delphi by Ray Lischner
// Published in The Delphi Magazine 55, page 16 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 }
setwindowpos(form1.handle,HWND_TOPmOST,LEFT,TOP,WIDTH,HEIGHT,SWP_NOACTIVE OR SWP_NOMORE OR SWP_NOSIZE)
SetWindowPos(form.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE+SWP_NOSIZE)
procedure AlwaysOnTop(Form: TForm; OnTop: Boolean);
begin
if OnTop then
SetWindowPos(Form.Handle, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE or SWP_NOSIZE)
else
SetWindowPos(Form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE or SWP_NOSIZE)
end;
新产生的窗体属性如果为fsStayOnTop,将继续在最前面。