Share via


DisplayMonitor.FromIdAsync(String) Method

Definition

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

Note

The argument must be a device identifier, and not a device interface identifier. If you have a device interface identifier (which is likely), then call FromInterfaceIdAsync instead. For more details, see DeviceInformation.Id.

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

Parameters

deviceId
String

Platform::String

winrt::hstring

The monitor device identifier. See DeviceInformation.Id.

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 EnumerateDisplayMonitorsUsingAdditionalPropertiesAsync()
{
    winrt::hstring propertyName = L"System.Devices.DeviceInstanceId";
    auto const dis{ co_await DeviceInformation::FindAllAsync(DisplayMonitor::GetDeviceSelector(), { propertyName }) };

    for (auto const& deviceInformation : dis)
    {
        WINRT_ASSERT(deviceInformation.Kind() == DeviceInformationKind::DeviceInterface);
        DisplayMonitor displayMonitor{ co_await DisplayMonitor::FromIdAsync(winrt::unbox_value<winrt::hstring>(deviceInformation.Properties().Lookup(propertyName))) };
    }
}

Applies to