views:

59

answers:

2

I am not entirely sure how to word this questions so I am just going to explain my problem.

My VB 6 program saves the location of the screen in the registry so that when it loads up again it can have a default location. This works as expected, but I encountered a problem. I had a computer setup with 2 monitors. I dragged the window to the second screen, then the next day when I unplugged the second monitor. Every time I would load the program it would appear in the dock, but the form itself was not.

I figured it was hiding on the second monitor's space (or were the second monitor should be) Now at first I connected a second monitor to grab it back, but it did not show up. The monitor setup was such that the main monitor (1) was to the left of the new monitor (2). I had to drag (2) over to the left of (1) at which point it showed up, and I was able do drag it back to the main window and everything worked fine. I mention this because I figured each monitor number's resolution was relative to itself. Is the multimonitor one giant coordinate plane?

What I want to know is when I grab the location numbers from the registry (Form.left and Form.top) is there a way to check it against what is available to the system? This is not a huge issue, but I know I am going to get clients calling in eventually asking, "Its loading, but I cant find it!" and would like to avoid those calls if possible.

Thank you all

A: 

Not really an answer to your question, but it could help in dealing with similar problems in the future, or your customers if they bump into it.

If you right-click the taskbar button (or on Windows 7, right-click the Aero Peek preview of the window), you'll see a Move option. Click that, and then press one of your arrow keys, doesn't matter which. After that, the window will be in movable mode, and you can just move your mouse and voila, it is back on your screen and acting as if you were dragging the title bar.

Stigma
Ya, I was wondering exactly how that move option worked. I was trying to use it to drag the form. Didn't really work. Figured I was missing something.Thanks for the tip.
Ian Kremer
A: 

Don't know about VB, but you can call native Win32 APIs to deal with the problem.

GetSystemMetrics(SM_CMONITORS) returns the number of monitors, or you can enumerate them with EnumDisplayMonitors() if you need to distinguish between "real" monitors and pseudo-display monitors.

Use MonitorFromPoint() or MonitorFromRect() or MonitorFromWindow() to identify the monitor at a specified point, and then use GetMonitorInfo() to return information about that monitor, including its virtual-screen coordinates. You can then position the window on the monitor of your choice.

I don't know how to reliably detect whether the second monitor is missing or powered off. You could use the setup API (!) for this, I suspect -- SetupDiEnumDeviceInfo() can be used to enumerate the monitor devices and SetupDiGetDeviceRegistryProperty() can be used to retrieve information about each, like its current power state.

Rob Pelletier