title: Read monitor name like MultiMonitor tool does
body: <p>I would like to know if there is a way in Delphi to read the <strong>monitor name</strong> as I see it in the <strong>MultiMonitorTool</strong> program:</p>
  <p><a href="https://i.stack.imgur.com/tl0Sq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tl0Sq.png" alt="image" /></a></p>
  <p>At the moment, I have tried to read it via the following methods:</p>
  <ul>
  <li><code>MonitorInfo.szDevice</code> (it returns <code>&quot;\\.\DISPLAY1&quot;</code>)</li>
  <li><code>monitorname(Screen.Monitors[i].MonitorNum)</code> (it returns <code>&quot;Generic-Non-PnP-Monitor&quot;</code>)</li>
  <li><code>Screen.Monitors[i].FriendlyName</code> (it returns <code>&quot;Generic-Non-PnP-Monitor&quot;</code>)</li>
  </ul>
  <pre class="lang-pascal prettyprint-override"><code>procedure TMonitorOrientationDemoForm.RefreshMonitorsList;
  var
    i: integer;
    li: TListItem;
    MonitorInfo: TMonitorInfoEx;
    LTmp: string;
  
    function ArrayToString(const a: array of Char): string;
    begin
      if Length(a) &gt; 0 then
        Result := StrPas(PChar(@a[0]))
      else
        Result := '';
    end;
  
  begin
    lvMonitors.Items.BeginUpdate;
    try
      lvMonitors.Items.Clear;
      for i := 0 to Screen.MonitorCount - 1 do
      begin
        li := lvMonitors.Items.Add;
        MonitorInfo.cbSize := SizeOf(MonitorInfo);
        if not GetMonitorInfo(Screen.Monitors[i].Handle, @MonitorInfo) then
          continue;
        LTmp := ArrayToString(MonitorInfo.szDevice);
        //Screen.Monitors[i].FriendlyName -&gt; returns the string &quot;Generic-Non-PnP-Monitor&quot;
        //MonitorInfo.szDevice -&gt; returns the string &quot;\\.\DISPLAY1&quot;
        //monitorname(Screen.Monitors[i].MonitorNum) -&gt; returns the string &quot;Generic-Non-PnP-Monitor&quot;
        LI.Caption := Screen.Monitors[i].FriendlyName;
        li.SubItems.Add(MonitorOrientationToString(Screen.Monitors[i].Orientation));
        if Screen.Monitors[i].SupportsRotation then
          li.SubItems.Add('Yes')
        else
          li.SubItems.Add('No');
      end;
    finally
      lvMonitors.Items.EndUpdate;
    end;
  end;
  
  function TMonitorOrientationDemoForm.monitorname(numberof: integer): string;
  Var
    Cntr: Cardinal;
    Info: TDisplayDevice;
    AdapterName: PChar;
    OldPos, j, i: integer;
    a: tstringlist;
  Begin
    a := tstringlist.create;
    Cntr := numberof;
    Info.cb := SizeOf(Info);
    While EnumDisplayDevices(Nil, Cntr, Info, 0) Do
    Begin
      AdapterName := StrAlloc(SizeOf(Info.DeviceName));
      StrCopy(AdapterName, Info.DeviceName);
      EnumDisplayDevices(AdapterName, 0, Info, 0);
      a.Add(Info.DeviceString);
      for i := 1 to a.count - 1 do
      begin
        a.Delete(i);
        Result := a.Strings[0];
        StrDispose(AdapterName);
        Inc(Cntr);
      End;
    End;
  End;
  
  </code></pre>