delphi 取屏幕分辨率

For the original Question, see: Setting resolution of screen from Delphi

有关原始问题,请参见从Delphi设置屏幕分辨率

Here's the code for a Delphi main form unit.  Take and learn whatever you need.  Note that it also sorts the menu so that the best resolution is also the most accessible.

这是Delphi主表单单元的代码。 采取并学习任何您需要的东西。 请注意,它还会对菜单进行排序,以便最容易获得最佳分辨率。

(
)



unit ChangeResMainUnit;
//==================================================================================================================================
// Note that this source file is arranged for 132-column display/editing - use the WIDTH, Luke!
//
// The following code was adapted by Alex Tidmarsh from an example provided by "williams2" upon https://www.experts-exchange.com.
// The point of it all is to (a) make it a little easier to use, and (b) ensure the task bar also resizes/moves for the resolution.
// In particular, it was recoded to help manage resolution changes under VMware KVM, especially for an older OS like Windows NT4.
// It ensures the "highest" modes are displayed as drop down menu options first, which ensures they are the ones most likely to be
// seen when trying to use this tool in a very low resolution!  Otherwise you would need many clicks to increase it from 320x200!
//==================================================================================================================================
//==================================================================================================================================
interface
//==================================================================================================================================
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Menus, ShellAPI;
type TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
MainMenu1: TMainMenu;
procedure MenuItemClick(Sender: TObject);
procedure CreateSortedResolutionEntries;
end;
var Form1: TForm1;
//==================================================================================================================================
implementation
//==================================================================================================================================
{$R *.DFM}
// ShowTaskBar allows the taskbar to be hidden and shown again - which can in theory be useful for REALLY small screen real-estates.
procedure ShowTaskBar(show:Boolean);
var taskbar : HWND;
begin
taskbar := FindWindow('Shell_TrayWnd', nil);
if (taskbar <> 0) then
begin
if Show then ShowWindow(taskbar, SW_SHOW )
else ShowWindow(taskbar, SW_HIDE);
UpdateWindow(taskbar);
end;
end;
// MenuItemClick implements the Device Mode chosen from the menu at runtime
procedure TForm1.MenuItemClick(Sender: TObject);
Var Mode: Integer;
DevMode: TDevMode;
res: Integer;
begin
ShowTaskBar(FALSE); // If (as happens in NT4 under VMware) the display surface is way too small, increase real estate.
try
Mode:= TMenuItem(Sender).Tag;
if EnumDisplaySettings(  nil,     // specifies the display device
Mode,    // specifies the graphics mode
DevMode  // points to structure to receive settings
) then
begin
res:= ChangeDisplaySettings( DevMode, CDS_UPDATEREGISTRY ); // MUST update registry to ensure taskbar movement/resize.
// We could use CDS_TEST, which apparently tests whether the displaymode is available, or ZERO (CDS_NONE) that changes the
// display mode, but does not necessarily cause certain windows (like the TaskBar in NT4 for instance) to also change.
// Check the outcome...
case res of
DISP_CHANGE_SUCCESSFUL:// The settings change was successful.
;
DISP_CHANGE_RESTART:   // The computer must be restarted in order for the graphics mode to work.
MessageDlg('You need to restart the computer to invoke changes.',mtInformation,[mbOk],0);
DISP_CHANGE_BADFLAGS:  // An invalid set of flags was passed in.
MessageDlg('Graphic settings are invalid.',mtError,[mbOk],0);
DISP_CHANGE_FAILED:    // The display driver failed the specified graphics mode.
MessageDlg('Failed to change to specified displaymode.',mtError,[mbOk],0);
DISP_CHANGE_BADMODE:   // The graphics mode is not supported.
MessageDlg('Graphic mode is invalid.',mtError,[mbOk],0);
DISP_CHANGE_NOTUPDATED:// Unable to write settings to the registry.
MessageDlg('Unable to update the system registry.',mtError,[mbOk],0);
end;
end else MessageDlg('Unable to retrieve mode!',mtError,[mbOk],0);
finally
ShowTaskBar(TRUE);  // Always, always, always - give the task bar back to the user!
end;
end;
// CreateSortedResolutionEntries creates a conveniently arranged drop-down menu of device modes to select from.
Procedure TForm1.CreateSortedResolutionEntries;
var HaveDevMode: BOOL;
DevMode: TDevMode;
S: String;
ModeNumber,b,r,f,c: Integer;
Index : Integer;
LBitsPerPel,LResolution,LFreq,LColour: TStringList;
MenuItem,BitsPerPelItem,ResolutionItem,FreqItem,ColorItem: TMenuItem;
begin
// First create a sorted list structure, starting with Bits/Pel at its lowest tier
LBitsPerPel:= TStringList.Create;
LBitsPerPel.Sorted := TRUE;
LBitsPerPel.Duplicates := dupIgnore;
// Now enumerate the device modes
ModeNumber:= 0;
repeat
HaveDevMode := EnumDisplaySettings( nil,        // specifies the display device
ModeNumber, // specifies the device mode number
DevMode     // points to structure to receive settings
);
if HaveDevMode then // Add this device mode to a pre-sorted list structure with no duplicates
with DevMode do
begin
// Find bits per pixel - note that we use an easily removable 2-digit hex code to provide a sort-order
Index := LBitsPerPel.add( IntToHex(dmBitsPerPel,2) + IntToStr(dmBitsPerPel)+' bit mode' );
// Start (or re-use) the next tier in the structure, which is Resolution
LResolution := TStringList( LBitsPerPel.Objects[ Index ] );
if LResolution = nil then
begin
LResolution := TStringList.Create;
LResolution.Sorted := TRUE;
LResolution.Duplicates := dupIgnore;
LBitsPerPel.Objects[ Index ] := LResolution;
end;
// Find width and height - note that we use an easily removable 10-digit hex code to provide a sort-order
Index := LResolution.add( IntToHex(dmPelsWidth,5) + IntToHex(dmPelsHeight,5)
+ IntToStr(dmPelsWidth)+'x'+IntToStr(dmPelsHeight) );
// Start (or re-use) the next tier in the structure, which is Frequency
LFreq := TStringList( LResolution.Objects[ Index ] );
if LFreq = nil then
begin
LFreq := TStringList.Create;
LFreq.Sorted := TRUE;
LFreq.Duplicates := dupIgnore;
LResolution.Objects[ Index ] := LFreq;
end;
// Find or create Frequency - note that we use an easily removable 4-digit hex code to provide a sort-order
Index := LFreq.add( IntToHex(dmDisplayFrequency,4) + IntToStr(dmDisplayFrequency)+' Hz' );
// Start (or re-use) the next tier in the structure, which is Colour
LColour := TStringList( LFreq.Objects[ Index ] );
if LColour = nil then
begin
LColour := TStringList.Create;
LColour.Sorted := TRUE;
LColour.Duplicates := dupIgnore;
LFreq.Objects[ Index ] := LColour;
end;
// Find Color Mode + Interlaced option.
If (dmDisplayFlags AND DM_GRAYSCALE)>0 then S:='B/W ' else S:='Color ';
If (dmDisplayFlags AND DM_INTERLACED)>0 then S:= S+'Interlaced';
Index := LColour.add( S );
LColour.Objects[ Index ] := TObject(ModeNumber);
end;
inc(ModeNumber);
until not(HaveDevMode);
// Create a menu structure from the sorted list structure we just built
LBitsPerPel.Sorted := FALSE;
LBitsPerPel.Sorted := TRUE;
MenuItem:= TMenuItem.Create(Self);
MenuItem.Caption:='Resolutions';
MainMenu1.Items.Add(MenuItem);
for b := LBitsPerPel.Count-1 downto 0 do  // Make highest mode first!
begin
BitsPerPelItem := TMenuItem.Create(self);
BitsPerPelItem.Caption := Copy(LBitsPerPel[b],3,99); // Remove 2-digit hex sort code and use remaining bits/pel string
MenuItem.Add( BitsPerPelItem );
LResolution := TStringList(LBitsPerPel.Objects[ b ]);
for r := LResolution.Count -1 downto 0 do  // Make highest mode first!
begin
ResolutionItem := TMenuItem.Create(self);
ResolutionItem.Caption := Copy(LResolution[r],11,99); // Remove 10-digit hex sort code & use remaining resolution string
BitsPerPelItem.Add( ResolutionItem );
LFreq := TStringList(LResolution.Objects[ r ]);
for f := LFreq.Count -1 downto 0 do  // Make highest mode first!
begin
FreqItem := TMenuItem.Create(self);
FreqItem.Caption := Copy(LFreq[f],5,99); // Remove 4-digit hex sort code and use remaining freq string
ResolutionItem.Add( FreqItem );
LColour := TStringList(LFreq.Objects[ f ]);
for c := 0 to LColour.Count-1 do  // Make highest mode first (already sorts that way)
begin
ColorItem := TMenuItem.Create(self);
ColorItem.Caption := LColour[c]; // This option was self-sorting already (text only, not varying-digit numeric)
FreqItem.Add( ColorItem );
// Add the payload.
ModeNumber := Integer(LColour.Objects[ c ]);
ColorItem.Tag := ModeNumber;
ColorItem.OnClick := MenuItemClick;
end;
end;
end;
end;
// Discard the list structure
for b := 0 to LBitsPerPel.Count-1 do
begin
LResolution := TStringList(LBitsPerPel.Objects[ b ]);
for r := 0 to LResolution.Count -1 do
begin
LFreq := TStringList(LResolution.Objects[ r ]);
for f := 0 to LFreq.Count -1 do
begin
LColour := TStringList(LFreq.Objects[ f ]);
LColour.Free;
end;
LFreq.Free;
end;
LResolution.Free;
end;
LBitsPerPel.Free;
end;
// Create the form with a menu!
procedure TForm1.FormCreate(Sender: TObject);
begin
MainMenu1:= TMainMenu.Create(Self);
CreateSortedResolutionEntries;
end;
end.

