following the example in the delphi help
winTimer.Visible := TRUE;
winTimer.BringToFront;
does not work and the timer form remains stubbornly behind my main form.
Any suggestions greatly appreciated.
Philip L jackson
--
Alex Yackimoff
NTV - HTB
Well first off you could try 'SetForeground' rather than bringto front.
But in any case, Win32 had changed the response, to limit windows from
jump at you while working (which I think is a good change).
But in any case it makes forcing a window to the front a little
difficult.
You could try Daniel routine below to force a window front.
function ForceForegroundWindow(hwnd: THandle): boolean;
// Code by Daniel P. Stasinski <dan...@karemor.com>
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 }
Also, Yorai Aminov (TeamB) gave an answer as:
There appear to be several solutions to the SetForegroundWindow...
1.
- Check for Windows 98/NT 5.0.
- Call SystemParametersInfo with the SPI_GETFOREGROUNDLOCKTIMEOUT and
save the value.
- Call SystemParametersInfo with the SPI_SETFOREGROUNDLOCKTIMEOUT to
set the value to 0.
- Call SetForegroundWindow.
- Call SystemParametersInfo with the SPI_SETFOREGROUNDLOCKTIMEOUT to
restore the original value.
The change affects the entire system. Make sure you're only modifying
the value for the duration of the SetForegroundWindow call.
2. Cheat Windows and make it think you have the right to call
SetForegroundWindow:
function ForceForegroundWindow(hWnd: THandle): BOOL;
var
hCurWnd: THandle;
begin
hCurWnd := GetForegroundWindow;
AttachThreadInput(
GetWindowThreadProcessId(hCurWnd, nil),
GetCurrentThreadId, True);
Result := SetForegroundWindow(hWnd);
AttachThreadInput(
GetWindowThreadProcessId(hCurWnd, nil),
GetCurrentThreadId, False);
end;
3. For Windows 98 only, the WIN.INI file can contain a section called
[Compatibility95]. Executable files listed in this section get the
old, Windows 95 behavior for SetForegroundWindow. For example,
Microsoft Visual C++ places the following value in that section:
MSDEV=0x00000002
I'm not sure what the value on the right side means.
To disable this behavior in Windows 98, you can also edit the registry
key HKEY_CURRENT_USER\Control Panel\Desktop. Add the binary value
"ForegroundLockTimeout", and set it to "00 00 00 00". Doing this will
disable the new behavior for the entire system.
--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia