How to determine if a Windows application is off-screen?

I am trying to debug a strange problem with users who have LogMeIn installed . After a few days, some of my dialogs opened by my application may end off-screen. If I could reliably detect this, I could programmatically move the dialogs back to where they are visible again.

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

Update: For the curious, the bug mentioned above is related to wxWidgets. If you run the wxWidgets application, leave and launch the screen saver, then log in remotely using LogMeIn, then try to open a dialog box from your application, you will have problems if you use wxDisplay :: GetFromPoint (pos) or wxWindowBase :: Center () to put a dialog.

+5
source share
8 answers

Just use MonitorFromWindow with the MONITOR_DEFAULTTONULL flag. If the return value is null, your window is not displayed. You can then pass MONITOR_DEFAULTTONEAREST to reposition your window on the nearest monitor.

+8

.NET Screen.PrimaryScreen.WorkingArea, (Screen.Screens [x].WorkingArea , ), Left Top , , ( , , [].Width .Height.

+1

.NET Screen.AllScreen, screen.Bounds.Contains(), , , (*), call screen.Bounds.IntersectsWith(), , .

(*) , . Rectangle.Union , , , , , .

. : .

+1

, , , (0,0) . , , , .

+1

. ?

, , , , . .

if (!Screen.FromControl(this).Bounds.Contains(this.Location))
            {
                this.DesktopLocation = new Point(100,100);
            }
+1

It seems GetMonitorInfo () is the equivalent of Win32 from Danny. I'm not sure how you are going to get HMONITOR for all the monitors in the system, but it looks like the documentation example example has some ways to do this.

0
source

Hm. This may not help, but when I did VB, you could do screen.width and screen.height, and then window.x and window.y ...

Of course, I do not know how this works with multiple monitors.

-1
source

All Articles