Jason,

thanks for the effort.  From the help files, I knew I could do that.  
My fault for not specifying the requirement.  I wish my app to run in 
1024X768.  The current temporary solution is that it refuses to run if 
you are in say 800x600.  What I want to do is to change the 
settings to 1024x768 run the program and on exit, change the 
system backto what it was.

For this to work, 

1.  I need to know the exact mode number to restore to.
2.  I need to know the current mode number so that I can figure out 
things like font size and display frequency before flipping to 
1024x768... otherwise we could have sync problems.

And there is no GetDisplaysettings.  EnumDisplaySettings as you 
know gives you all the settings but I cant find anyway to know what 
the current setting is.  I can get a few of those fields from 
GetSystemMetrics, but not all.

To:                     Multiple recipients of list delphi <[EMAIL PROTECTED]>
Send reply to:          [EMAIL PROTECTED]
From:                   "Jason" <[EMAIL PROTECTED]>
Subject:                RE: [DUG]:  Screen Size
Date sent:              Mon, 12 Jun 2000 13:16:35 +1200

> Here it is anyway!
> 
> 
> //********************************************************************
> {Whoops! Delphi imports this function incorrectly, so we must manually
>  import it}
> function ChangeDisplaySettings(lpDevMode: PDeviceMode;
>                                dwFlags: DWORD): Longint; stdcall;
> var
>   Form1: TForm1;
>   DevModeArray: TList;    // holds a list of device mode information
> structures
> 
> implementation
> 
> uses Math;
> 
> {$R *.DFM}
> 
> {import the function}
> function ChangeDisplaySettings; external user32 name
> 'ChangeDisplaySettingsA';
> 
> procedure TForm1.FormCreate(Sender: TObject);
> var
>   DevModeCount: Integer;            // tracks the number of display modes
>   DevModeInfo: ^TDevMode;           // a pointer to display mode information
> begin
>   {create the list to hold display mode information structures}
>   DevModeArray := TList.Create;
> 
>   {initialize the counter}
>   DevModeCount := 0;
> 
>   {dynamically allocate memory to hold display mode information}
>   GetMem(DevModeInfo, SizeOf(TDevMode));
> 
>   {begin enumerating display modes}
>   while EnumDisplaySettings(NIL, DevModeCount, DevModeInfo^) do
>   begin
>     {add the information to the list}
>     DevModeArray.Add(DevModeInfo);
> 
>     {increment the counter}
>     Inc(DevModeCount);
> 
>     {display the resolution of the enumerated display mode}
>     ListBox1.Items.Add(IntToStr(DevModeInfo^.dmPelsWidth)+'x'+
>                        IntToStr(DevModeInfo^.dmPelsHeight)+', '+
>                        IntToStr(Trunc(IntPower(2,
> DevModeInfo^.dmBitsPerPel)))+
>                        ' colors');
> 
>     {allocate another slot for device mode information}
>     GetMem(DevModeInfo, SizeOf(TDevMode));
>   end;
> 
>   {the above loop always exits with one extra, unused block of memory,
>    so delete it}
>   FreeMem(DevModeInfo, SizeOf(TDevMode));
> 
>   {select the first item in the list box}
>   ListBox1.ItemIndex := 0;
> end;
> 
> procedure TForm1.FormDestroy(Sender: TObject);
> var
>   iCount: Integer;         // a general loop counter
> begin
>   {free all memory pointed to by each item in the list}
>   for iCount := 0 to DevModeArray.Count-1 do
>     FreeMem(DevModeArray.Items[iCount], SizeOf(TDevMode));
> 
>   {free the list}
>   DevModeArray.Free;
> end;
> 
> procedure TForm1.Button1Click(Sender: TObject);
> var
>   ModeChange: Longint;        // indicates if a Windows reboot is necessary
> begin
>   {change the display mode}
>   ModeChange:=ChangeDisplaySettings(DevModeArray[ListBox1.ItemIndex],
>                                     CDS_UPDATEREGISTRY);
> 
>   {indicate if a dynamic change was successful or if Windows must be
> rebooted}
>   if ModeChange=DISP_CHANGE_SUCCESSFUL then
>     ShowMessage('Dynamic display mode change successful.');
>   if ModeChange=DISP_CHANGE_RESTART then
>     ShowMessage('Change successful; Windows must be restarted for the
> changes '+
>                 'to take effect');
> end;
> 


Rohit

======================================================================
CFL - Computer Fanatics Ltd.  21 Barry's Point Road, AKL, New Zealand
PH    (649) 489-2280 
FX    (649) 489-2290
email [EMAIL PROTECTED]  or  [EMAIL PROTECTED]
======================================================================

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to