激活窗口(200分)

  • 主题发起人 主题发起人 Pipi.
  • 开始时间 开始时间
P

Pipi.

Unregistered / Unconfirmed
GUEST, unregistred user!
如何把后台的窗口切换到前台来,
并且要获得focus,而不是光显示到前台,也不只是在任务栏闪几闪
 
if myform.canfocus then
myform.setfocus;
 
你这个方法是没用的。
注意,窗口原来是被其他进程的窗口覆盖的,而且当前输入焦点在其他进程,
现在碰到某种情况,需要它切换到前台来,而且获得焦点,立即可以在它上面输入
类似于SetForeGroundWindow在win95下的作用,不过在win98/2000下只是会在任务栏
闪啊闪
 
不知道你需要切换后台得指定窗口,还是模拟一下Alt+TAB
 
setforegroundwindow和setactivewindow
 
BringToFront!
 
///Copy的
从Win98开始,微软更改了系统代码,一般的SetForegroundWindow只能将
状态栏中应用按钮闪烁,并没有将应用调到最前面。请使用下列函数:

function ForceForegroundWindow(hwnd: THandle): boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
timeout: DWORD;
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
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout,
0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
TObject(0), SPIF_SENDCHANGE);
Result := SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
TObject(timeout), SPIF_SENDCHANGE);
end
else
Result := SetForegroundWindow(hWnd);
end; { ForceForegroundWindow }

***********************
发现一个2000下面的方法,试一下
function AllowSetForegroundWindow( dwProcessId:DWORD): BOOL; stdcall;

implementation
function AllowSetForegroundWindow; external 'user32.dll' name 'AllowSetForegroundWindow';
 
Sorry,刚才太急了。
应该是: Application.BringToFront;
OK!
 
Kingron 是正确的
不过最后SystemParametersInfo恢复参数:
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,Pointer(timeout), SPIF_SENDCHANGE);
如果不去掉,在WIN2000下不灵
 
完整写法:Win98和Win2000下都可以用
function ForceForegroundWindow(hwnd: THandle): boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
timeout: DWORD;
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
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @TimeOut, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Pointer(0), SPIF_SENDCHANGE);
Result := SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,Pointer(TimeOut), SPIF_SENDCHANGE);
end
else
Result := SetForegroundWindow(hWnd);
end;
 
后退
顶部