//常量声明
#define WS_EX_LAYERED 0x00080000
#define LWA_COLORKEY 0x00000001
#define LWA_ALPHA 0x00000002
//CreateWindowEx(WS_EX_LAYERED,...);//创建窗体
BLENDFUNCTION bindfun;
//设置AlphaBind的最后一个参数
bindfun.BlendOp=AC_SRC_OVER;
bindfun.BlendFlags=0;
bindfun.SourceConstantAlpha=255;
bindfun.AlphaFormat=AC_SRC_ALPHA;
//以下三行为虚代码,具体实现请参考相关代码
//HDC hmemdc=CreateMemDC(); //创建内存绘图设备句柄
//CPng png;
//png.Load("1.png");//加载png图片
//在将ColorBits转换为DC前,先将每个像素进行下面的运算
//R=BYTE(MulDiv(R,A,255));
//G=BYTE(MulDiv(G,A,255));
//B=BYTE(MulDiv(B,A,255));
::AlphaBlend(hmemdc,0,0,260,60,png.GetDC(),0,0,260,60,bindfun);
RECT crc,wrc;
GetClientRect(hWnd,&crc);
GetWindowRect(hWnd,&wrc);
POINT ptWinPos={wrc.left,wrc.top};
SIZE sizeWindow={crc.right, crc.bottom};
POINT ptSrc={0,0};
BOOL bResult=::UpdateLayeredWindow(hWnd, hWinhdc, &ptWinPos, &sizeWindow, hmemdc, &ptSrc, 0, &bindfun, ULW_ALPHA);
以下为效果图