pede
asked on
Bringing window to front
Simple question, but I couldnt find the answer :o(
How do I bring a window to front, when it is overlapped by system windows?
Application.BringToFront;
Form2.BringToFront;
This works if an application like Outlook is in front, but if a dos- or folder window is overlapping form2, then it doesnt come to front!
How do I bring a window to front, when it is overlapped by system windows?
Application.BringToFront;
Form2.BringToFront;
This works if an application like Outlook is in front, but if a dos- or folder window is overlapping form2, then it doesnt come to front!
formstyle := fsStayOnTop;
try:
SetForegroundWindow(Form1. handle);
it depends on what operating system your using as there are big diference in how 98/nt/2k handle doing this
this is cut from a question the other day about same topic
<start paste>
ok the following is getting silly but im guesssing your using 2k or something else setforegroundwindow
would be working.
its not small but is nessesary ,it came form the borland newsgroups with parts from different sources.
http://groups.google.com/groups?q=forceforegroundwindow+delphi+ray&hl=en&selm=3A62F81B.7790A088%40ia.comweb.nl&rnum=1
so you can call
ForceForeground(handle);
function ForceForeground(AppHandle: HWND): boolean;
const
SPI_GETFOREGROUNDLOCKTIMEO UT = $2000;
SPI_SETFOREGROUNDLOCKTIMEO UT = $2001;
var
ForegroundThreadID: DWORD;
ThisThreadID : DWORD;
timeout : DWORD;
OSVersionInfo : TOSVersionInfo;
Win32Platform : Integer;
begin
if IsIconic(AppHandle) then ShowWindow(AppHandle, SW_RESTORE);
if (GetForegroundWindow = AppHandle) then Result := true else
begin
Win32Platform := 0;
OSVersionInfo.dwOSVersionI nfoSize := SizeOf(OSVersionInfo);
if GetVersionEx(OSVersionInfo ) then Win32Platform := OSVersionInfo.dwPlatformId ;
{ Windows 98/2000 doesn't want to foreground a window when some other window has keyboard focus}
if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (OSVersionInfo.dwMajorVers ion > 4)) or
((Win32Platform = VER_PLATFORM_WIN32_WINDOWS ) and ((OSVersionInfo.dwMajorVer sion > 4) or
((OSVersionInfo.dwMajorVer sion = 4) and (OSVersionInfo.dwMinorVers ion > 0)))) then
begin
Result := false;
ForegroundThreadID := GetWindowThreadProcessID(G etForegrou ndWindow,n il);
ThisThreadID := GetWindowThreadPRocessId(A ppHandle,n il);
if AttachThreadInput(ThisThre adID, ForegroundThreadID, true) then
begin
BringWindowToTop(AppHandle );
SetForegroundWindow(AppHan dle);
AttachThreadInput(ThisThre adID, ForegroundThreadID, false);
Result := (GetForegroundWindow = AppHandle);
end;
if not Result then
begin
SystemParametersInfo(SPI_G ETFOREGROU NDLOCKTIME OUT, 0, @timeout, 0);
SystemParametersInfo(SPI_S ETFOREGROU NDLOCKTIME OUT, 0, TObject(0), SPIF_SENDCHANGE);
BringWindowToTop(AppHandle );
SetForegroundWindow(AppHan dle);
SystemParametersInfo(SPI_S ETFOREGROU NDLOCKTIME OUT, 0, TObject(timeout), SPIF_SENDCHANGE);
Result := (GetForegroundWindow = AppHandle);
if not Result then
begin
ShowWindow(AppHandle,SW_HI DE);
ShowWindow(AppHandle,SW_SH OWMINIMIZE D);
ShowWindow(AppHandle,SW_SH OWNORMAL);
BringWindowToTop(AppHandle );
SetForegroundWindow(AppHan dle);
end;
end;
end else
begin
BringWindowToTop(AppHandle );
SetForegroundWindow(AppHan dle);
end;
Result := (GetForegroundWindow = AppHandle);
end;
end;
see here for details of a new win2k api allowsetforegroundwindow:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_5fw7.asp
<end paste>
SetForegroundWindow(Form1.
it depends on what operating system your using as there are big diference in how 98/nt/2k handle doing this
this is cut from a question the other day about same topic
<start paste>
ok the following is getting silly but im guesssing your using 2k or something else setforegroundwindow
would be working.
its not small but is nessesary ,it came form the borland newsgroups with parts from different sources.
http://groups.google.com/groups?q=forceforegroundwindow+delphi+ray&hl=en&selm=3A62F81B.7790A088%40ia.comweb.nl&rnum=1
so you can call
ForceForeground(handle);
function ForceForeground(AppHandle:
const
SPI_GETFOREGROUNDLOCKTIMEO
SPI_SETFOREGROUNDLOCKTIMEO
var
ForegroundThreadID: DWORD;
ThisThreadID : DWORD;
timeout : DWORD;
OSVersionInfo : TOSVersionInfo;
Win32Platform : Integer;
begin
if IsIconic(AppHandle) then ShowWindow(AppHandle, SW_RESTORE);
if (GetForegroundWindow = AppHandle) then Result := true else
begin
Win32Platform := 0;
OSVersionInfo.dwOSVersionI
if GetVersionEx(OSVersionInfo
{ Windows 98/2000 doesn't want to foreground a window when some other window has keyboard focus}
if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (OSVersionInfo.dwMajorVers
((Win32Platform = VER_PLATFORM_WIN32_WINDOWS
((OSVersionInfo.dwMajorVer
begin
Result := false;
ForegroundThreadID := GetWindowThreadProcessID(G
ThisThreadID := GetWindowThreadPRocessId(A
if AttachThreadInput(ThisThre
begin
BringWindowToTop(AppHandle
SetForegroundWindow(AppHan
AttachThreadInput(ThisThre
Result := (GetForegroundWindow = AppHandle);
end;
if not Result then
begin
SystemParametersInfo(SPI_G
SystemParametersInfo(SPI_S
BringWindowToTop(AppHandle
SetForegroundWindow(AppHan
SystemParametersInfo(SPI_S
Result := (GetForegroundWindow = AppHandle);
if not Result then
begin
ShowWindow(AppHandle,SW_HI
ShowWindow(AppHandle,SW_SH
ShowWindow(AppHandle,SW_SH
BringWindowToTop(AppHandle
SetForegroundWindow(AppHan
end;
end;
end else
begin
BringWindowToTop(AppHandle
SetForegroundWindow(AppHan
end;
Result := (GetForegroundWindow = AppHandle);
end;
end;
see here for details of a new win2k api allowsetforegroundwindow:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_5fw7.asp
<end paste>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Having a look at it, thank you!
ASKER
Freshman3k's solution works with very little code, so I gave him the points. But thanks for all comments!