C/C++ Duilib custom control

1. Inherit the corresponding controls according to the current needs, which has reduced repeated development

Generally inherit DoPaint to write, if you need to display on the top layer, you must inherit DoPostPaint()

For example, read the picture rotation display, cooperate with GDI+, pay attention to the constructor of Gdiplus::Bitmap, in this case, PNG uses PixelFormat32bppPARGB

bool RotateAnimation::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
{
		Gdiplus::PointF centerPos(m_rcItem.left + GetWidth()/ 2, m_rcItem.top + GetHeight()/ 2);

		Gdiplus::Graphics graphics(hDC);
		//graphics.SetSmoothingMode(SmoothingModeAntiAlias);

		graphics.TranslateTransform(centerPos.X, centerPos.Y);
		graphics.RotateTransform(m_fCurAngle);
		graphics.TranslateTransform(-centerPos.X, -centerPos.Y);

		const TImageInfo* imgInfo = GetManager()->GetImageEx(m_diBk.sImageName);
		BITMAP bmp;
		GetObject(imgInfo->hBitmap, sizeof(BITMAP), &bmp);		
		Gdiplus::Bitmap gdi_bmp(imgInfo->nX, imgInfo->nY, imgInfo->nX * 4, PixelFormat32bppPARGB, (BYTE*)bmp.bmBits);
	
		graphics.DrawImage(&gdi_bmp, m_rcItem.left, m_rcItem.top, GetWidth(), GetHeight());
		return true;
	}	
}

Take a closer look at DoPostPaint. First, add the m_aPostPaintControls array. After all the controls are painted, it will be called last. Therefore, it is at the top level than DoPaint.

When you look at the source code of Duilib, you can see
Insert picture description here
powered by: the little tortoise is on the back of the big tortoise.
More articles: https://blog.csdn.net/what951006

Guess you like

Origin blog.csdn.net/what951006/article/details/88601698