■■■如何获取当前显示器的刷新频率■■■
如何获取当前显示器的刷新频率?又如何更改刷新率?
请给代码?

解决方案 »

  1.   

    你指的是DisplayFrequency?
    如果是, 用EnumDisplaySettings这个API函数试试. 
    帮助中的提到dmDisplayFrequency这个参数
      

  2.   

    //获得当前系统显示刷新频率
    function GetDispSet():integer;
    var
      DeviceMode: TDeviceMode;
    begin
       result:=0;
       EnumDisplaySettings(nil, Cardinal(-1), DeviceMode);
       result:=DeviceMode.dmDisplayFrequency;
    end;//改变系统显示刷新频率
    function ChangeDispSet(iFrequency:integer):integer;
    var
      DeviceMode:TDeviceMode;
    begin
       result:=0;
       EnumDisplaySettings(nil,Cardinal(-1), DeviceMode);
       DeviceMode.dmDisplayFrequency:=Cardinal(iFrequency);
       result:=ChangeDisplaySettings(DeviceMode,CDS_UPDATEREGISTRY);
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      devmode:Tdevicemode;
      freq:integer;
    begin
      DevMode.dmSize:=sizeof(TDeviceMode);
      EnumDisplaySettings(nil, DWORD(-1), DevMode);
      Freq:= DevMode.dmDisplayFrequency;
      showmessage(inttostr(freq));
    end;
      

  4.   

    读注册表HKEY_CURRENT_CONFIG\Display\Settings\RefreshRate的值.
      

  5.   

    谢谢 WWWWA(aaaa) 和 haerbin982() !
     Wnyu(西门吹水) 注册表里无此分支。win2000。
    TScreen里也没有。结贴。
      

  6.   

    不过我还有一个疑问,我查了一下windows SDK,其中关于第二个参数是这样描述的:iModeNumIndex value that specifies the graphics mode for which information is to be obtained.
    Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls to EnumDisplaySettings, as follows: Set iModeNum to zero for the first call, and increment iModeNum by one for each subsequent call. Continue calling the function until the return value is FALSE.  
    When you call EnumDisplaySettings with iModeNum set to zero, the operating system initializes and caches information about the display device. When you call EnumDisplaySettings with iModeNum set to a non-zero value, the function returns the information that was cached the last time the function was called with iModeNum set to zero.“索引值指定要获取的某个信息的图形模式。
    图形模式索引值从0开始。要获取所有显示设备图形模式的列表,则要对EnumDisplaySettins进行一系列调用,如下:第一次调用时将iModeNum值设为0,然后逐步增加这个值调用EnumDisplaysettings,直到该函数返回值为false为止。
    .....”其中并未提到Cardinal(-1)这个参数,请问各位是如何知道的?
      

  7.   

    The first function returns the color of a specific pixel(像素;显示器的最小分辨单元). The SetPixel function changes the targeted pixel to the color sent. There is no PowerBuilder equivalent.
    Global External Function: 
    FUNCTION ulong GetPixel(ulong hwnd, long xpos, long ypos) LIBRARY "Gdi32.dll" 
    FUNCTION ulong SetPixel(ulong hwnd, long xpos, long ypos, ulong pcol) LIBRARY "Gdi32.dll" Script: 
    long lx, ly 
    ulong rtn 
    ulong l_handle, l_device 
    lx = 100 
    ly = 100 
    l_handle = handle(w_main) 
    l_device = GetDC(l_handle) 
    rtn = GetPixel(l_device, 100, 100) 
    MessageBox("Position " + string(lx) + "," + string(ly),"Color = " + string(rtn)) 
    SetPixel(l_device, lx, ly, 0) // This call will set the pixel at lx, ly to black.
      

  8.   

    Cardinal(-1)并不等于-1啊,是-1的补码,是个正数。