[changeset] Missing ScreenSize & ScreenPixelsPerInch properties

Michael Goffioul michael.goffioul at gmail.com
Thu Jan 22 12:58:15 CST 2009


Better with the attachment.

On Thu, Jan 22, 2009 at 6:57 PM, Michael Goffioul
<michael.goffioul at gmail.com> wrote:
> I used the attached code instead (note the use LOGPIXELSX/Y and
> ReleaseDC). The results are:
>
> 1280x800 pixels
> 320x200 mm
> 101.6 resx
> 101.6 resy
> 96 resx_log
> 96 resy_log
> 101.6 avg dpi
> 32 bit depth
>
> Michael.
>
>
> On Thu, Jan 22, 2009 at 3:08 PM, John W. Eaton <jwe at octave.org> wrote:
>> On 22-Jan-2009, Michael Goffioul wrote:
>>
>> | On Thu, Jan 22, 2009 at 2:13 PM, John W. Eaton <jwe at octave.org> wrote:
>> | > On 22-Jan-2009, Shai Ayal wrote:
>> | >
>> | > | OK. But I don't know how hard it will be to make this cross platform.
>> | > | We might try to "steal" some code from fltk to discover the
>> | > | platform.
>> | >
>> | > Why?  This seems to be a compile-time thing.  We can discover if the
>> | > build system has X11, or is Windows, or is OS X, and then we just need
>> | > to know how to get the screen characteristics on those systems.  I
>> | > provided the example code for X11.  Now someone else needs to do the
>> | > same for Windows and
> OS X.
>> |
>> | Under Windows, it would be done using GetSystemMetrics and
>> | GetDeviceCaps functions.
>>
>> Does the following program do the right thing?
>>
>> Thanks,
>>
>> jwe
>>
>>
>> #include <iostream>
>>
>> #include <Windows.h>
>>
>> int
>> main (void)
>> {
>>  HDC hdc = GetDC (0);
>>
>>  if (hdc)
>>    {
>>      int ht = GetDeviceCaps (hdc, VERTRES);
>>      int wd = GetDeviceCaps (hdc, HORZRES);
>>
>>      std::cerr << wd << "x" << ht << " pixels" << std::endl;
>>
>>      double ht_mm = GetDeviceCaps (hdc, VERTSIZE);
>>      double wd_mm = GetDeviceCaps (hdc, HORZSIZE);
>>
>>      std::cerr << wd_mm << "x" << ht_mm << " mm" << std::endl;
>>
>>      double resy = wd * 25.4 / wd_mm;
>>      double resx = ht * 25.4 / ht_mm;
>>
>>      std::cerr << resx << " resx" << std::endl;
>>      std::cerr << resy << " resx" << std::endl;
>>
>>      std::cerr << (resx + resy) / 2 << " avg dpi" << std::endl;
>>
>>      int depth = GetDeviceCaps (hdc, BITSPIXEL)
>>
>>      std::cerr << depth << " bit depth" << std::endl;
>>    }
>>  else
>>    std::cerr << "failed to get device context" << std::endl;
>>
>>  return 0;
>> }
>>
>>
>
-------------- next part --------------
#include <iostream>

#include <Windows.h>

int
main (void)
{
  HDC hdc = GetDC (0);

  if (hdc)
    {
      int ht = GetDeviceCaps (hdc, VERTRES);
      int wd = GetDeviceCaps (hdc, HORZRES);

      std::cerr << wd << "x" << ht << " pixels" << std::endl;

      double ht_mm = GetDeviceCaps (hdc, VERTSIZE);
      double wd_mm = GetDeviceCaps (hdc, HORZSIZE);

      std::cerr << wd_mm << "x" << ht_mm << " mm" << std::endl;

      double resy = wd * 25.4 / wd_mm;
      double resx = ht * 25.4 / ht_mm;
      
      double resy_log = GetDeviceCaps (hdc, LOGPIXELSY);
      double resx_log = GetDeviceCaps (hdc, LOGPIXELSX);

      std::cerr << resx << " resx" << std::endl;
      std::cerr << resy << " resy" << std::endl;
      std::cerr << resx_log << " resx_log" << std::endl;
      std::cerr << resy_log << " resy_log" << std::endl;

      std::cerr << (resx + resy) / 2 << " avg dpi" << std::endl;

      int depth = GetDeviceCaps (hdc, BITSPIXEL);

      std::cerr << depth << " bit depth" << std::endl;

      ReleaseDC(0, hdc);
    }
  else
    std::cerr << "failed to get device context" << std::endl;

  return 0;
}


More information about the Octave-maintainers mailing list