[vc] mfc 对话框采用png的自定义格式

OnPaint() 中添加
CString pngFileName=L"D:\\图    样\\png图片\\linux.png";
	CBitmap m_bmpDialog;
	CDC dcMemory;
	CDC* m_screenDC;

	m_screenDC=new CDC();
	m_screenDC->Attach(::GetDC(NULL));
	dcMemory.CreateCompatibleDC(m_screenDC);
	ModifyStyleEx(0,0x80000);

	HBITMAP hBitmap;
	hBitmap=CreateCompatibleBitmap(this->GetDC()->m_hDC,300,300);

	{
		HDC hDC;
		WORD wBitCount=32;
		DWORD dwPaletteSize=0, dwBmBitsSize=0, dwDIBSize=0, dwWritten=0;
		BITMAP Bitmap; 
		BITMAPINFOHEADER bi; 
		LPBITMAPINFOHEADER lpbi; 
		HANDLE hPal,hOldPal=NULL;
		HBITMAP hDib;
		GetObject(hBitmap, sizeof(Bitmap), (LPSTR)&Bitmap);
		bi.biSize = sizeof(BITMAPINFOHEADER);
		bi.biWidth = Bitmap.bmWidth;
		bi.biHeight = Bitmap.bmHeight;
		bi.biPlanes = 1;
		bi.biBitCount = wBitCount;
		bi.biCompression = BI_RGB;
		bi.biSizeImage = 0;
		bi.biXPelsPerMeter = 0;
		bi.biYPelsPerMeter = 0;
		bi.biClrImportant = 0;
		bi.biClrUsed = 0;
		dwBmBitsSize = ((Bitmap.bmWidth * wBitCount + 31) / 32) * 4 * Bitmap.bmHeight;
		hPal = GetStockObject(DEFAULT_PALETTE);
		if (hPal)
		{
			hDC = ::GetDC(NULL);
			hOldPal = ::SelectPalette(hDC, (HPALETTE)hPal, FALSE);
			RealizePalette(hDC);
		}
		hDib = CreateDIBSection(hDC,(BITMAPINFO*)&bi,DIB_RGB_COLORS, (LPVOID*)&lpbi, NULL, 0);
		GetDIBits(hDC, hBitmap, 0, (UINT) Bitmap.bmHeight, (LPSTR)lpbi+dwPaletteSize, (LPBITMAPINFO)&bi, DIB_RGB_COLORS);
		if (hOldPal)
		{
			::SelectPalette(hDC, (HPALETTE)hOldPal, TRUE);
			RealizePalette(hDC);
			::ReleaseDC(NULL, hDC);
		}
		CloseHandle(hPal);
		CloseHandle(hOldPal);
		DeleteObject(hBitmap);
		hBitmap=hDib;
	}
	m_bmpDialog.DeleteObject();
	m_bmpDialog.Attach(hBitmap);

	CBitmap *pOldBitmap= dcMemory.SelectObject(&m_bmpDialog);
	BITMAP bmpInfo;
	m_bmpDialog.GetBitmap(&bmpInfo);
	CRect rectDlg;
	this->GetWindowRect(rectDlg);
	CPoint ptWindowScreenPosition(rectDlg.TopLeft());
	CSize szWindow(bmpInfo.bmWidth, bmpInfo.bmHeight);
	BLENDFUNCTION blendPixelFunction= { AC_SRC_OVER, 0, 255, 0x01};
	CPoint ptSrc(0,0);

	//
	//Image *m_bit=new Bitmap(pngFileName.AllocSysString());

	Image *m_Png;
	m_Png=Image::FromFile(pngFileName);
	Graphics graphics(dcMemory.m_hDC);
	graphics.DrawImage(m_Png,0,0);
	//
	graphics.ReleaseHDC(dcMemory.m_hDC);
	
	::UpdateLayeredWindow(this->m_hWnd,m_screenDC->m_hDC,
		&ptWindowScreenPosition, 
		&szWindow,
		dcMemory,
		&ptSrc, 0, 
		&blendPixelFunction, 0x02);
OnLButtonDown(UINT nFlags, CPoint point)
{
	PostMessage(WM_NCLBUTTONDOWN,   HTCAPTION,   MAKELPARAM(point.x,   point.y));
	CDialog::OnLButtonDown(nFlags, point);
}

#include <gdiplus.h>
using namespace Gdiplus;

#pragma comment(lib,"gdiplus.lib")





GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值