首页  编辑  

设置屏幕分辨率和颜色

Tags: /超级猛料/Hardware.硬件相关/其它硬件/   Date Created:

procedure SetRes(XRes, YRes: DWord);

var

lpDevMode : TDeviceMode;

begin

EnumDisplaySettings(nil, 0, lpDevMode);

lpDevMode.dmFields:=DM_PELSWIDTH or DM_PELSHEIGHT;

lpDevMode.dmPelsWidth:=XRes;

lpDevMode.dmPelsHeight:=YRes;

ChangeDisplaySettings(lpDevMode, 0);

end;

******************

设置屏幕颜色深度

procedure Toggle;

var

 i : LongInt;

 b : LongInt;

 DevM : TDEVMODE;

 h: HDC;

 w: HWND;

  IsToggled:  Boolean;

  PreviousBitsPerPixel: Integer;

begin

 IsToggled := not IsToggled;

 w:=GetDesktopWindow;

 h:=GetDC(w);

 try

    if IsToggled then

    begin {change to 8 bit}

       PreviousBitsPerPixel := GetDeviceCaps(h, BITSPIXEL);

       i := -1;

       Repeat

         Inc(i);

       Until EnumDisplaySettings(pchar(0), i, DevM) = False;

       DevM.dmFields := DM_BITSPERPEL;

       DevM.dmBitsPerPel := 8;

       b := ChangeDisplaySettings(DevM, 0);

       if ((GetDeviceCaps(h, RASTERCAPS) and RC_PALETTE) = 0) or

          (b <> DISP_CHANGE_SUCCESSFUL) then

       begin

         showmessage('can''t use palettes');

         IsToggled := False;

       end

    end else {Change mform to palette values and perform desired 8 bit display}

    else begin {change back value}

       i := -1;

       Repeat

         Inc(i);

       Until EnumDisplaySettings(pchar(0), i, DevM) = False;

       DevM.dmFields := DM_BITSPERPEL;

       DevM.dmBitsPerPel := PreviousBitsPerPixel;

       b := ChangeDisplaySettings(DevM, 0);

       if b <> DISP_CHANGE_SUCCESSFUL then showmessage( 'Error restoring origional display');

    end;

 finally

    ReleaseDC(w,h);

 end;

end;

qres.zip (37.3KB)