Loading ...
Sorry, an error occurred while loading the content.

Finding physical screen size

Expand Messages
  • Tim Hewitt
    Can anyone help please ? I have a large Liberty Basic 4.04 program which I use for drawing maps in various map projections via a graphics box. I Want to use
    Message 1 of 8 , Apr 8, 2012
    • 0 Attachment
      Can anyone help please ?



      I have a large Liberty Basic 4.04 program which I use for drawing maps in
      various map projections via a graphics box. I Want to use this software on
      different computers, but then I obviously need to scale the output for the
      appropriate screen size.



      Liberty Basic gives me the screen size in pixels via WindowWidth and
      WindowHeight, so I can easily scale the graphics. However, the maps have a
      lot of text labelling on them, and I need to scale the font size depending
      on screen height. Is there any way LB can find and return the screen
      dimensions in actual inches or alternatively give me the relevant dpi figure
      for the particular screen ?



      Any help would be much appreciated,



      Tim





      [Non-text portions of this message have been removed]
    • Stefan Pendl
      ... At the bottom find a handy function to get the screen scale. BTW, DisplayHeight and DisplayWidth give you the size of the screen, but the taskbar or any
      Message 2 of 8 , Apr 9, 2012
      • 0 Attachment
        Am 09.04.2012 17:11, schrieb Lorne Russell:
        > To get the dpi setting
        > ----------------------
        >
        > calldll #user32, "GetDC",_
        > 0 as ulong,_ ' entire screen
        > hDC as ulong
        >
        > nIndex = _LOGPIXELSX
        >
        > calldll #gdi32, "GetDeviceCaps",_
        > hDC as ulong,_
        > nIndex as ulong,_
        > dpi as ulong
        >
        > calldll #user32, "ReleaseDC",_
        > 0 as ulong,_ ' entire screen
        > hDC as ulong,_
        > result as ulong ' 1 = success
        >
        >
        > Lorne Russell
        >

        At the bottom find a handy function to get the screen scale.

        BTW, DisplayHeight and DisplayWidth give you the size of the screen, but
        the taskbar or any other bar displayed is not taken into account.

        WindowWidth and WindowHeight only give you the size of the window.

        To get the size of the screen without any area covered by a tool bar,
        use the following code.

        '---code start (watch for line wraps)

        struct RECT, _
        left as long, _
        top as long, _
        right as long, _
        bottom as long

        uiAction = _SPI_GETWORKAREA

        calldll #user32, "SystemParametersInfoA", _
        uiAction as ulong, _
        uiParam as ulong, _
        RECT as struct, _
        fWinIni as ulong, _
        result as long

        PosLeft = RECT.left.struct
        PosTop = RECT.top.struct
        PosRight = RECT.right.struct
        PosBottom = RECT.bottom.struct

        '---code end


        '---code start (watch for line wraps)

        print GetScreenScale()
        end

        function GetScreenScale()
        calldll #user32, "GetDC",_
        0 as ulong,_ ' entire screen
        hDC as ulong

        nIndex = _LOGPIXELSX

        calldll #gdi32, "GetDeviceCaps",_
        hDC as ulong,_
        nIndex as ulong,_
        dpi as ulong

        calldll #user32, "ReleaseDC",_
        0 as ulong,_ ' entire screen
        hDC as ulong,_
        result as ulong ' 1 = success

        GetScreenScale = dpi / 96
        end function

        '---code end

        --
        Stefan Pendl
        http://stefanpendl.runbasichosting.com/

        LB 4.04 Pro ... http://www.libertybasic.com/assist.html
        LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

        LB Community Wiki .............. http://basic.wikispaces.com/
        LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
        LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

        Books at http://www.lulu.com/ and http://www.amazon.com/
        Alyce Watson ... APIs for Liberty BASIC
        Carl Gundel .... Beginning Programming with Liberty BASIC

        Windows 7 Home Premium 64-bit SP1
        AMD Turion X2 RM-70 2GHz, 4GB RAM
      • Tim Hewitt
        My sincere thanks Harry, Lorne and Stephan for the quick responses to my question on dpi etc. I have tried out the dlls provided by Lorne and Stephan. However,
        Message 3 of 8 , Apr 10, 2012
        • 0 Attachment
          My sincere thanks Harry, Lorne and Stephan for the quick responses to my
          question on dpi etc.



          I have tried out the dlls provided by Lorne and Stephan. However, whilst
          these both work very well indeed and both offer refinements that I will
          build in to my software, they did not solve my immediate problem. The fault
          was mine, in that I did not appreciate the particular significance of the
          term "dpi" in the Windows screen context. In fact I had actually asked the
          wrong question, and for my purposes I now realize that I needed to determine
          the "pixels per inch" (ppi), not dpi, as these are different things. If
          there is a means of determining the ppi of a screen it would be very useful
          indeed.



          I come from a time of typing pools, Letraset, Tipp-Ex and daisy wheel
          printers when a "point" was simply 1/72 inch. I also did not realize how
          "point size" had subtly changed its meaning as type and graphic design had
          transitioned into the digital era. I am wiser now thanks to your help and
          see I need to think of font size in terms of the number of pixels needed to
          form the character shape. Having got things straight in my mind after much
          reading last night, I understood the usefulness of the table that Harry sent
          in his reply, and I can certainly now use this to get to 90% of what I need.



          Again, thanks for your help,



          Tim











          [Non-text portions of this message have been removed]
        • Stefan Pendl
          ... There is no difference between DPI (dots-per-inch) and PPI (pixels-per-inch), they are both exactly the same, just called differently. A dot is a pixel on
          Message 4 of 8 , Apr 10, 2012
          • 0 Attachment
            Am 10.04.2012 14:26, schrieb Tim Hewitt:
            >
            > I have tried out the dlls provided by Lorne and Stephan. However, whilst
            > these both work very well indeed and both offer refinements that I will
            > build in to my software, they did not solve my immediate problem. The fault
            > was mine, in that I did not appreciate the particular significance of the
            > term "dpi" in the Windows screen context. In fact I had actually asked the
            > wrong question, and for my purposes I now realize that I needed to determine
            > the "pixels per inch" (ppi), not dpi, as these are different things. If
            > there is a means of determining the ppi of a screen it would be very useful
            > indeed.
            >

            There is no difference between DPI (dots-per-inch) and PPI
            (pixels-per-inch), they are both exactly the same, just called differently.

            A dot is a pixel on the screen.

            The DLLs are part of every Windows installation, since they are shipping
            with Windows and you won't be able to run any other software if they are
            missing too.


            --
            Stefan Pendl
            http://stefanpendl.runbasichosting.com/

            LB 4.04 Pro ... http://www.libertybasic.com/assist.html
            LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

            LB Community Wiki .............. http://basic.wikispaces.com/
            LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
            LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

            Books at http://www.lulu.com/ and http://www.amazon.com/
            Alyce Watson ... APIs for Liberty BASIC
            Carl Gundel .... Beginning Programming with Liberty BASIC

            Windows 7 Home Premium 64-bit SP1
            AMD Turion X2 RM-70 2GHz, 4GB RAM
          • Sarmed Shakir
            Dear Sir, Use DisplayHeight, DisplayWidth instead of WindowHeight, WindowWidth. The following example may be help. code started ----------------  
            Message 5 of 8 , May 6 11:41 PM
            • 0 Attachment
              Dear Sir,

              Use DisplayHeight, DisplayWidth instead of WindowHeight, WindowWidth. The following example may be help.

              'code started ----------------
                ' nomainwin
                UpperLeftX = INT((DisplayWidth-WindowWidth)/2): UpperLeftY = 50
                  button #graph, "Exit", [exit], LR, 35, 20'window will have a button
                  print "DisplayHeight= "; DisplayHeight
                  print "DisplayWidth= "; DisplayWidth
                  open "Example" for graphics as #graph    'open graphics window
                [inputLoop]
                  input b$ : goto [inputLoop]              'wait for button press
                [exit]
                  close #graph
                end 
              'code End ------------------            

              Best Regards
              SARMED 


              ________________________________
              From: Tim Hewitt <tim.hewitt@...>
              To: libertybasic@yahoogroups.com
              Sent: Sunday, April 8, 2012 7:38 PM
              Subject: [libertybasic] Finding physical screen size


               
              Can anyone help please ?

              I have a large Liberty Basic 4.04 program which I use for drawing maps in
              various map projections via a graphics box. I Want to use this software on
              different computers, but then I obviously need to scale the output for the
              appropriate screen size.

              Liberty Basic gives me the screen size in pixels via WindowWidth and
              WindowHeight, so I can easily scale the graphics. However, the maps have a
              lot of text labelling on them, and I need to scale the font size depending
              on screen height. Is there any way LB can find and return the screen
              dimensions in actual inches or alternatively give me the relevant dpi figure
              for the particular screen ?

              Any help would be much appreciated,

              Tim

              [Non-text portions of this message have been removed]




              [Non-text portions of this message have been removed]
            Your message has been successfully submitted and would be delivered to recipients shortly.