2

So I have tried searching for the better part of a day for the answer to a simple question. I want my C# application to popup another winform on a timer and then close it after a delay. Simple enough, done and done. Now my issue is that I want it to actually be on top of other applications UNLESS they are full screen. By that I mean a true full screen application such as a game. I do not want to interfere with such an application since it should take priority over my application.

The issue is that I am using the 'OnTop' property on the popup form and, while it works perfectly for any other applications I have been testing it while playing a full screen game and the form, when it "Show()"s, takes the full screen application and drops it into windowed mode.

Is this the intended effect of the 'OnTop' property with full screen applications? If so is there a way that I can have my form popup on top of normal windowed windows and not interfere with full screen applications?

Any links, example, a kick in the general direction is great. The only hits that I come up with when searching for winforms involving full screen is people trying to get their application into full screen or having their application take focus away from another application.

Thanks on advance.

(I didn't post any code due to it just being a simple winform that is "formX:Show()" on a timer with the "onTop" property set)


(EDIT) So thanks to awilson53 for putting me on the right track I was able to find a method (albeit somewhat picky) to determine if an application is full screen. Seems kinda simple, and an "well duh", answer after all is said and done.

95% of the credit goes to the author of the article: http://www.richard-banks.org/2007/09/how-to-detect-if-another-application-is.html

~5% goes to awilson53 for getting me on the right track. :)

7
  • I don't know any easy way out here. But maybe there are ways to iterate through all open applications and check their window state. And after that determine a kind of "Z-level" for you r pop-up. Feb 3, 2012 at 20:37
  • Showing the window without stealing focus may help. stackoverflow.com/questions/156046/…
    – Josh
    Feb 3, 2012 at 20:49
  • Windows doesn't allow a form to be "most" OnTop. What if another program had the same type of setting?
    – LarsTech
    Feb 3, 2012 at 20:54
  • @Josh Tried the suggestions from that question from an earlier search with no joy. The winform does not steal focus but it still pops the full screen application into windowed mode.
    – teek5449
    Feb 3, 2012 at 22:03
  • @LarsTech I was under the 'false'(?) impression that full screen applications took priority over windowed applications. There must be a way since I have come out of full screen applications to find a form staring at me waiting for my input.
    – teek5449
    Feb 3, 2012 at 22:06

1 Answer 1

4

Check out this wrapper for the EnumWindows function. This will allow you to enumerate all open windows and determine their window state. You will want to check the EnumWindowItem.Maximized property, and if it is true set your OnTop property to false. If none of the EnumWindowItem's return Maximised you can set OnTop to true.

3
  • And then, if you like, if there is in fact a full-screen window, you can set your popup-window to be the top one in z-order below the full-screen one using the SetWindowPos API function. Feb 4, 2012 at 1:22
  • Thanks for the idea. I implemented the class with success and it returns whether or not a window is maximized. What I needed was to determine if an application is full screen and not just a maximized window. This did however get me on the right track since I do not believe that there is any other way other than using a dll import. See my original post for the answer that I found due to you putting me on the right thought track. Thanks!
    – teek5449
    Feb 4, 2012 at 1:30
  • I was typing in a rush and missed the distinction you made between full screen vs. maximized, but glad I was still able to help in spite of myself!
    – A. Wilson
    Feb 6, 2012 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.