whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

88 Visitors Online


 
...Change the Screen Resolution?
Autor: Simon Grossenbacher
Homepage: http://www.swissdelphicenter.ch
[ Print tip ]  

Tip Rating (22):  
     


{
The function NewRes can have the following result:

DISP_CHANGE_SUCCESSFUL The settings change was successful.
DISP_CHANGE_RESTART The computer must be restarted in order for the graphics mode to work.
DISP_CHANGE_BADFLAGS An invalid set of flags was passed in.
DISP_CHANGE_FAILED The display driver failed the specified graphics mode.
DISP_CHANGE_BADMODE The graphics mode is not supported.
DISP_CHANGE_NOTUPDATED Windows NT only: Unable to write settings to the registry.
}


{
Folgene Rückgabewerte sind für NewRes möglich:

DISP_CHANGE_SUCCESSFUL Auflösung geändert
DISP_CHANGE_RESTART Computer muss neugestartet werden
DISP_CHANGE_BADFLAGS Falsche Flags
DISP_CHANGE_FAILED Fehler in Grafiktreiber
DISP_CHANGE_BADMODE Auflösung nicht unterstützt
DISP_CHANGE_NOTUPDATED Windows NT: Einstellungen konnten nicht in die Registry geschrieben werden
}


function NewRes(XRes, YRes: DWORD; Frequency: Cardinal): Integer;
var
  
DevMode: TDeviceMode;
begin
  
EnumDisplaySettings(nil, 0, DevMode);
  DevMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT or DM_DISPLAYFREQUENCY;
  DevMode.dmPelsWidth := XRes;
  DevMode.dmPelsHeight := YRes;
  DevMode.dmDisplayFrequency := Frequency;
  Result := ChangeDisplaySettings(DevMode, 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
NewRes(1280, 1024, 85) = DISP_CHANGE_SUCCESSFUL then
    
ShowMessage('Resolution changed!');
end


//Another function:


function ChangeResolution(XResolution, YResolution, Depth: DWORD): BOOL;
var
  
DevMode: TDeviceMode;
  i: Integer;
begin
  
Result := False;
  i      := 0;
  while EnumDisplaySettings(nil, i, DevMode) do
    with 
DevMode do
    begin
      if 
(dmPelsWidth = XResolution) and
        
(dmPelsHeight = YResolution) and
        
(dmBitsPerPel = Depth) then
        if 
ChangeDisplaySettings(DevMode, CDS_UPDATEREGISTRY) =
          DISP_CHANGE_SUCCESSFUL then
        begin
          
Result := True;
          SendMessage(HWND_BROADCAST, WM_DISPLAYCHANGE, SPI_SETNONCLIENTMETRICS, 0);
          Break;
        end;
      Inc(i);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
ChangeResolution(800, 600, 32) then ShowMessage('Resolution changed!');
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners