How we can get Screen size of device in C++ Builder? What are the properties of a Screen? Can we use Screen in Multi-Device applications? In this post, we will explain some of important properties of Screen class.
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files and LSP support for code. C++ Builder comes with Rapid Application Development Studio, also known as RAD Studio, and C++ Builder is one of the most professional IDE’s that work under RAD Studio. It is the oldest IDE (it began as Borland TurboC in 1990 and was later renamed Borland C++ Builder). Under the Embarcadero brand it comes with new versions, features, updates and support. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs. There is a free C++ Builder Community Edition for students, beginners and startups.
Table of Contents
The C++ Builder Community Edition makes learning C++ a no-cost activity
You can download the free C++ Builder Community Edition here: https://www.embarcadero.com/products/cbuilder/starter.
Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. Please visit https://www.embarcadero.com/products/cbuilder.
The screen is your user’s primary method of interacting with your application
The Screen and size of the application is sometimes needed to check number of current pixels in X and Y longitudes. It is also good to understand what kind of screen user is using, so you can arrange your UI elements, you can change some of size of elements. C++ Builder is a great IDE and development environment that allows you to align all your layouts, panels, group items and all other UI elements to the left, right up, down, center, client etc. Both FireMonkey and VCL UI frameworks support this well and you don’t need to check windows size or screen size etc. Sometimes, rarely we need this information to display some kind of UI elements, or we may use very specific different layouts for different screen sizes. Sometimes we need this to draw into full screen bitmaps, or for the other drawing tools.
Screen size and number of available colors on a device (a desktop computer, a mobile device, a tablet or IoT) is configurable and dependent on the hardware installed. These attributes are also likely to differ on the deployment computer compared to those on the development computer.
An application’s appearance (window, object, and font sizes) on computers configured for different screen resolutions can be handled in various ways:
The C++ Screen component has all you need to know
The Screen represents a screen device in other terms represents the screen of the system on which the application runs. By default, applications create a screen component based on information about the current screen device and assign it to Screen.
Use Screen to obtain a list of displays used to comprise the desktop, coordinates, dimensions, and other properties of displays. The DisplayCount property returns the number of displays and Displays provides an access to properties of all displays. See also Multiple Display Support
For example we get size of the screen as below,
What is the DisplayCount property used for in C++ Builder?
We can use DisplayCount to get the number of displays used to comprise the desktop.
Your application creates a global Screen variable encapsulating the state of the screen on which your application is running. The DisplayCount property of Screen returns the number of displays used to comprise the desktop. DisplayCount is the number of displays in the Displays array of Screen. DisplayCount gets information from FMX.Platform.IFMXMultiDisplayService.DisplayCount.
We can get count of displays and we can get more information from each display as below,
Everything you need for counting and manipulating displays
Displays is the array of displays used to comprise the desktop. Displays provides access to individual displays used to comprise the desktop on which an application runs.
our application creates a global Screen variable, of type TScreen, encapsulating the state of the screen on which your application is running. Use the Displays property of Screen to obtain an array of displays used to comprise the desktop. The DisplayCount property of Screen returns the number of displays. The display with its Primary property set to True
is the primary display.
Displays gets information from FMX.Platform.IFMXMultiDisplayService.Displays.
What is the TScreenOrientation property?
The TScreenOrientation Defines the screen or form orientations that are available for devices that support this feature (for instance, an iPad or an iPhone). The TScreenOrientation type defines the following constants:
Constant | Meaning |
---|---|
Portrait | Portrait (or vertical) screen/form orientation. |
Landscape | Landscape (or horizontal) screen/form orientation. |
InvertedPortrait | Screen/form is in vertical orientation but upside down, with the device held upright and the home button at the top. (Under iOS) |
InvertedLandscape | Screen/form is in horizontal orientation but upside down, with the device held upright and the home button at the left side. (Under iOS) |
The TPlatformServices class is your cross-platform information power-house
TPlatformServices is a class that can be used to determine the services that are available on the platform on which your application is running. We can use TPlatformServices in order to determine the services that are available on the run-time platform, and also to enable and use those services in your application. For instance, you could check if a virtual keyboard service is available on an OS X running computer and the results would be negative, while on Windows the virtual keyboard service is available.
We can use _di_IFMXScreenService to get Screen Service information, we can get ScreenSize, ScreenScale and ScreenOrientation features by using GetScreenSize(), GetScreenScale() and GetScreenOrientation() methods. See example below;
Here is a full FireMonkey example that gives information about full screen size and form size with different properties
You can download a free trial of C++ Builder from the following link, today: https://www.embarcadero.com/products