简体   繁体   中英

Is there a way to guarantee that internet explorer will alway be the topmost window?

I'm trying to force an internet explorer window to be TOPMOST. No other windows should show on top of the internet explorer window. I have to use internet explorer. I'm also running this in Windows 7. Apparently that makes a difference but all the information I found on that is rather vague and basically consists of people shouting "why isn't this easier!". This is my code:

HWND ieWin = FindWindow(TEXT("IEFrame"), 0);
SetFocus(ieWin);
SetWindowPos(ieWin, HWND_TOPMOST, 0, 0, 100, 100, SWP_SHOWWINDOW );
UpdateWindow(GetParent(ieWin));

This is running in a loop so I can force the window to have these settings continuously but it's not helping. Sometimes the above code works and sometimes it doesn't.

After much discussion I did wind up forcing the window to stay on top using a loop. If anyone else really needs to do this in the future they really need to make sure they are following the steps below.

1) Ensure that they will have absolute control over the windows that their user can open. In my case The user will only be able to open my program and internet explorer.

2) The first time you set the IE window to show set it to the foreground.

3) While looping to set the window to TOP_MOST do NOT set the focus to the IE window.

4) Make sure you have SWP_SHOWWINDOW, SWP_NOSIZE, and SWP_NOMOVE. Otherwise that loop will change your window's size and place at every iteration.

And if you can avoid it at all possible, don't ever do this at all :P

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM