Function with a gradient filling rectangle

xiaoxiao2021-03-06  18

The following code is primarily derived from a part of the code in the Static control that populates DC with a progressive color. This is to use the function prototype: typedef UINT (CALLBACK * LPGNDLLFUNC) (HDC, CONST PTRIVERTEX, DWORD, CONST PVOID, DWORD, DWORD); HINSTANCE hinst_msimg32 = NULL; static LPGNDLLFUNC pdllfunc_GradientFill; Initialization: hinst_msimg32 = LoadLibrary ( "msimg32.dll "); if (hinst_msimg32) {pdllfunc_GradientFill = ((LPGNDLLFUNC) GetProcAddress (hinst_msimg32," GradientFill "));} function definition: / * * on pDCMem fills a rectangular area pRect * pDcMem in FillMode mode to draw DC * pRect For the rectangular area * FillMode, the lateral filling and longitudinal filling two * cr HiRolor is the one end of the gradient, and the other end shows whether the white * Breverse reversely fill, ie the white gradient to Cfhicolor or by Croid DrawGradientfill (CDC) * pDCMem, CRect * pRect, BackFillMode FillMode, COLORREF crHiColor, BOOL bReverse) {TRIVERTEX rcVertex [2]; COLORREF crLoColor = RGB (255,255,255); if (bReverse) {crLoColor = crHiColor; crHiColor = RGB (255,255,255);} rcVertex [ 0] .x = prect-> left; rcvertex [0] .y = prect-> top; rcvertex [0] .red = getRvalue (crlocolor) << 8; rcvertex [0] .Green = getgvalue (crlocolor) << 8; RCVERTEX [0] .boe = getbvalue (crlocolor) << 8; rcvertex [0] .alpha = 0x0000; RCVERTEX [1] .x = prect-> Right; RcVertex [1] .y = prect-> bottom; rcvertex [1] .red = getRvalue (cr HiColor) << 8; rcvertex [1] .green = getgvalue (cr HiColor) << 8; RcVERTEX [1] .boe = getBValue crHiColor) << 8; rcVertex [1] .Alpha = 0; GRADIENT_RECT grect; grect.UpperLeft = 0; grect.LowerRight = 1; (pdllfunc_GradientFill) ((HDC) * pDCMem, (CONST PTRIVERTEX) rcVertex, (DWORD) 2 , (Const PVOID) & GRECT, (DWORD) 1, (DWORD) (FillMode == HGRADIENT? GRADIENT_FILL_RECT_H: GRADIENT_FILL_RECT_V));} To implement the gradient of the two colors, it is slightly modified. There is a gradientfill function in the MSDN, and the filling of any polygon can be used in a similar manner, the specific function, and the method of use MSDN.

转载请注明原文地址:https://www.9cbs.com/read-41815.html

New Post(0)