Take the tour ×

our delphi application can have multiple DirectX windows, often on multiple screens. up to now the user had to specify the fullscreen resolution using a dropdown with the supported resolutions. it would be very nice, if he could use a setting like 'current' which would be the resolution of the screen on which the window is.

we are using delphi with clootie directX headers. can someone give me a hint, how i would write a method using directX, winAPI or delphi methods to get the resolution of the current screen on which the window is?

kind regards, thalm


ok, delphi 2007 MultiMon.pas returns crap for GetMonitorInfo, so i found this method, which works for me, using the winAPI directly:

function GetRectOfMonitorContainingRect(const R: TRect): TRect;
{ Returns bounding rectangle of monitor containing or nearest to R }
  HMONITOR = type THandle;
  TMonitorInfo = record
    cbSize: DWORD;
    rcMonitor: TRect;
    rcWork: TRect;
    dwFlags: DWORD;
  Module: HMODULE;
  MonitorFromRect: function(const lprc: TRect; dwFlags: DWORD): HMONITOR; stdcall;
  GetMonitorInfo: function(hMonitor: HMONITOR; var lpmi: TMonitorInfo): BOOL; stdcall;
  Info: TMonitorInfo;
  Module := GetModuleHandle(user32);
  MonitorFromRect := GetProcAddress(Module, 'MonitorFromRect');
  GetMonitorInfo := GetProcAddress(Module, 'GetMonitorInfoA');
  if Assigned(MonitorFromRect) and Assigned(GetMonitorInfo) then begin
    Info.cbSize := SizeOf(Info);
    if GetMonitorInfo(M, Info) then begin
      Result := Info.rcMonitor;
  Result := GetRectOfPrimaryMonitor(True);
share|improve this question
but i wonder whats the difference between GetMonitorInfo, GetMonitorInfoA and GetMonitorInfoW? can anyone explain that? –  thalm Aug 17 '11 at 0:32
ok, found out, its A for ansi strings and W for wide strings... –  thalm Aug 17 '11 at 11:44
add comment

3 Answers

up vote 5 down vote accepted
  MonInfo: TMonitorInfo;
  MonInfo.cbSize := SizeOf(MonInfo);
  ShowMessage(Format('Current resolution: %dx%d',
              [MonInfo.rcMonitor.Right - MonInfo.rcMonitor.Left,
               MonInfo.rcMonitor.Bottom - MonInfo.rcMonitor.Top]));
share|improve this answer
see my post for a complete solution, it only works using the winAPI directly, as delphi 2007 seems to be buggy here. –  thalm Aug 16 '11 at 18:32
add comment

See the GetDeviceCaps API to get the screen resolution.

Use the TCustomForm.Monitor property to get the monitor on which the form appears.

share|improve this answer
TCustomForm.Monitor do what you said, but OP wants to get all of them. Also the GetDeviceCaps function is common for getting many attributes and many device types. Anyway I haven't voted here. –  user532231 Aug 16 '11 at 12:54
There is Screen.Monitors to get all monitors. But as I understand it the OP wants to get the current screen, ie quote: "it would be very nice, if he could use a setting like 'current' which would be the resolution of the screen on which the window is" and thats what Form.Monitor gives? –  ain Aug 16 '11 at 13:02
add comment

First use EnumDisplayDevices to obtain a list of all monitor names, see this usenet post for how to do that in Delphi. Note that you want the DeviceName rather than the DeviceString.

Then for each monitor use EnumDisplaySettings(lpDisplayDevice.DeviceName, ENUM_CURRENT_SETTINGS, lpDevMode) to obtain the current settings. Here you can also use NULL as the device name, which means: "A NULL value specifies the current display device on the computer on which the calling thread is running.". This should usually correspond to the monitor the user is currently on.

share|improve this answer
add comment

Your Answer


