我们的Delphi应用程序可以在多个DirectX窗口上运行,通常在多个屏幕上。到目前为止,用户必须使用支持的分辨率下拉列表指定全屏分辨率。如果他可以使用“当前”这样的设置,那将非常好,它将是窗口所在屏幕的分辨率。
我们正在使用带有Clootie DirectX标头的Delphi。有人能给我一个提示,我将如何编写一个使用DirectX、WinAPI或Delphi方法的方法来获取窗口所在当前屏幕的分辨率吗?
此致敬礼, thalm
最终解决方案:
好的,Delphi 2007 MultiMon.pas 对于GetMonitorInfo返回垃圾,所以我找到了这种方法,对我有效,直接使用winAPI:
我们正在使用带有Clootie DirectX标头的Delphi。有人能给我一个提示,我将如何编写一个使用DirectX、WinAPI或Delphi方法的方法来获取窗口所在当前屏幕的分辨率吗?
此致敬礼, thalm
最终解决方案:
好的,Delphi 2007 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;