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);