----Because window 95 adds support for the concept of the Windows area, the window area is the shape that the window appears to be, the window area as the actual boundary area of the window, so that the window area not only defines the window's area of painting, Also defines the hidden area under the window and the response window area in response to the mouse keystroke event.
The various shapes----buttons are set at run time rather than at design time. The shape of the button at design time is still rectangular or square.
The design of a----button shape is divided into two steps.
----The first step is to create the shape of the button, which defines the window area. Use the area creation function of the API to achieve the goal. There are many area creation functions, mainly CreateEllipticRgn, CreatePolygonRgn, CreateRectRgn, CreateRoundRectRgn, to create different types of area display. If you need a complex area shape, you can create different areas by using different zone functions, and then call the Combinergn API functions to combine them. So, not only can you create a garden-shaped, triangular button, but you can also create buttons for various other shapes.
----The second step, apply the area display to the window. Once you have created a new area display using the area function, you can use the SETWINDOWSRGN function to apply the area to the window.
----below gives the concrete code for the implementation of the circular and triangular buttons. To visually display the effect, set the background color of the form to black (color set to Clbtntext) and set the cursor of the two buttons crcross. Place two button buttons on the form, defined as Rbutton, TButton, respectively. The best time to implement the window area is to place the handler in the OnCreate event when the form is first created
In
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//创建园形按钮
HRGN hRgnR = CreateEllipticRgn(0,0,RButton->
Width,RButton->Height);
SetWindowRgn(RButton->Handle,hRgnR,TRUE);
//创建三角形按钮
TrPoint[0].x=TButton->Width/2;
TrPoint[0].y=0;
TrPoint[1].x=0;
TrPoint[1].y=TButton->Height;
TrPoint[2].x=TButton->Width;
TrPoint[2].y=TButton->Height;
HRGN hRgnT = CreatePolygonRgn(TrPoint,3,ALTERNATE);
SetWindowRgn(TButton->Handle,hRgnT,TRUE);
}
The trpoint is defined in the Unit.h header file as follows:
Private://User declarations
Point Trpoint[3];
----The above code creates a garden area and a triangular area, respectively, within the bounds of the button, and assigns it to its respective buttons as a new window area. When you create a garden button, you use an oval-shaped area to create a function, so that the button is landscaped and designed to be square. In addition, the area is defined in the form of a button coordinate, not the screen coordinates. The (0,0) point is the top-left corner of the button, and the (wide, high) point is the lower-right corner of the button.
----should note that once the area handle is assigned to the button, no more action can be taken on the area handle. If you assign an area handle to a button, modifying or deleting the handle will cause the program to crash.
The----cursor changes to Crcross shapes only within the garden and triangle regions. To make the button beautiful you can use the BITBTN or Speedbutton button to attach a bitmap to the button. Refer to the Win32sdk.hlp Help file for the use of API area functions.