コード例 #1
0
void CVideoClientDlg::OnLoadPNG(LPCTSTR Path, CRect m_Rect)
{
	ATL::CImage img;
	HRESULT ret = img.Load(Path); //要加载的图片名称,包含路径
	HBITMAP hbitmap = img.Detach();

	//像操作 BMP 图片一样处理图片 ,下面是显示图片的操作
	CPaintDC dc(this);// 用于绘制的设备上下文
	CRect rect;    
	GetClientRect(&rect);  
	CBitmap pngBackground;
	BITMAP bitmap;
	CDC memdc;
	pngBackground.Attach(hbitmap);
	memdc.CreateCompatibleDC(&dc);
	pngBackground.GetBitmap(&bitmap);  //建立绑定关系  
	CBitmap  *pbmpOld=memdc.SelectObject(&pngBackground);   //保存原有CDC对象,并选入新CDC对象入DC  
	dc.SetStretchBltMode(COLORONCOLOR);//防止bmp图片失真
	dc.StretchBlt(0,0,rect.Width(),rect.Height(),&memdc,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
	memdc.SelectObject(pbmpOld);

	//程治谦 2015-1-13 防止内存泄漏
	(*pbmpOld).DeleteObject();
	DeleteObject(hbitmap);
	img.Destroy();
	pngBackground.DeleteObject();  
	memdc.DeleteDC(); 
}
コード例 #2
0
void CVideoClientDlg::OnPaint()
{
	CRect rect;
	m_sdlPlayer.GetWindowRect(&rect);
	OnLoadPNG(_T(g_szOcxPath+"res/ui-mockup-player-bg1.png"), rect);

	//程治谦 2015-1-13 防止内存泄漏
	//CStatic* pWnd = (CStatic*)GetDlgItem(IDCSDLPLAYER); // 得到 Picture Control 句柄  

	ATL::CImage image;  
	image.Load(_T(g_szOcxPath+"res/ui-mockup-player-inner.png"));  
	HBITMAP hBmp = image.Detach();  
	m_sdlPlayer.SetBitmap(hBmp);

	//程治谦 2015-1-13 防止内存泄漏
	DeleteObject(hBmp);
	image.Destroy();
}