LoginSignup
1
2

More than 1 year has passed since last update.

マルチディスプレイの表示方法を変更する

Posted at

やりたいこと

サブモニタの電源を入れたり切ったりしたい。
接続されているモニタをすべて入れたり切ったりすることはできたけど
片方だけを入れたり切ったりすることができなかった。

解決方法

マルチディスプレイの表示方法で「1のみに表示する」と設定することでサブモニタを真っ暗にすることができた。やりたかったことは叶ったのでこれで。

コーディング

C#
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern UInt32 SetDisplayConfig(
    UInt32 numPathArrayElements, 
    IntPtr pathArray, 
    UInt32 numModeInfoArrayElements, 
    IntPtr modeInfoArray, 
    UInt32 flags
);

/// <summary>
/// サブモニタを非表示にする。
/// </summary>
public void SetDisplayModeToInternal()
{
    SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, 0x00000001 | 0x00000080);
}

/// <summary>
/// サブモニタにメインモニタと同じ内容を表示する。
/// </summary>
public void SetDisplayModeToClone()
{
    SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, 0x00000002 | 0x00000080);
}

引数はこの辺り参考に
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setdisplayconfig

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2