Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetForegroundWindow API in WinXP

Status
Not open for further replies.

steve3739

Programmer
Jul 5, 2002
32
US
I used the following code to bring a VFP 5.0 app (a network messaging program) to the foreground whenever a user received a message:

&& setup code:
declare integer FindWindow in Win32api string,string
declare SetForegroundWindow in Win32api integer
_screen.caption = "Test Window"
nWinHandle=FindWindow(null,"Test Window")

x=inkey(5) && for this demo only, pause to move some other windows to top

&& to bring app to the foreground:
SetForegroundWindow(nWinHandle)

This worked fine under Windows 95, bringing the app to the foreground. But under Windows XP, the title just flashes in the taskbar. Is there a way to make the VFP application the foreground/active app in Windows XP?

Thanks for any help with this.
 
steve3739

I have a felling you may have to use an additional API call to force to application on top.

DECLARE Long BringWindowToTop in Win32API Long


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thank you for the reply, Mike. I tried your suggestion, but it does not work either.

In searching Microsoft's knowledgebase, it looks like letting an application bring itself to the foreground is not allowed in most cases under XP.

Steve3739
 
I think the rule in Windows 2000/XP is that an application can't bring itself to the top, but another application can do it. I've found that a windows scripting object can sometimes get the job done.

The WScript.shell object has an AppActivate() method that works. It takes a window caption instead of the window handle as a parameter though. That might not work if you have multiple windows open with the same caption. Also, it won't bring the window forward if it is minimized. You'd have to use the API to determine the window state and change it first.

Here's a sample call:

loShell = CREATEOBJECT("wscript.shell")
loShell.AppActivate(&quot;<window caption>&quot;)
 
Try the SetActiveWindow API.

Example:
DECLARE INTEGER SetActiveWindow IN user32 INTEGER

SetActiveWindow(nWinHandle)

The SetForegroundWindow behaves differently in NT,2K and XP then in 9X. Check out the MSDN for both of these functions and it might clear it up for you.

Dave L.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top