Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get screen resolution
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00471746
Message ID:
00471785
Views:
11
>Hello,
>I figured out a way to get the screen resolution for the device, using GetDeviceCaps in Gdi32.dll.
>
>Maybe someone is interested, or someone may like to put it in the API lib (I do not know how to do this), or someone has a better way of doing this.
>
>Here is an example:
>
>PROCEDURE GetScreenResolution
>*-- Create an object:
>LOCAL loScreenResolution
>loScreenResolution = NEWOBJECT("Relation")
>*
>WITH loScreenResolution
> .ADDPROPERTY("Horizontal", 0)
> .ADDPROPERTY("Vertical", 0)
> .ADDPROPERTY("HorzResConstant", 8)
> .ADDPROPERTY("VertResConstant", 10)
> .ADDPROPERTY("ActiveWindow", 0)
> .ADDPROPERTY("DeviceContext", 0)
>ENDWITH
>*
>*-- Get a handle on the active window.
>DECLARE INTEGER GetActiveWindow IN Win32API
>loScreenResolution.ActiveWindow = GetActiveWindow()
>*
>DECLARE INTEGER GetDCEx IN User32.dll INTEGER, INTEGER, INTEGER
>loScreenResolution.DeviceContext = GetDCEx(loScreenResolution.ActiveWindow, 0, 0)
>DECLARE INTEGER GetDeviceCaps IN Gdi32.dll INTEGER, INTEGER
>*
>*-- The api calls.
>loScreenResolution.Horizontal = GetDeviceCaps(loScreenResolution.DeviceContext, loScreenResolution.HorzResConstant)
>loScreenResolution.Vertical = GetDeviceCaps(loScreenResolution.DeviceContext, loScreenResolution.VertResConstant)
>*
>*-- The result.
>?loScreenResolution.Horizontal
>?loScreenResolution.Vertical
>*
>ENDPROC
>
>You can use this function to return other values, using different constants like those:
>
>' Device Parameters for GetDeviceCaps()
>Public Const DRIVERVERSION = 0 ' Device driver version
>Public Const TECHNOLOGY = 2 ' Device classification
>Public Const HORZSIZE = 4 ' Horizontal size in millimeters
>Public Const VERTSIZE = 6 ' Vertical size in millimeters
>Public Const HORZRES = 8 ' Horizontal width in pixels
>Public Const VERTRES = 10 ' Vertical width in pixels
>Public Const BITSPIXEL = 12 ' Number of bits per pixel
>Public Const PLANES = 14 ' Number of planes
>Public Const NUMBRUSHES = 16 ' Number of brushes the device has
>Public Const NUMPENS = 18 ' Number of pens the device has
>Public Const NUMMARKERS = 20 ' Number of markers the device has
>Public Const NUMFONTS = 22 ' Number of fonts the device has
>Public Const NUMCOLORS = 24 ' Number of colors the device supports
>Public Const PDEVICESIZE = 26 ' Size required for device descriptor
>Public Const CURVECAPS = 28 ' Curve capabilities
>Public Const LINECAPS = 30 ' Line capabilities
>Public Const POLYGONALCAPS = 32 ' Polygonal capabilities
>Public Const TEXTCAPS = 34 ' Text capabilities
>Public Const CLIPCAPS = 36 ' Clipping capabilities
>Public Const RASTERCAPS = 38 ' Bitblt capabilities
>Public Const ASPECTX = 40 ' Length of the X leg
>Public Const ASPECTY = 42 ' Length of the Y leg
>Public Const ASPECTXY = 44 ' Length of the hypotenuse

Christian,

The screen resolution and other information about Windows can be retrieved via SYSMETRIC(1) (Horizontal resolution) and SYSMETRIC(2) (Vertical resolution). The function basically maps to GetSystemMetrics(), which can be used as an alternative API call to the above for screen resolution, without having to retrive a device context.
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform