Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradient Brush in Native C++?

Tags:

c++

native

winapi

In c#, you can use drawing2d.lineargradientbrush, but in c++ right now I only found the CreateSolidBrush function. Is there a function in the native gdi dll to create a gradient brush? I couldn't find anything like this at msdn. Thanks

like image 904
jmasterx Avatar asked Oct 28 '25 08:10

jmasterx


2 Answers

To draw a vertical gradient:

void VerticalGradient(HDC hDC, const RECT& GradientFill, 
                      COLORREF rgbTop, COLORREF rgbBottom)
{
    GRADIENT_RECT gradientRect = { 0, 1 };
    TRIVERTEX triVertext[ 2 ] = {
        GradientFill.left - 1,
        GradientFill.top - 1,
        GetRValue(rgbTop) << 8,
        GetGValue(rgbTop) << 8,
        GetBValue(rgbTop) << 8,
        0x0000,         
        GradientFill.right,
        GradientFill.bottom,
        GetRValue(rgbBottom) << 8,
        GetGValue(rgbBottom) << 8,
        GetBValue(rgbBottom) << 8,
        0x0000
    };
    GradientFill(hDC, triVertext, 2, &gradientRect, 1, GRADIENT_FILL_RECT_V);
}
like image 177
Alan Avatar answered Oct 29 '25 23:10

Alan


C# uses GDI+ for Drawing2d. You can use GDI+ in C++ also - MSDN Creating a Linear Gradient

like image 26
Cristian Adam Avatar answered Oct 29 '25 21:10

Cristian Adam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!