mfc_gradientfill - 8BitsCoding/RobotMentor GitHub Wiki


이미지

void CMFCApplication1Dlg::OnPaint()
{
	CPaintDC dc(this); // 그리기λ₯Ό μœ„ν•œ λ””λ°”μ΄μŠ€ μ»¨ν…μŠ€νŠΈμž…λ‹ˆλ‹€.

	if (IsIconic())
	{
        // ..
	}
	else
	{
		//GradientFillFn(&dc, 10, 10, 210, 210, RGB(0, 128, 255), RGB(0, 255, 255));
		GradientFillFn_3D(&dc, 10, 10, 210, 210, RGB(0, 128, 255), RGB(0, 255, 255));
    }
}
void CMFCApplication1Dlg::GradientFillFn(CDC* ap_dc, int a_sx, int a_sy, int a_ex, int a_ey,
	COLORREF a_start_color, COLORREF a_end_color) 
{
	TRIVERTEX data[2];	// μ‹œμž‘μ’Œν‘œ λμ’Œν‘œ λ„£λŠ”κ³³
	GRADIENT_RECT r;

	data[0].x = a_sx;		// left
	data[0].y = a_sy;		// top

	data[0].Red = GetRValue(a_start_color);
	data[0].Green = GetGValue(a_start_color) << 8;
	data[0].Blue = GetBValue(a_start_color) << 8;
	data[0].Alpha = 0;

	data[1].x = a_ex;	// right
	data[1].y = a_ey;	// bottom

	data[1].Red = GetRValue(a_end_color);
	data[1].Green = GetGValue(a_end_color) << 8;
	data[1].Blue = GetBValue(a_end_color) << 8;
	data[1].Alpha = 0;

	r.UpperLeft = 0;
	r.LowerRight = 1;

	ap_dc->GradientFill(data, 2, &r, 1, GRADIENT_FILL_RECT_V);
}
void CMFCApplication1Dlg::GradientFillFn_3D(CDC* ap_dc, int a_sx, int a_sy, int a_ex, int a_ey,
	COLORREF a_start_color, COLORREF a_end_color)
{
	TRIVERTEX data[2];	// μ‹œμž‘μ’Œν‘œ λμ’Œν‘œ λ„£λŠ”κ³³
	GRADIENT_RECT r;

	data[0].x = a_sx;		// left
	data[0].y = a_sy;		// top

	data[0].Red = GetRValue(a_start_color);
	data[0].Green = GetGValue(a_start_color) << 8;
	data[0].Blue = GetBValue(a_start_color) << 8;
	data[0].Alpha = 0;

	data[1].x = a_ex;	// right
	data[1].y = a_sy + (a_ey - a_sy) / 2;	// bottom

	data[1].Red = GetRValue(a_end_color);
	data[1].Green = GetGValue(a_end_color) << 8;
	data[1].Blue = GetBValue(a_end_color) << 8;
	data[1].Alpha = 0;

	r.UpperLeft = 0;
	r.LowerRight = 1;

	ap_dc->GradientFill(data, 2, &r, 1, GRADIENT_FILL_RECT_V);

	data[0].x = a_sx;		// left
	data[0].y = a_sy + (a_ey - a_sy) / 2;		// top

	data[0].Red = GetRValue(a_end_color);
	data[0].Green = GetGValue(a_end_color) << 8;
	data[0].Blue = GetBValue(a_end_color) << 8;
	data[0].Alpha = 0;

	data[1].x = a_ex;	// right
	data[1].y = a_ey;	// bottom

	data[1].Red = GetRValue(a_start_color);
	data[1].Green = GetGValue(a_start_color) << 8;
	data[1].Blue = GetBValue(a_start_color) << 8;
	data[1].Alpha = 0;

	ap_dc->GradientFill(data, 2, &r, 1, GRADIENT_FILL_RECT_V);
}