#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib,"gdiplus.lib")
下面的代码加在初始化位置:(MFC的OnInitDialog)
Image image(L"meinv.png");
DWORD dwStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE);SetWindowLong(m_hWnd, GWL_EXSTYLE, dwStyle | 0x80000);
HDC hDCDest = ::GetDC(m_hWnd);
m_hDCMem = CreateCompatibleDC(hDCDest);
HBITMAP hBmp=CreateCompatibleBitmap(hDCDest, image.GetWidth(), image.GetHeight());
SelectObject(m_hDCMem, hBmp);
RECT rect;
GetWindowRect(&rect);
POINT ptDest = { rect.left, rect.top };
POINT ptSrc = { 0, 0 };
SIZE sizeWindow = { image.GetWidth(), image.GetHeight() };
Graphics graphics(m_hDCMem);
graphics.DrawImage(&image, 0, 0, image.GetWidth(), image.GetHeight());
m_Blend.AlphaFormat = AC_SRC_ALPHA;
m_Blend.BlendFlags = 0;
m_Blend.BlendOp = AC_SRC_OVER;
m_Blend.SourceConstantAlpha = 255;
::UpdateLayeredWindow(m_hWnd, hDCDest, &ptDest, &sizeWindow, m_hDCMem, &ptSrc, 0, &m_Blend, 2);
效果