Implement "non-typical" form with API functions in Delphi
Some of the current sharing software, especially some multimedia player software, in order to attract users, very focused on the design of the program interface. In fact, we can use the API function to achieve those and alternative effects.
Alien form
Can the form can only be a party? No, there can be other shapes. This is used to use two Win32 API functions. First, use the CreateroundRectrGn () function to define an elliptical area within the form. The region referred to herein is a special API object, we can fill and cut in the area to define external features of the form. Then call the setWindowRGN () function to draw, and further use the COMBinerGN () function to merge multiple zones, such as adding the following code in the Delphi unit file:
Procedure TFORM1.FormCreate (Sender: TOBJECT);
VAR
Fregion1: thandle;
Fregion2: thandle;
Begin
Fregion1: = CreateroundRectrGN (20, 20, 200, 200, 300, 300); // Define an ellipse area
Fregion2: = CreateRectrGN (170, 170, 400, 400); // Define a rectangular area
Combinergn (Fregion1, Fregion1, Fregion2, RGN_OR); // Connecting two regions
SetwindowRgn (Handle, Fregion1, True); / / Drawing the connected area
END;
The CreateroundRectRGN () function in the block is used to create a rounded rectangular area, and its prototype is:
HRGN CREATEROUNDRGN
INT NLEFTRECT, / / X coordinate in the upper left corner
INT NTOPRECT, / / Y coordinate in the upper left corner
INT NRIGHTRECT, / / X coordinate in the lower right corner
INT nbottomRect, // Y coordinate in the lower right corner
Int nwidthellipse, // rounded in ellipse
INT NHEIGHTELLIPSE / / Rounded in ellipse
);
Other graphics such as polygons, ellipses, etc. have corresponding API functions, their prototypes as follows:
HRGN CREATEELLIPTICRGN (int NLEFTRECT, INT NTOPRECT, INT NRIGHTRECT)
HRGN CREATEELLIPTICRGNINDIRECT (Const Rect * LPRC)
HRGN CREATEPOLYGONRGN (Const Point * LPPT, INT CPOINTS, INT FNPOLYFILLMODE)
HRGN CREATEPOLYPOLYGONRGN (Const Point * LPPT, Const Int * LPPOLYCOUNTS, INT NCOUNT, INT FNPOLYFILLMODE)
HRGN CreateRectrgn (int NLEFTRECT, INT NTOPRECT, INT NRIGHTRECT, INT NBOTTOMRECT)
HRGN CREATERECTRGNIIRECT (Const Rect * LPRC)
The parameters of the above functions are well understood, used to explain the coordinates of the graphic built-in rectangle or point to the rectangle. Take a look at the other two functions:
Function prototype: setWindowRgn
HWND HWND, // Current Form Handle
HRGN HRGN, / / Current Handle
Bool brew, // redraw signs
)
Function function: This function passes the handle of the created area as a parameter to the current form handle and draws a form within the area;
Function prototype: Combinergn (HRGN HRGNDEST, // handle of the area
HRGN HRGNSRC1, / / The handle of the first connection source area
HRGN HRGNSRC2, / / Second Connection Source Area Handle
INT FNCOMBINEMODE // Connection mode
)
Function function: This function combines two areas into a new area, where the connection mode can take the following value:
Parameter value
RGN_AND is created from the total part of the area 1 and the area 2, which is intended to create a new area.
RGN_COPY Create a copy of the area 1 as a new area
RGN_DIFF connection is part of the region 1 but does not belong to the area 2 is a new area
All parts of the RGN_OR connection area 1 and region 2 are set
RGN_XOR. All parts of the connection area 1 and region 2 are removed and
2. Hollow form
This form is characterized by a good end of the end, and the intermediate is dug a part. For example, add the following code in the unit file of Delphi:
Procedure TFORM1.FormCreate (Sender: TOBJECT);
VAR
Fregion3: thandle;
Begin
Canvas.Font.name:= 'Huawen line "; // set font
Canvas.Font.size: = 100; // Set the font size
Beginpath (canvas.handle); // Get the outline drawn on Vanvas
Textout (Form1.canvas.Handle, 0, 20, 'program Spring and Autumn ", 8); // Put the" Procedure Spring and Autumn "four words
Endpath (canvas.handle);
Fregion3: = pathtoregion (canvas.handle); // assigns the above area to the form
SetwindowRgn (Handle, Fregion3, True); // Start
END;
Here mainly uses three API functions:
Function prototype: BOOL BeginPath (HDC HDC // Equipment Environment Handle)
Function function: Start receiving the path trajectory of the current device environment;
Function prototype: BOOL Endpath (HDC HDC // Equipment Environment Handle)
Function function: Stop receiving and transmitted the received path track to the current device environment
Function prototype BOOL TEXTOUT
HDC HDC, // Handle of Device Context
INT NxStart, / / The X coordinate of the start position
INT NYSTART, / / The y coordinate of the start position
LPCTSTR LPSTRING, / / String Address
INT CBString // String contains the number of characters (note a Chinese word for two characters)
)
Function function: Draw a given string in the specified location.
Summary: Society is skilled in using the API to program, it is a very important skill, sometimes achieving unexpected effects. The above several techniques are designed to throw bricks, I hope everyone can make full use of various techniques, play their own imagination, design a dazzling form, beautify their procedures. If you have any questions, welcome to your letter (e-mail: iam229@sohu.com).