Winapi: createpolypolygonrgn-create an area composed of multiple Polygon

Source: Internet
Author: User
Tags textout
In this example:


Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) Procedure formclick (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} var F: Boolean = false; Procedure tform1.formclick (Sender: tobject); const n = 50; var PS: array [0 .. 6] of tpoint; NS: array [0 .. 1] of integer; RGN: hrgn; I: integer; begin refresh; PS [0]: = point (N, N Div 2); PS [1]: = point (n, clientheight-N); PS [2]: = point (clientwidth-N, clientheight-N); PS [3]: = point (clientwidth-N, N Div 2); PS [4]: = point (clientwidth Div 2, n); PS [5]: = point (N Div 2, clientheight-N Div 2 ); PS [6]: = point (clientwidth-N Div 2, clientheight-N Div 2); NS [0]: = 4; NS [1]: = 3; {create a region composed of multiple polygon} if F then begin RGN: = createpolypolypolygonrgn (Ps, NS, length (NS), winding); text: = 'fill mode: winding '; end else begin RGN: = createpolypolygonrgn (Ps, NS, length (NS), alternate); text: = 'fill mode: alternet'; end; F: = not F; {fill area} canvas. brush. color: = clsilver; canvas. brush. style: = bscross; fillrgn (canvas. handle, RGN, canvas. brush. handle); {draw area boundary} canvas. brush. color: = clred; canvas. brush. style: = bssolid; framergn (canvas. handle, RGN, canvas. brush. handle, 2, 2); canvas. brush. color: = self. color; for I: = 0 to length (PS) Do canvas. textout (PS [I]. x, PS [I]. y, inttostr (I); deleteobject (RGN); end.
 
   
 

The following "Old A123" requires a dynamic array, which can be changed to this:

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) Procedure formclick (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} var F: Boolean = false; Procedure tform1.formclick (Sender: tobject); const n = 50; var PS: array of tpoint; NS: array of integer; RGN: hrgn; i: integer; begin setlength (Ps, 7); setlength (NS, 2); refresh; PS [0]: = point (N, N Div 2 ); PS [1]: = point (n, clientheight-N); PS [2]: = point (clientwidth-N, clientheight-N); PS [3]: = point (clientwidth-N, N Div 2); PS [4]: = point (clientwidth Div 2, n); PS [5]: = point (N Div 2, clientheight-N Div 2); PS [6]: = point (clientwidth-N Div 2, clientheight-N Div 2); NS [0]: = 4; NS [1]: = 3; {create a region composed of multiple polygon} if F then begin RGN: = createpolypolygonrgn (PS [0], NS [0], length (NS), winding); text: = 'fill mode: winding'; end else begin RGN: = createpolypolygonrgn (PS [0], NS [0], length (NS), alternate); text: = 'fill mode: alternet'; end; F: = not F; {fill area} canvas. brush. color: = clsilver; canvas. brush. style: = bscross; fillrgn (canvas. handle, RGN, canvas. brush. handle); {draw area boundary} canvas. brush. color: = clred; canvas. brush. style: = bssolid; framergn (canvas. handle, RGN, canvas. brush. handle, 2, 2); canvas. brush. color: = self. color; for I: = 0 to length (PS) Do canvas. textout (PS [I]. x, PS [I]. y, inttostr (I); deleteobject (RGN); end.
 
  
 

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.