Alex Tidmarsh

亚历克斯·提德马什(Alex Tidmarsh)

翻译自: https://www.experts-exchange.com/articles/31321/An-update-to-changing-Windows-screen-resolution-using-Delphi.html

delphi 取屏幕分辨率

delphi 取屏幕分辨率_使用Delphi更改Windows屏幕分辨率的更新相关推荐

  1. iphone分辨率_揭示真实的手机屏幕大小和分辨率

    关于屏幕面积: 如今随着全面屏的发展,手机屏幕的尺寸越来越大,几年前6寸就算大屏手机,而如今,小于6寸的手机已经很少了.但是随着手机尺寸的增加,特别是18:9等比例手机的增加,大家发现现在手机&quo ...

  2. ati自定义分辨率_修改三国无双 游戏自定义分辨率教学 6/19更新

    本帖最后由 jam52076 于 2014-6-19 10:15 编辑 修改游戏自定义分辨率教学 另外大神們有更好的方式 比如程序啥的 調用就能改的 可以私密我加上來 N卡 首先打开NVIDIA的控制 ...

  3. python解锁电脑屏幕_怎样解除电脑屏幕锁定_教你解除电脑屏幕锁定的方法-系统城...

    电脑自带有屏幕锁定功能,可有效防止他人非法查看自己电脑上的隐私.但是也有用户觉得开启电脑要输入密码才能进入很麻烦,有什么办法解除屏幕锁定呢?方法当然有的,小编这就分享具体方法给大家. 具体方法如下: ...

  4. win7调整屏幕亮度_番禺区户外LED屏幕求购,区LCD屏幕解决方案

    广州市唯昕电子科技有限公司为您详细解读gVtwd番禺区户外LED屏幕求购的相关知识与详情,正在当今大尺寸液晶面板范畴,55英寸卖得货已经成为市场的支流.但是关于很多行业用户来说,李某们会担忧将来使用的 ...

  5. android锁定屏幕通知_如何在Android锁定屏幕上隐藏敏感通知

    android锁定屏幕通知 When Google brought notifications to Android's lock screen, it was a game changer. Ins ...

  6. python降低图片分辨率_使用numpy快速降低图像分辨率的Python代码

    我首先要说的是,你的"只装箱"方式似乎很不寻常,我想这正是@ljetibo在评论中所指的.在"优化"讨论之后,我将回到这个话题.在 首先,您可以通过去掉对np. ...

  7. android最新屏幕视频教程,安卓怎么录制手机屏幕视频_怎么录制自己手机屏幕教程_好特教程...

    怎样能够用自己的手机录制自己手机屏幕的视频呢?安卓手机在没有其他录制设备的情况下如何录制手机屏幕上的视频呢? 1.首先我们下载安装好 录屏精灵 这软件 . 很多小伙伴可能会问,为什么我要选择这软件呢? ...

  8. matlab修改图像分辨率_[转载]Matlab图片保存指定分辨率(图片dpi设置)

    登录后查看更多精彩内容~ 您需要 登录 才可以下载或查看,没有帐号?立即注册 x 本帖最后由 haobang008 于 2016-7-19 14:38 编辑 先附上效果对比,第一张图是300dpi设置 ...

  9. ati自定义分辨率_关于ATI显卡无法保存分辨率设置的完美解决办法!

    由于本人使用ATI9550,也有分辨率无法保存的问题,一偶然机会发现了完美的解决办法. 大多数出现此问题的朋友使用的都是A卡9550或X550+Philips显示器,主要原因是由于新版驱动和PHILI ...

