How to determine whether a Windows application is offscreen?

By : kgriffs
Source: Stackoverflow.com
Question!

I am trying to debug a strange issue with users that have LogMeIn installed. After a few days, some of my dialogs that my app opens can end up offscreen. If I could reliable detect that, I could programmatically move the dialogs back where they are visible again.

Note: this has to work for multiple monitors and use the win32 API. However, if you know how to do it from .NET I can probably extrapolate from there...

Update: For the curious, the bug mentioned above has to do with wxWidgets. If you run a wxWidgets application, then walk away and let your screen saver go, then log in remotely with LogMeIn, then try to open a dialog from your app, you will have trouble if you use wxDisplay::GetFromPoint(pos) or wxWindowBase::Center() to position the dialog.

By : kgriffs


Answers

See also How can I get the active screen dimensions?

This is the code I used in the form constructor it's a quickie to move the form to a visible screen after you undock your laptop or whatever it is you did to make some screen real estate go away. Refine for your own consumption.

if (!Screen.FromControl(this).Bounds.Contains(this.Location))
            {
                this.DesktopLocation = new Point(100,100);
            }
By : CAD bloke


Whatever you do, please account for multiple monitors which may have coordinates thousands of pixels away from (0,0) in any direction. I hate it when an app forces itself back into another screen, frequently messing up any full-screen games I may be in at the time.

By : tsilb


This is what I've been using for development:

<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>

This is a very liberal approach, but is fine for my application.

As others have pointed out below, beware the risks of this.



This video can help you solving your question :)
By: admin