C# 화면 회전(Screen Rotate)
DEVMODE dm = NativeMethods.CreateDevmode();GetSettings(ref dm); int temp = dm.dmPelsHeight; dm.dmPelsHeight = dm.dmPelsWidth; dm.dmPelsWidth = temp; int index = Array.IndexOf(orientationValues, (object)dm.dmDisplayOrientation); int newIndex = (index == 0) ? 3 : index - 1; dm.dmDisplayOrientation = orientationValues[newIndex]; ChangeSettings(dm); private void ChangeSettings(DEVMODE dm){ NativeMethods.ChangeDisplaySettings(ref dm, 0);} private int GetSettings(ref DEVMODE dm){ return GetSettings(ref dm, NativeMethods.ENUM_CURRENT_SETTINGS);} private int GetSettings(ref DEVMODE dm, int iModeNum){ return NativeMethods.EnumDisplaySettings(null, iModeNum, ref dm);}
NativeMethods 클래스 관련 부분:
//-------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // File: NativeMethods.cs // C# file for the DisplaySettingsSample application // //-------------------------------------------------------------------------- using System; using System.Runtime.InteropServices; namespace DisplaySettingsSample { [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)] public struct DEVMODE { [MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)] public string dmDeviceName; public short dmSpecVersion; public short dmDriverVersion; public short dmSize; public short dmDriverExtra; public int dmFields; public int dmPositionX; public int dmPositionY; public int dmDisplayOrientation; public int dmDisplayFixedOutput; public short dmColor; public short dmDuplex; public short dmYResolution; public short dmTTOption; public short dmCollate; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string dmFormName; public short dmLogPixels; public short dmBitsPerPel; public int dmPelsWidth; public int dmPelsHeight; public int dmDisplayFlags; public int dmDisplayFrequency; public int dmICMMethod; public int dmICMIntent; public int dmMediaType; public int dmDitherType; public int dmReserved1; public int dmReserved2; public int dmPanningWidth; public int dmPanningHeight; }; public class NativeMethods { // PInvoke declaration for EnumDisplaySettings Win32 API [DllImport("user32.dll", CharSet=CharSet.Ansi)] public static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode); // PInvoke declaration for ChangeDisplaySettings Win32 API [DllImport("user32.dll", CharSet=CharSet.Ansi)] public static extern int ChangeDisplaySettings(ref DEVMODE lpDevMode, int dwFlags); // helper for creating an initialized DEVMODE structure public static DEVMODE CreateDevmode() { DEVMODE dm = new DEVMODE(); dm.dmDeviceName = new String(new char[32]); dm.dmFormName = new String(new char[32]); dm.dmSize = (short)Marshal.SizeOf(dm); return dm; } // constants public const int ENUM_CURRENT_SETTINGS = -1; public const int DISP_CHANGE_SUCCESSFUL = 0; public const int DISP_CHANGE_BADDUALVIEW = -6; public const int DISP_CHANGE_BADFLAGS = -4; public const int DISP_CHANGE_BADMODE = -2; public const int DISP_CHANGE_BADPARAM = -5; public const int DISP_CHANGE_FAILED = -1; public const int DISP_CHANGE_NOTUPDATED = -3; public const int DISP_CHANGE_RESTART = 1; public const int DMDO_DEFAULT = 0; public const int DMDO_90 = 1; public const int DMDO_180 = 2; public const int DMDO_270 = 3; } }
'소스 관련' 카테고리의 다른 글
2013. 04. 20 사이트 자원 캐쳐 (0) | 2013.04.20 |
---|---|
ShowWindow를 통한 윈도우 숨기기 (0) | 2013.04.01 |
C# 크레이지 마우스(crazy mouse) (0) | 2013.03.24 |
C# 화면 흘러내림(Screen melt) (1) | 2013.03.24 |
2013-02-20 C# 마인크래프트 사이트 로그인 (3) | 2013.02.20 |