Share via


DisplayMonitor.FromInterfaceIdAsync(String) Method

Definition

Asynchronously creates a DisplayMonitor object for the specified monitor interface identifier (a string containing a PnP device interface path). See the code example below.

Note

If you call DeviceInformation.FindAllAsync, passing the Advanced Query Syntax (AQS) device interface selector string returned by DisplayMonitor.GetDeviceSelector, then you will retrieve a collection of DeviceInformation objects that describe monitor interfaces (rather than monitor devices). Accessing the DeviceInformation.Id property on one of those objects retrieves a monitor interface identifier, which you can pass to DisplayMonitor.FromInterfaceIdAsync. See the code example below.

Most Win32 APIs that provide a monitor identifier actually provide the monitor interface identifier (and not the device identifier).

public:
 static IAsyncOperation<DisplayMonitor ^> ^ FromInterfaceIdAsync(Platform::String ^ deviceInterfaceId);
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<DisplayMonitor> FromInterfaceIdAsync(winrt::hstring const& deviceInterfaceId);
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<DisplayMonitor> FromInterfaceIdAsync(string deviceInterfaceId);
function fromInterfaceIdAsync(deviceInterfaceId)
Public Shared Function FromInterfaceIdAsync (deviceInterfaceId As String) As IAsyncOperation(Of DisplayMonitor)

Parameters

deviceInterfaceId
String

Platform::String

winrt::hstring

The monitor interface identifier

Returns

An asynchronous create operation.

Attributes

Examples

using namespace winrt;
using namespace Windows::Devices::Display;
using namespace Windows::Devices::Enumeration;
using namespace Windows::Foundation;

IAsyncAction EnumerateDisplayMonitorsAsync()
{
    auto const dis{ co_await DeviceInformation::FindAllAsync(DisplayMonitor::GetDeviceSelector()) };

    for (auto const& deviceInformation : dis)
    {
        WINRT_ASSERT(deviceInformation.Kind() == DeviceInformationKind::DeviceInterface);
        DisplayMonitor displayMonitor{ co_await DisplayMonitor::FromInterfaceIdAsync(deviceInformation.Id()) };
    }
}

Applies to