如何检测Delphi中的屏幕分辨率变化?

时间:2013-02-08 12:28:02

标签: delphi winapi screen-resolution

问题很简单。如何检测Delphi中的屏幕分辨率变化?

1 个答案:

答案 0 :(得分:19)

您只需要检测WM_DISPLAYCHANGE消息。

例如,

TForm1 = class(TForm)
private
protected
  procedure WMDisplayChange(var Message: TWMDisplayChange);
    message WM_DISPLAYCHANGE;
  { Private declarations }

public
  { Public declarations }
end;

...

procedure TForm1.WMDisplayChange(var Message: TWMDisplayChange);
begin
  ShowMessageFmt('The screen resolution has changed to %d×%d×%d.',
    [Message.Width, Message.Height, Message.BitsPerPixel]);
end;

Sample screenshot http://privat.rejbrand.se/screenreschange.png