delphi如何获取屏幕的分辨率

来源:互联网 发布:加载更多js 编辑:程序博客网 时间:2024/06/05 21:11

 屏幕的分辨率用这个  
  x=GetSystemMetrics(SM_CXSCREEN)  
  y=GetSystemMetrics(SM_CYSCREEN)  
  同上。
.而且获得屏幕上的像素好像应该使用screen.pixelsperinch函数

int   GetDeviceCaps(  
   
          HDC   hdc, //   device-context   handle    
          int   nIndex   //   index   of   capability   to   query      
        );  
    LOGPIXELSX Number   of   pixels   per   logical   inch   along   the   screen   width.  
  LOGPIXELSY Number   of   pixels   per   logical   inch   along   the   screen   height. 

当我们需要获取所运行程序时计算机的分辨率时,有两种方法:①可以通过访问Delphi提供的SCREEN全局变量,即SCREEN.WIDTH和SCREEN.HEIGHT以像素点给出屏幕的分辨率。②利用Windows的API函数GetDeviceCaps()来得到所用显示器的分辨率,源代码如下:

    Application.Initialize;

    Application.CreateForm(TForm1, Form1);

    CASE GetDeviceCaps(GetDC(Form1.Handle),HORZRES) of

    640 : //对640×480分辨率进行处理的代码;

    800 : //对800×600分辨率进行处理的代码;

    1024: //对1024×768分辨率进行处理的代码;

    1280: //对1280×1024分辨率进行处理的代码;

END;

总结:谢谢各位朋友的奉献,可以放置以show事件中,而且用self引用,可降低出错概率!

原创粉丝点击