Using API function to realize polymorphic form in Delphi

Source: Internet
Author: User
Tags definition function prototype

It is not difficult to realize the special form, this article will show you how to use the API function to achieve rounded rectangle and oval form, and on this basis to explore the realization of the descendants of the Twincontrol class.

To change the form shape, that is, to achieve the control of the region (region). The definition of the area (region) in the WIN32 API program reference manual is described as follows: It can be a rectangle, a polygon, an ellipse (or a combination of both, or more), which can be filled, drawn, flipped, structured and subject to focus execution.

The definition concludes that the region (region) can be changed and manipulated to define the region according to our requirements and to produce the shape we require.

It should be noted that the region (region) can also define and control the descendants of any Twincontrol class (not just forms), that is, the definition of the region (region) can be applied to objects such as Tpanel or Tedit. When you change the shape of a descendant control of a Twincontrol class, you need to provide a handle and create some function that changes the shape.

The concrete realization way generally divides into two steps:

1. Define the area boundary shape (for example, oval) of the desired shape.

2. Applies the defined area boundary shape to the window.

Here, we will complete the above two steps by calling the Windows API function, which is described below for the application of the specific function:

To implement the first step: define the zone boundaries.

The three winapi are called here, and the three functions are:

The CreateEllipticRgn () function is to generate an elliptical region;

CreateRoundRectRgn () function is to generate rounded rectangular region;

The CreatePolygonRgn () function is to generate the polygon area, and Windows ensures that its vertices are automatically connected to form a closed area.

These three functions are identified by the returned pointer variable, and the resulting region is applied by the second step. The function declarations and parameter meanings of these functions in Delphi are described as follows:

(1) Oval region generating function:

Function prototype: hrgn createellipticrgn (int nleftrect,int ntoprect,int nrightrect,int nbottomrect);

Parameter meaning:

Nleftrect,ntoprect: The upper left corner coordinate of the region;

Nrightrect, Nbottomrect: The lower right corner coordinate of the region;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.