Example 1
{...}type
  TForm1 = class(TForm)
    Button1: TButton;
    ListView1: TListView;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    { 05/31/99 - added TListView.OnDblClick event }
    procedure ListView1DblClick(Sender: TObject);
  private
    { Private declarations }  
    { 05/31/99 - moved here for4m TButton.OnClick
                 event as an array so we can use
                 the array to get the TDevMode for
                 the selected one from the TListView }
    DevMode : array[0..20] of TDevMode;
  public
    { Public declarations } 
  end; {...}procedure TForm1.FormCreate(Sender: TObject);
begin
  { set viewstyle to vsReport }
  ListView1.ViewStyle := vsReport;  { set rowselect to TRUE }
  ListView1.RowSelect := TRUE;  {add our columns ans set their values }
  ListView1.Columns.Add;
  ListView1.Columns.Add;
  ListView1.Columns[0].Caption := 'Width x Height';
  ListView1.Columns[0].Width   := 100;
  ListView1.Columns[1].Caption := 'Colors';
  ListView1.Columns[1].Width   := 100;
end;procedure TForm1.Button1Click(Sender: TObject);
var
  { moved to be a private array so we can use
    the array to get the TDevMode for the
    selected one from the TListView }
  { DevMode    : TDevMode; }
  tmpStr1,
  tmpStr2    : String;
  tmpDC      : HDC;
  x,
  Selection,
  cxScreen,
  cyScreen,
  Resolution : Integer;
begin
  { get our color mode }
  tmpDC := getDC(Handle);
  try
    cxScreen   := GetSystemMetrics(SM_CXSCREEN);
    cyScreen   := GetSystemMetrics(SM_CYSCREEN);
    Resolution := GetDeviceCaps(tmpDC, BITSPIXEL);
  finally
    ReleaseDC(Handle, tmpDC);
  end;  ListView1.Items.Clear;
  x := 0;  { 05/31/99 - changed DevMode to an array to
               hold all the TDevMode values to be
               easily selected on a TListView
               OnDblClick event }
  { enumerate all possible display settings }
  while EnumDisplaySettings(nil,x,DevMode[x]) do
  begin    { screen width and height }
    tmpStr1 := IntToStr(DevMode[x].dmPelsWidth)+
               'x'+
               IntToStr(DevMode[x].dmPelsHeight);    { colors }
    case DevMode[x].dmBitsPerPel of
      4  : tmpStr2 := '16 Colors';
      8  : tmpStr2 := '256 Colors';
      16 : tmpStr2 := 'High Color (16 Bit)';
      32 : tmpStr2 := 'True Color (32 Bit)';
    end;    { add resolution to out tlistbox }
    with ListView1.Items.Add do
    begin
      Caption := tmpStr1;
      SubItems.Add(tmpStr2);
    end;    { compare our settings to the one being added
      and set a variable to be used to visually
      set out display settings in our tlistview }
    if ( cxScreen   = DevMode[x].dmPelsWidth  ) and
       ( cyScreen   = DevMode[x].dmPelsHeight ) and
       ( Resolution = DevMode[x].dmBitsPerPel ) then
      Selection := x;    { inc to the next display setting in the array }
    inc(x);    { 05/31/99 - make sure we do not over
                run our array }
    if x = 20 then
      Break;
  end;  { set our tlistview to select our current setting
    according the the compare done within the above
    loop }
  ActiveControl      := ListView1;
  ListView1.Selected := ListView1.Items.Item[Selection];
end;{ 05/31/99 }
procedure TForm1.ListView1DblClick(Sender: TObject);
var
  tmpDevMode : TDevMode;
begin
  { get our selected TDevMode structure }
  tmpDevMode := DevMode[ListView1.Items.IndexOf(ListView1.Selected)];  { tell windows what seetings in the TDevMode structure to us, we
    do this by setting the TDevMode.dmFields flag }
  tmpDevMode.dmFields := DM_BITSPERPEL or
                         DM_PELSWIDTH or
                         DM_PELSHEIGHT or
                         DM_DISPLAYFLAGS or
                         DM_DISPLAYFREQUENCY;  { use the CDS_TEST flag first to test that the selected display
    setting will work properly, then actually set the new dusplay
    settings }
  if ChangeDisplaySettings(tmpDevMode,
                           CDS_TEST) = DISP_CHANGE_SUCCESSFUL then
    ChangeDisplaySettings(tmpDevMode,
                          CDS_UPDATEREGISTRY);
end;{...}