Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I need to get notification when there is a change in the display settings (resolution, orientation, relative position and when a monitor is being connected/disconnected) of multiple monitors connected to my computers from within a Windows Service (can't listen to WM_DISPLAYCHANGE) . I can get a notification when there is a resolution change or change in number of connected monitors by registrying using WMI to changes in the monitor's WMI class, but I don't find a class that stores the orientation and relative position. Is there such a class?

In addition, if I could find a registry key which stores that data it will be a solution too (I can get a notification when the key changes using WMI). In particular I need a key which exists ib both Win7 and WinXP.

If there is another way to get this data from within a Windows service, I'll be happy to know it.

I will be thankfull for any help.
Posted
Updated 2-Dec-10 1:00am
v2

1 solution

To detect the orientation (or change in orientation) is the most easy part of the problem. There is no display resolution that has the same width and height, so the orientation changes if the vertical becomes the horizontal resolution an vice versa. It is also possible to say that the width is always greater than the height.

C#
#include <windows.h>
//. . .
//Compare the height and width of the screen and act accordingly.
int theScreenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
int theScreenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
if (theScreenWidth > theScreenHeight)
    //Run the application in landscape, as in:
    MessageBox(NULL,"Run in landscape.","Landscape",MB_OK);
else
    //Run the application in portrait, as in:
    MessageBox(NULL,"Run in portrait.","Portrait",MB_OK);


more info: http://msdn.microsoft.com/en-us/library/ms812142.aspx[^]

So if you can already detect the changing of the screen resolution you can also detect orientation changes.

Information about the screen position can be found using GetMonitorInfo. Because the rect of MONITORINFO.rcMonitor is virtual, some of the coordinates could be negative if it is not the primary monitor. This is of course the case when the second monitor is left of the primary monitor.

more info: http://msdn.microsoft.com/en-us/library/dd162826.aspx[^]

I also found some info on where to find this info in the registry:
System\CurrentControlSet\Control\Video\{GUID}\0000
System\CurrentControlSet\Control\Video\{GUID}\0001

System\Currentcontrolset\4D36E968-E325-11CE-BFC1-08002BE10318\0000
System\Currentcontrolset\4D36E968-E325-11CE-BFC1-08002BE10318\0001

Machine\hardware\devicemap\video


Good luck!
 
Share this answer
 
v3
Comments
knaf 5-Dec-10 3:06am    
Thanks for the answer. I thought that it's possible to detect orientation change by resoulution change too, but it doesn't work via WMI.
As for the registry keys, what OS do you have? in Win7 I don't have the desirable data in this keys.
E.F. Nijboer 6-Dec-10 4:06am    
These reg keys come from Vista Enterprise, so dhould be the same for Windows 7.
HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Video\{GUID}\0000

I forgot to mention the "Class" entry.
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{4D36E968-E325-11CE-BFC1-08002BE10318}\0000

HKEY_LOCAL_MACHINE\hardware\devicemap\video
knaf 7-Dec-10 7:08am    
Hi,

thanks again. did you check if these keys being updated if you make a change? because in my computer they don't..
E.F. Nijboer 7-Dec-10 7:48am    
I just tested it for you on Vista. I changed the resolution and gave a refresh in regedit. The changes were immediately updated when looking at the config data under the GUID that is the actual active configuration.
REGKEY: HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Video\{GUID}\0000

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900