Results 1 to 6 of 6

Thread: Problem getting monitor information

  1. #1

    Problem getting monitor information

    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:
    [pascal]
    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;
    [/pascal]

    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?

  2. #2

    Problem getting monitor information

    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
    Code:
    not(GetMonitorInfo(...));
    write
    Code:
    not&#40;GetMonitorInfo&#40;...&#41;<>0&#41;;
    Actually it should return bool, but maybe they did something wrong on the translation.

  3. #3

    Problem getting monitor information

    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

  4. #4

    Problem getting monitor information

    Is the handle you obtain from MonitorFromWindow correct; do you provide
    the correct window handle to it?

  5. #5

    Problem getting monitor information

    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
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #6

    Problem getting monitor information

    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 .

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •