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. :)

teek5449
  • 51
  • 5
  • 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. – Youp Bernoulli Feb 03 '12 at 20:37
  • Showing the window without stealing focus may help. http://stackoverflow.com/questions/156046/show-a-form-without-stealing-focus – Josh Feb 03 '12 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 03 '12 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 03 '12 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 03 '12 at 22:06
  • I don't think there is anything special about [full screen applications](http://www.vesic.org/english/blog/winforms/full-screen-maximize/) that would give them a special priority. What if someone else had a full screen application, too? – LarsTech Feb 03 '12 at 22:11
  • My thought was that "full screen applications took priority over windowed applications" that's all nothing more nothing less. Not one app being more important than another app. :) So fullscreenApp_A would not receive priority over fullscreenApp_B but fullscreenApp_A would receive priority over windowedApp_A. Am I way off here? Usually I find that full screen applications will tend to maintain their full screen nature even if another windowed application is requesting focus. That is why I was confused why my winform was bringing an application out of full screen mode. – teek5449 Feb 04 '12 at 01:42

1 Answers1

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.

A. Wilson
  • 688
  • 1
  • 6
  • 15
  • 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. – 500 - Internal Server Error Feb 04 '12 at 01: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 04 '12 at 01: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 06 '12 at 13:55