Gradient effect on background color (Code Project)

xiaoxiao2021-04-06  268

If only the background color gradient in the horizontal or vertical direction, simply reload the operasebkgn function, the specific code is as follows: CDIALOG :: OneRaseBkGnd (PDC);

CRECT RECT; GetClientRect (& Re);

INT R1 = 127, G1 = 127, B1 = 56; // ANY Start Colorint R2 = 5, G2 = 55, B2 = 165; // Any Stop Color

For (int i = 0; i FillsolidRect (I, 0, 1, Rect.Height (), RGB (R, G, B));}

Return True;

If you want to achieve the tilt gradient, you need to add a function, and call in OnInitDialog.

CDIALOG :: OneRaseBkGnd (PDC);

CRECT RECT; GetClientRect (& Re);

CDC DC2; DC2.CreateCompatibleDC (PDC); cBitmap * Oldbmap = dc2.selectObject (& m_bitmap);

/ * We copy the bitmap INTO The DC * / PDC-> Bitblt (0, 0, Rect.width (), Rect.Height (), & DC2, 0, Srccopy; dc2.selectObject (OldbMap);

Return True;

Void cyorclassname :: madebitmap () {cpaintdc dc (this); cRect Rect; getClientRect (& REC);

INT R1 = 245, G1 = 190, B1 = 240; INT R2 = 130, G2 = 0, B2 = 0;

INT x1 = 0, y1 = 0; int X2 = 0, y2 = 0;

CDC DC2; DC2.CREATECOMPATIPLDC (& DC);

IF (m_bitmap.m_hobject) m_bitmap.deleteObject (); m_bitmap.createcompatiblebitmap (& DC, Rect.width (), Rect.Height ());

CBITMAP * OLDBMAP = dc2.selectObject (& m_bitmap);

While (x1

IF (x2

INT R, G, B; INT i = x1 y1; R = R1 (I * (R2-R1) / (Rect.Width () Rect.Height ())); g = g1 (i * (i * G2-G1) / (Rect.width () Rect.Height ())); b = b1 (i * (b2-b1) / (rect.width () Rect.Height ())); CPEN P (PS_SOLID, 1, RGB (R, G, B)); CPEN * OLDPEN = DC2.SelectObject (& P);

DC2.Moveto (x1, y1); dc2.LineTo (X2, Y2);

DC2.SelectObject (Oldpen);

Dc2.selectObject (Oldbmap);

}

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

New Post(0)