DelphiFAQ Home Search:

Delphi Command line tool to change Screen Resolution

 

comments1 comments. Current rating: 2 stars (1 votes). Leave comments and/ or rate it.

The following little commandline tool, written in Delphi, demonstrates how to retrieve all available screen resolutions (width, height, number of colors and display frequency), and how to modify the current setting.

If you run the executable in a DOS box, it will write all possible settings to standard output.
If you provide a set of settings e.g. 800 600 256 85, then it will switch to this (provided, that your drivers allow the setting).

{$APPTYPE CONSOLE}
// commandline use:      DisplayMode 800 600 256 85
// no arguments: it will list all modi.
program DisplayMode;

uses
  SysUtils, Messages, Windows;

{$R *.RES}

var
  i: Integer;
  DevMode: TDevMode;

begin
  i := 0;
  if ParamCount=0 then
  begin
    while EnumDisplaySettings(nil, i, DevMode) do
    begin
      with DevMode do
        Writeln(Format('%dx%d %d Colors, %d Hz', [dmPelsWidth, dmPelsHeight,
                       Int64(1) shl dmBitsperPel, dmDisplayFrequency]));
      inc(i);
    end;
    Writeln('-----');
    Writeln('Usage:   DisplayMode    ');
    Writeln('Example: DisplayMode 800 600 65536 85');
  end
  else
  begin
    while EnumDisplaySettings(nil, i, DevMode) do
    begin
      with DevMode do
      begin
        if (paramstr(1)=IntToStr(dmPelsWidth)) and
           (paramstr(2)=IntToStr(dmPelsHeight)) and
           (paramstr(3)=IntToStr(Int64(1) shl dmBitsperPel)) and
           (paramstr(4)=IntToStr(dmDisplayFrequency)) then
        begin
          ChangeDisplaySettings(DevMode, CDS_UPDATEREGISTRY);
          SendMessage(HWND_BROADCAST, WM_DISPLAYCHANGE, SPI_SETNONCLIENTMETRICS, 0);
          break;
        end;
      end;
      inc(i);
    end
  end;
end.

Comments:

2007-04-30, 06:58:26   (updated: 2007-04-30, 06:59:13)
[hidden] from Tehran in Tehran, Iran  
rating
I not found response your qustions about use ParamCount and paramstr in delphi
thanks.

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.