English 中文(简体)
How to check visible resolution of system
原标题:

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

最佳回答

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.

问题回答

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.





相关问题
Is CLSID in registry for windows operating system is constant

I am developing a windows mobile application where i need to get a registry value of notification settings ,that is stored with CLSID as a key .Can i depend on the CLSID for retrieving the value of a ...

登记许可问题

vs2008, c. First time myhons# , it needs to establish a LM LMSoftware. 湿租赁

Reading registry values with cmake

On a Windows 7 machine I cannot read any registry values that contain a semicolon. For example if you have 7-zip, running the following SET(MYPATH [HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip;Path]) ...

How to check visible resolution of system

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

How to read and write to registry using VB.NET

How do I read, write and delete a registry using VB 2005/2008? Please give your explanation to your answer. I am really a registry noob... Thanks. I can t read any programming language other than vb.

Installing a Windows Service as a user

I m currently in the process of creating a Windows service application which will monitor changes to certain keys made in the HKEY_USERS registry. The way I do this is by collecting the SID of the ...

热门标签