最新文章

  1. c盘扩展卷是灰色的_银行电脑win7-C盘满了怎么办
  2. java classloader_Java Classloader原理分析
  3. python编辑邮件格式_python发送邮件模板
  4. 时间管理,从洗碗开始
  5. IRC 聊天工具(xchat,chatzilla,pidgin)入门教程
  6. Linux下安装Go环境
  7. Eclipse 工具的安装和配置
  8. 开源字体lato fonts
  9. 盗窟手机小我私人撤军华强北:市场一年不如一年
  10. 《经济机器是怎样运行的》笔记(二)
  11. 牛客每日一题 飞扬的小鸟
  12. mac的python怎么打中文空格_中英文排版空格问题解决方案
  13. Line 167. parse error, unexpected IS, expecting SEMICOLON ISE14.7
  14. Profinet协议解析-过程数据
  15. python高斯噪声怎么去除_【OpenCV+Python】线性滤波amp;非线性滤波
  16. Magento 1.4 EAV 属性中的新东西
  17. Listener refused the connection with the following error
  18. word中图片批量修改
  19. 奇怪的报错(uncaught typeerror illegal invocation)
  20. AndroidStudio升级后,离线更新Gradle版本失败问题解决

热门文章

  1. 不小心清空了回收站怎么恢复,回收站删除的东西可以恢复吗
  2. NPOI 设置excel 边框
  3. next_day的使用
  4. 计算机主机显卡在哪里,苹果台式电脑显卡位置在哪里
  5. 政府怎么应用视频直播系统?
  6. ps转换html适应网页尺寸,【ps制作网页页面】ps图像如何生成html?如何将PS制作的网页效果图变成可用的网页?PC端UI设计尺寸规范?...
  7. 抽样平均近似方法(SAA)
  8. 论文写作分析报告CSDN
  9. 基于 qiankun 的微前端最佳实践(万字长文) - 从 0 到 1 篇
  10. 如何判断代理IP的匿名程度?