PDA

View Full Version : Problem getting monitor information



Luuk van Venrooij
12-07-2008, 06:45 PM
He all,

Last week I wrote some code at work to make our webgames fullscreen. I added some cool code that detects the current monitor the browser is on so we can set it fullscreen on that one. Now I want todo the same my template application but then of course in delphi. The problem the same code in I use to give me back the monitor information on which the application resides fails in delphi. Here is the c and delphi code:

c++:

HMONITOR hMonitor = MonitorFromWindow(m_Handle,MONITOR_DEFAULTTOPRIMAR Y);
MONITORINFOEX monInfo;
memset(&monInfo, 0, sizeof(MONITORINFOEX));
monInfo.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &monInfo);

delphi:

iMonInfo : MONITORINFOEX;
iHM : HMONITOR;

iHM := MonitorFromWindow(Wnd, MONITOR_DEFAULTTOPRIMARY);
FillChar(iMonInfo, SizeOf(iMonInfo), 0);
iMonInfo.cbSize := SizeOf(iMonInfo);
If Not(GetMonitorInfo(iHM, @iMonInfo)) then
begin
MessageBox(0, 'Unable to switch to fullscreen!', 'Error', MB_OK or MB_ICONERROR);
Fullscreen := False;
end;


GetMonitorInfo fails in delphi. I searched the internet and I only could find this:

http://qc.codegear.com/wc/qcmain.aspx?d=3239

I checked the records and there fixed in delphi 2007. Anyone got any clew whats going on here?

waran
13-07-2008, 04:15 AM
wrong:

szDevice: array[0..CCHDEVICENAME] of AnsiChar;
right:

szDevice: array[0..CCHDEVICENAME - 1] of AnsiChar;

Simply use the MONITORINFOEX-definition from the workaround and it should work just fine.

Edit:
Oh, they are already fixed in 2007. Ok try following: Instead of writing

not(GetMonitorInfo(...));
write

not&#40;GetMonitorInfo&#40;...&#41;<>0&#41;;
Actually it should return bool, but maybe they did something wrong on the translation.

Luuk van Venrooij
13-07-2008, 09:03 AM
Check should not be the problem. The struc that is returned spimpy is empty. When I run the c++ version on my pc it`s filled with information I can verify. I delphi everyting is just empty

waran
13-07-2008, 10:03 AM
Is the handle you obtain from MonitorFromWindow correct; do you provide
the correct window handle to it?

JSoftware
13-07-2008, 02:51 PM
Looking at the multimon unit is very weird. They use some sort of stub calling to call the API function. Might be something screwed up in there. It's funny that MSDN don't state any calling convention on their definition of the API functions for multi monitors

Luuk van Venrooij
13-07-2008, 08:16 PM
The handle is correct but I have fixed the problem another way. I just imported the needed functions myself and do not use the MultiMon unit anymore. Don`t know what the problem is with it but something is broke :) .