Getting Started with Win32 development (23): Gradient Color Fills

Source: Internet
Author: User
Tags win32

The GradientFill function can be filled with a gradient color for a particular rectangular region or a triangular region. Let's look at what the GradientFill function looks like, not handsome.

BOOL GradientFill (  
  _in_  HDC HDC,  
  _in_ ptrivertex pvertex  ,  
  _in_  
  ULONG Nvertex, _in_  pvoid Pmesh,  
  _in_  ULONG nmesh, _in_ ULONG  
);

Arguments involve structs, and some people begin to feel pain, and the call function suffers when it encounters a struct, which is more painful and has an array of structures.

The Dharma founder said that pain is your business, not with the API, it is not because of your pain will become easy to use, the simple is simple, the complex is still so complex. Let's analyze One. First HDC will not need me to say, is a context, this context you understand for who is related to, who is the handle, the handle is a resource identification, said before, just like the identity card number can uniquely identify your identity general (except fake ID). So, this hdc is to decide where you want to draw the gradient color, draw to the window is the HDC of the window, painted on the desktop is the desktop hdc.

The second parameter, note, is an array of trivertex structures, in which each Trivertex variable in the array specifies the coordinates and color of a gradient point, the color is ARGB four channels, which means you can play the transparency effect, a,r,g,b the range of each value, On MSDN There is a description of the color information of the of each channel are specified as a value from 0x0000 to 0xff00, which is in decimal to indicate how much, open "calculator" to calculate Know, Win7 after the calculator program is very powerful, used to fortune-telling can, let alone into the system conversion.

If you write more C + + programs, you will guess what the third parameter is, which involves passing an array as a parameter, and then definitely take a parameter to indicate how many elements are in the array. Because the C-language array is different from the managed language, in fact it is changeable, you define int a[3] ..., and then you assign value, assign to a[5] all can, although will be an error, but you may try, even if the error, but still can take the value, because the memory distribution is continuous.

Needless to say, the Nvertex is to indicate the number of the front Pvertex, and then a pmesh is an array of structures, but it is "male and female," can be an array of gradient_triangle structures, or an array of gradient_rect structures, Specific depends on how you want to fill, from the name know, Gradient_triangle is a triangular fill, is filled with the area is triangular, this should be good understanding, is the shape of your underwear; and gradient_rect better understand, the rectangle, is the primary school teacher taught you the rectangle Square.

Then this nmesh parameter you must know, do not explain, you understand.

The last parameter is to specify how to fill, nothing more than the level of filling in the past, or vertical fill in the sort of.

So how does a Trivertex array correspond to an array of gradient_rect or Gradient_triangle?

Gradient_triangle is defined as a triangle, it takes three points to determine a triangle, so these points come from the Trivertex array, and each Trivertex variable defines a point.

For example, the Trivertex array has six elements, there are six points, just can define two triangles, gradient_triangle three members is the triangle three points index, which is Trivertex array of elements of the index, six points, index is 0,1,2 , 3,4,5, and then, if the three members of the first Gradient_triangle are set to 0,1,2, then the first three points in the six point are defined with the initial triangle, and if the three members of the second gradient_triangle are set to 3,4,5, The last three points in a six point form a triangle. In the case of 1,4,5, the second of the six dots, the fifth and sixth points will form a triangle.

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.