|
■No78118 (Azulean さん) に返信
> ■No78114 (NOVO さん) に返信
>>VBでは出来ないんでしょうか・・・
VBは門外漢なので、C#になります。
VisualStudio 2013, .NET Framework 4.5.2環境で作成、動作確認はしていません。
using System;
using System.Runtime.InteropServices;
namespace AR
{
public class AutoRotation
{
[Flags]
public enum AR_STATE : int
{
AR_ENABLED = 0x0,
AR_DISABLED = 0x1,
AR_SUPPRESSED = 0x2,
AR_REMOTESESSION = 0x4,
AR_MULTIMON = 0x8,
AR_NOSENSOR = 0x10,
AR_NOT_SUPPORTED = 0x20,
AR_DOCKED = 0x40,
AR_LAPTOP = 0x80
};
public enum ORIENTATION_PREFERENCE : int
{
ORIENTATION_PREFERENCE_NONE = 0x0,
ORIENTATION_PREFERENCE_LANDSCAPE = 0x1,
ORIENTATION_PREFERENCE_PORTRAIT = 0x2,
ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4,
ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8
};
public static bool IsRotateEnabled()
{
AR_STATE autoRotationState = 0;
bool success = GetAutoRotationState(out autoRotationState);
if (!success)
{
return false; // disable
}
return autoRotationState.HasFlag(AR_STATE.AR_ENABLED);
}
public static ORIENTATION_PREFERENCE GetRotation()
{
ORIENTATION_PREFERENCE orientation;
bool success = GetDisplayAutoRotationPreferences(out orientation);
if (!success)
{
return ORIENTATION_PREFERENCE.ORIENTATION_PREFERENCE_NONE;
}
return orientation;
}
public static bool SetRotation(ORIENTATION_PREFERENCE orientation)
{
return SetDisplayAutoRotationPreferences(orientation);
}
[DllImport("Kernel.dll")]
private static extern bool GetAutoRotationState(out AR_STATE pState);
[DllImport("Kernel.dll")]
private static extern bool GetDisplayAutoRotationPreferences(out ORIENTATION_PREFERENCE pOrientation);
[DllImport("Kernel.dll")]
private static extern bool SetDisplayAutoRotationPreferences(ORIENTATION_PREFERENCE orientation);
}
}
|