How do I set the monitor orientation in Windows 7?

老子叫甜甜 提交于 2019-11-28 00:07:37

I have started something.

Please have a look: MultiMonitorHelper

It includes necessary structures for Win7, so that you could call SetDisplayConfig and other functions.

An actual example, how to rotate monitor 90 degrees:

        int numPathArrayElements;
        int numModeInfoArrayElements;

        const QueryDisplayFlags pathType = QueryDisplayFlags.OnlyActivePaths;

        // query active paths from the current computer.
        // note that 0 is equal to SUCCESS!
        // TODO; HARDCODE MAGIC VALUES AWAY.
        if (CCDWrapper.GetDisplayConfigBufferSizes(pathType, out numPathArrayElements,
                                                   out numModeInfoArrayElements) == 0)
        {
            var pathInfoArray = new DisplayConfigPathInfo[numPathArrayElements];
            var modeInfoArray = new DisplayConfigModeInfo[numModeInfoArrayElements];

            // TODO; FALLBACK MECHANISM THAT HANDLES DIFFERENT VALUES FOR ZERO.
            if (CCDWrapper.QueryDisplayConfig(
                pathType,
                ref numPathArrayElements, pathInfoArray,
                ref numModeInfoArrayElements,
                modeInfoArray, IntPtr.Zero) == 0)
            {

                pathInfoArray[0].targetInfo.rotation = DisplayConfigRotation.Rotate90;
                CCDWrapper.SetDisplayConfig((uint) numPathArrayElements, pathInfoArray, (uint) numModeInfoArrayElements,
                                            modeInfoArray, SdcFlags.Apply | SdcFlags.UseSuppliedDisplayConfig);
            }
         }

it's raw right now, meaning there is no "C# style" API right now, but none the less, you can use those structures.

On Windows 7, ChangeDisplaySetting has a known compatibility issue. The workaround is to call the WDK function: SetDisplayConfig.

http://social.msdn.microsoft.com/Forums/en/windowsuidevelopment/thread/5bc2396d-1e0e-44fb-b73b-95f8dfc45684

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!