Develop applications that use multiple displays in Delphi

zhaozj2021-02-17  48

Windows can map multiple dispenseumes into virtual desktops that allow us to use this to design and make an application for your work. For example, PowerPoint gives full play to the advantages of a dual display (most of the laptops), it can play slides on one display, and display memo on another display, you can control the process of playback, make the user to do business The speech is very waiting. So how do we develop this application? This article will show you if you use Delphi to use multiple display applications.

Windows also supports clone display, each display outputs the same content, which is also meaningful for some applications. Although some graphics cards also support two displays, they are not true in the true sense, but the virtual high resolution display mode (such as 2048 × 768 or 1024 × 1536), display the screen to two displays, respectively, by the graphics card on. Both display modes are not called ZHONGDIAN this article, and it is also very simple, so we will not let it go again.

Windows supports up to 10 monitors, and Windows maps all monitors to a large virtual desktop. You can understand the display as a partial view of the desktop. These displays can be arbitrarily arranged in accordance with the physical location of the display in the display attribute. If the display of the display is irregular, some parts on the virtual desktop may not be displayed on any display. In order not to make a form displayed between the two displays, Windows uses a display as a main display. When you start your computer, the login dialog is displayed in the main display. Most programs start show, they will be displayed in the main monitor.

According to the above introduction, it is not difficult to find several important concepts: desktop, display, main display, etc. First, you must first understand these concepts and their previous relationships. This is the focus of mastering multi-display applications development methods. Understand these concepts, other parts are very well understood.

The desktop actually refers to the logical area that Windows can display. In fact, you can display a form outside of the desktop. However, this is not that all parts of the desktop will appear on a display (whose reasons are as mentioned); but in turn, any display of any display is inevitably part of the desktop.

The desktop is a rectangular area that can be described by vertex coordinates (TOP, LEFT) and width. Why do you need a vertex coordinate? Because the vertex coordinates do not want to be of course (0, 0). So where is it (0, 0)? Say the length, let's take a look at a concept-main display just mentioned the concept that just mentioned. Windows hopes that the general program is initially displayed to the primary display because people are accustomed to paying attention to a display that is closest to their own. WINDOWS is not possible to force users to use one of the left sides as a primary display, so that in order to display itself to the main display, the application needs the calculation of the cost. However, most users have only one display (two displays are too places), and the general application does not want a large-scale meal to calculate where the main display is, what location should be displayed. So Windows puts forward a reasonable solution: the origin of the coordinate system with the vertex coordinates of the main display. In this way, ordinary programs need to be considered in the single display environment.

The display is a partial view of the desktop. It seems to be seen from the scenery outside the window, you can see different pictures before standing in different windows. Similarly, the display is also a rectangular area, which can also describe its size through vertex coordinates (TOP, LEFT), and width. The vertex coordinates are the origin of the desktop coordinate, that is, the vertices relative to the main display.

The concept of workspace is relatively simple, it refers to a rectangular area other than task bars and other forms on the table.

Windows provides a set of APIs for the development of multi-display applications. VCL encapsulates these APIs, which is naturally integrated into the entire Framework, making it very simple to develop multi-display applications. Here are the content related to it. In the VCL, everyone is most familiar with TCUSTOMFORM, it is the base class of all forms. The Position attribute of TCUSTOMFORM is used to set up the real location of the form. There are two in the optional value: one is POSCREENCENTER, and when the position property is set to POSCREENCENTER, the form will display the center of the main display; One is Podesktopcenter, when the Position property is set to Podesktopcenter, the form is displayed at the center of the entire desktop. If this property is set to Podesktopcenter, the program runs on a system with multiple monitors, then this window will display unnecessary trouble to the user in two displays. So even if our procedure is not designed for multi-displays, it should also be carefully processed. Another attribute is defaultmonitor, and its role is some similar to position, and the decision window is originally displayed in which display. It has four optional values: DMDESKTOP, DMPRIMARY, DMMAINFORM, and DMACTIVEFORM. Their meaning is as follows:

Value Meaning DMDesktop does not specifically process DMPRIMARY to display the form to the first display. This is another trap, literally understood is the main display, but in fact it refers to the display of Screen.Monitor [0]. DMMAINFORM Displays the form to the display DMActiveForm where the main form is located, display the display to the display on the table.

TCUSTOMFORM also has a read-only share attribute (no Published) Monitor, which provides a reference to the display instance where the form is located, this value is closely related to DefaultMonitor.

So how do you move the form between different displays? This is not difficult, it is estimated that you also thought. Here are two ways:

First, you can set TCUSTOMFORM TOP and LEFT to make the form on any location of the desktop. As mentioned earlier, the desktop consists of all the displays. They have a common coordinate system, so they can determine the location of the form based on the logical position of the display. The current problem is how to get the logical location and size of each monitor, and will be introduced later.

Second, you can call the TCUSTOMFORM's MakefullyVisible method to completely display the form to the specified display. You can avoid the window in the two displays by this method.

Just now, we have proposed a problem: how to get the logical position and size of each display. In order to understand this problem, you need to introduce a class: Tscreen and TMonitor.

Tscreen describes some information related to the display device, which we mainly care about information related to the display logic location and size. Other aspects can be known in Delphi documents. When the program is running, VCL automatically creates a TSCreen instance - global variable, so the program is not required to instantiate Tscreen.

Tscreen has a set of properties such as Desktop *, which describes the size of the entire desktop and vertex coordinates. There is also an enabled attribute for developing multi-display applications: MonitorCount and Monitors. Through these two attributes we can enumerate all instances of all the display in the system, each instance reflects information such as relative position and resolution of the corresponding display (later in detail later).

In the numerous properties of Tscreen, we will find two properties of Height and Width. It is important to be alert to the size of the entire desktop, but the height and width of the main display. This is very easy to make people feel illusions, nothing to be the size of the entire desktop. There is also a set of properties such as Workarea *, which describes the size of the work area of ​​the main display and a vertex coordinates. Do you feel less? Why not get the property of the relative position of the main display? The reason is as previously said: Windows is the origin of the main display in the upper left corner of the main display, so the relative position of the main display is inevitably (0,0). In addition to these properties, Tscreen's three member functions: MonitorFromPoint, MonitorFromRect, and MonitorFromWindow. As the name suggests, they are an instance of the display of a coordinate, a region, and a window. It may be used in actual development.

It is best to take a look at the TMONITOR class. It encapsulates the relevant properties of the physical displays - these properties are read-only. The following table briefly introduces the meaning of these properties, which is useful for writing multi-display applications:

Property Description Handle Gets the Windows Handle MonitorNum gets the number of the display primary gets whether the display is a main display. And only one display of Primary is TRUE. Top Gets the upper boundary of the display LEFT Get the left boundary of the display Height Get the high Width for the display to get the width of the display of the display, which is the area of ​​the corresponding desktop of the display, which is equivalent to WorkareArect Get the workspace of the monitor. Correspondence area.

After the Tscreen and TMonitor have been clearly understood, the previous problems will naturally be solved. Here, this article has introduced all the knowledge required to develop multi-display applications. I believe you can use this knowledge to develop a very practical software product.

Attachment: You can download a Demo to help understand this article.

转载请注明原文地址:https://www.9cbs.com/read-28647.html

New Post(0)