Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine whether a Windows application is offscreen?

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.

like image 954
kgriffs Avatar asked Oct 17 '08 18:10

kgriffs


People also ask

How do I find a window that is off screen?

The easiest way to get back a hidden window is to just right-click on the Taskbar and select one of the window arrangement settings, like “Cascade windows” or “Show windows stacked.”

How do I move a window that is partially off screen?

Hold down the Shift key, then right-click on the appropriate application icon in the Windows taskbar. On the resulting pop-up, select the Move option. Begin pressing the arrow keys on your keyboard to move the invisible window from off-screen to on-screen.

How do I find hidden files in Windows 11?

Open File Explorer from the taskbar. Select View > Show > Hidden items.

Do programs run when screen off?

If the script runs via Task Scheduler or like, it will run when the screen is off (computer ON, screen OFF).


1 Answers

Simply use MonitorFromWindow with the MONITOR_DEFAULTTONULL flag. If the return value is null, your window is not visible. You can subsequently pass MONITOR_DEFAULTTONEAREST to be able to reposition your window on the nearest monitor.

like image 166
Frederik Slijkerman Avatar answered Oct 14 '22 10:10

Frederik Slijkerman