프리젠테이션 등을 하다보면 화면을 확장하는 것보다 복제하는 것이 편하거나 반대인 경우가 많습니다. 이에 단축키로 이것을 스왑하는 기능을 만들어 보고자 관련 win32 API를 찾아보았습니다. API는 찾은 후 프로그램의 단축키로 지정하자 프리젠테이션용이니까 Windows+Shift+P 정도의 단축키를 써야지 했는데 결론적으로는 해당 기능은 윈도우에서 지원하고 있었습니다. 게다가 단축키도 제 생각과 동일하게 Windows+Shift+P 였습니다.;;
프로그램을 만들 필요는 없어졌지만 win32 API를 이용하여 모니터 디스플레이 확장/복제를 설정하는 방법을 찾아놓은 것을 기록삼아 이곳에 남겨둡니다. win32 API중 SetDisplayConfig 함수를 사용하면 됩니다. 함수에 대한 Microsoft의 설명은 다음과 같습니다.
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setdisplayconfig
SetDisplayConfig function (winuser.h) - Win32 apps
The SetDisplayConfig function modifies the display topology, source, and target modes by exclusively enabling the specified paths in the current session.
learn.microsoft.com
사실 win32 API로 지원되었기에 함수 하나로 가능했고 설명을 해드릴게 별로 없을 정도로 간단한 기능이였습니다. 다음은 SetDisplayConfig 를 사용하기 위해 Win32 API를 포장하여 만들어 본 클래스입니다.
namespace Library
{
internal class Monitor
{
[Flags]
public enum SetDisplayConfigFlags : uint
{
SDC_TOPOLOGY_INTERNAL = 0x00000001,
SDC_TOPOLOGY_CLONE = 0x00000002,
SDC_TOPOLOGY_EXTEND = 0x00000004,
SDC_TOPOLOGY_EXTERNAL = 0x00000008,
SDC_APPLY = 0x00000080
}
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern long SetDisplayConfig(
uint numPathArrayElements,
IntPtr pathArray,
uint numModeArrayElements,
IntPtr modeArray,
SetDisplayConfigFlags flags);
private static void ApplyDisplayFlag(SetDisplayConfigFlags flag)
{
SetDisplayConfig(
0,
IntPtr.Zero,
0,
IntPtr.Zero,
flag | SetDisplayConfigFlags.SDC_APPLY);
}
public static void CloneDisplays()
{
ApplyDisplayFlag(SetDisplayConfigFlags.SDC_TOPOLOGY_CLONE);
}
public static void ExtendDisplays()
{
ApplyDisplayFlag(SetDisplayConfigFlags.SDC_TOPOLOGY_EXTEND);
}
}
}
위의 함수들의 설명 드리자면 다음과 같습니다.
함수명 | 설명 |
Library.Monitor.CloneDisplays() | 디스플레이 복제 설정으로 바꿉니다. |
Library.Monitor.ExtendDisplays() | 디스플레이 확장 설정으로 바꿉니다. |
'C#' 카테고리의 다른 글
[C# / WinUI3] User Control에서 Property 및 Event 추가 (0) | 2023.08.28 |
---|---|
[C#.NET] C# 에서 C++ Windows Runtime Component 사용하기 (0) | 2022.12.02 |
[C#.NET] Laptop Battery 정보 얻기 (Power Status) (0) | 2022.09.26 |
[C# .NET] COM 통신 (4) | 2022.09.21 |