我们的delphi应用程序可以有多个DirectX窗口,通常在多个屏幕上。到目前为止,用户必须使用支持的分辨率下拉框来指定全屏分辨率。如果他能使用像“电流”这样的设置,这将是窗口所在屏幕的分辨率,那就太好了。
我们使用头。有人能给我一个提示吗?我将如何使用directX、winAPI或delphi方法编写一个方法来获得窗口所在的当前屏幕的分辨率?
亲切的问候,地中海
最终解决方案:
好的,Delphi2007 MultiMon.pas返回GetMonitorInfo的所以我发现,这个方法对我有用,直接使用winAPI:
function GetRectOfMonitorContainingRect(const R: TRect): TRect;
{ Returns bounding rectangle of monitor containing or nearest to R }
type
HMONITOR = type THandle;
TMonitorInfo = record
cbSize: DWORD;
rcMonitor: TRect;
rcWork: TRect;
dwFlags: DWORD;
end;
const
MONITOR_DEFAULTTONEAREST = $00000002;
var
Module: HMODULE;
MonitorFromRect: function(const lprc: TRect; dwFlags: DWORD): HMONITOR; stdcall;
GetMonitorInfo: function(hMonitor: HMONITOR; var lpmi: TMonitorInfo): BOOL; stdcall;
M: HMONITOR;
Info: TMonitorInfo;
begin
Module := GetModuleHandle(user32);
MonitorFromRect := GetProcAddress(Module, 'MonitorFromRect');
GetMonitorInfo := GetProcAddress(Module, 'GetMonitorInfoA');
if Assigned(MonitorFromRect) and Assigned(GetMonitorInfo) then begin
M := MonitorFromRect(R, MONITOR_DEFAULTTONEAREST);
Info.cbSize := SizeOf(Info);
if GetMonitorInfo(M, Info) then begin
Result := Info.rcMonitor;
Exit;
end;
end;
Result := GetRectOfPrimaryMonitor(True);
end;
发布于 2011-08-16 11:48:27
首先使用EnumDisplayDevices
获取所有监视器名称的列表,请参阅这 usenet post,了解如何在Delphi中这样做。请注意,您需要的是DeviceName
而不是DeviceString
。
然后,对于每个监视器,使用EnumDisplaySettings
(lpDisplayDevice.DeviceName, ENUM_CURRENT_SETTINGS, lpDevMode)
获取当前设置。在这里,还可以使用NULL
作为设备名称,这意味着:“NULL值指定正在运行调用线程的计算机上的当前显示设备。”这通常应该与用户当前所使用的监视器相对应。
https://stackoverflow.com/questions/7077572
复制相似问题