{从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 }
{从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 }
ForceForegroundWindow(AHwnd{你要激活的窗口句柄})
DWORD dwCurID = ::GetCurrentThreadId();
DWORD dwForeID = ::GetWindowThreadProcessId(hForegdWnd, NULL);
::AttachThreadInput(dwCurID, dwForeID, TRUE);
::SetForegroundWindow(m_hWnd);
::AttachThreadInput(dwCurID, dwForeID, FALSE); 这个肯定行,自己改为delphi的