-api-id | -api-type |
---|---|
M:Windows.Devices.Display.DisplayMonitor.FromInterfaceIdAsync(System.String) |
winrt method |
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).
The monitor interface identifier
An asynchronous create operation.
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()) };
}
}