Board index » delphi » Help on changing screen size

Help on changing screen size

Can anyone please tell me how to go about changing a users screen
resolution under windows 95 using delphi 2, I have managed to work out how
to find out what the user has got his/her screen set to, but I need to know
how to change it without the user having to do it them selves.

Any help would be very much appreciated both on here and via email to
idmcc...@globalnet.co.uk

Thanks Ian...

 

Re:Help on changing screen size


Quote
Ian D McCabe wrote:

> Can anyone please tell me how to go about changing a users screen
> resolution under windows 95 using delphi 2, I have managed to work out how
> to find out what the user has got his/her screen set to, but I need to know
> how to change it without the user having to do it them selves.

> Any help would be very much appreciated both on here and via email to
> idmcc...@globalnet.co.uk

> Thanks Ian...

You can use the Windows API function EnumDisplaySettings() to get a list
of
valid mode settings, and use the Windows API function
ChangeDisplaySettings()
to actually change the display setting. Note that many drivers will not
preform the
reset without rebooting the computer, even though they are capable of
doing so.

Example:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls, Spin;

type
  PdmArray = ^TDmArray;
  TDmArray = array[0..0] of TDeviceMode;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    SpinEdit1: TSpinEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    lpDmArray : PDmArray;
    NumModes : integer;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  i : integer;
  MoreModes : bool;
  dm : TDeviceMode;
begin
  Memo1.Lines.Clear;
  MoreModes := True;
  i := 0;
  while MoreModes <> false do begin
    MoreModes :=
      EnumDisplaySettings(nil,
                          i,
                          dm);
    Memo1.Lines.Add('Mode ' +
      IntToStr(i) + ': ' +
      IntToStr(dm.dmBitsPerPel) + ' Bits Per Pixel ' +
      IntToStr(dm.dmPelsWidth) + ' x ' +
      IntToStr(dm.dmPelsHeight));
    Inc(i);
  end;
  NumModes := i;
  SpinEdit1.MinValue := 0;
  SpinEdit1.MaxValue := NumModes;
  GetMem(lpDmArray, sizeof(TDeviceMode) * NumModes);
  FillChar(lpDmArray^, sizeof(TDeviceMode) * NumModes, #0);
{$IFOPT R+}
  {$DEFINE CKRANGE}
  {$R-}
{$ENDIF}
  for i := 0 to (NumModes - 1) do
    EnumDisplaySettings(nil,
                        i,
                        lpDmArray^[i]);
{$IFDEF CKRANGE}
  {$UNDEF CKRANGE}
  {$R+}
{$ENDIF}
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ReturnVal : LongInt;
begin
{$IFOPT R+}
  {$DEFINE CKRANGE}
  {$R-}
{$ENDIF}
  ReturnVal := ChangeDisplaySettings(lpDmArray^[SpinEdit1.Value],
                                     CDS_UPDATEREGISTRY);
{$IFDEF CKRANGE}
  {$UNDEF CKRANGE}
  {$R+}
{$ENDIF}
  case ReturnVal of
    DISP_CHANGE_SUCCESSFUL : Memo1.Lines.Add('DISP_CHANGE_SUCCESSFUL');
    DISP_CHANGE_RESTART : Memo1.Lines.Add('DISP_CHANGE_RESTART');
    DISP_CHANGE_BADFLAGS : Memo1.Lines.Add('DISP_CHANGE_BADFLAGS');
    DISP_CHANGE_FAILED : Memo1.Lines.Add('DISP_CHANGE_FAILED');
    DISP_CHANGE_BADMODE : Memo1.Lines.Add('DISP_CHANGE_BADMODE');
    DISP_CHANGE_NOTUPDATED : Memo1.Lines.Add('DISP_CHANGE_NOTUPDATED');
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeMem(lpDmArray, sizeof(TDeviceMode) * NumModes);
end;

end.

Joe
--
Joe C. Hecht
joehe...@gte.net
http://home1.gte.net/joehecht/index.htm

Re:Help on changing screen size


Use the attached unit as starting point. It determines all video modes that
DON'T need a reboot and can dynamically be set (any resolution, any color
depth).

Ciao, Mike

Ian D McCabe <idmcc...@globalnet.co.uk> schrieb im Beitrag
<01bca934$bb4e5dc0$3d5f7ec2@ianmccab>...

Quote
> Can anyone please tell me how to go about changing a users screen
> resolution under windows 95 using delphi 2, I have managed to work out
how
> to find out what the user has got his/her screen set to, but I need to
know
> how to change it without the user having to do it them selves.

> Any help would be very much appreciated both on here and via email to
> idmcc...@globalnet.co.uk

> Thanks Ian...

begin 600 Screen.zip
<encoded_portion_removed>
end

Re:Help on changing screen size


Thanks for the help Mike, will have a go at the zip you sent me in a few
ins...

Ian...

Mike Lischke <Lisc...@imib.med.tu-dresden.de> wrote in article
<01bca94e$cc945e30$cd8e4c8d@plato>...

Quote
> Use the attached unit as starting point. It determines all video modes
that
> DON'T need a reboot and can dynamically be set (any resolution, any color
> depth).

> Ciao, Mike

> Ian D McCabe <idmcc...@globalnet.co.uk> schrieb im Beitrag
> <01bca934$bb4e5dc0$3d5f7ec2@ianmccab>...
> > Can anyone please tell me how to go about changing a users screen
> > resolution under windows 95 using delphi 2, I have managed to work out
> how
> > to find out what the user has got his/her screen set to, but I need to
> know
> > how to change it without the user having to do it them selves.

> > Any help would be very much appreciated both on here and via email to
> > idmcc...@globalnet.co.uk

> > Thanks Ian...

Other Threads