15,980
社区成员




RECT rc;
GetWindowRect(&rc);
const int nWidth = rc.right - rc.left;
const int nHeight = rc.bottom - rc.top;
CDC* pDC = GetDC();
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&memDC, nWidth, nHeight);
CBitmap *pOldBmp = memDC.SelectObject(&bmp);
Graphics graph(memDC.m_hDC);
Image img(L"e:\\a.png");
graph.DrawImage(&img, 0, 0, nWidth, nHeight);
BLENDFUNCTION blend;
blend.BlendOp = 0;
blend.BlendFlags = 0;
blend.AlphaFormat = 1;
blend.SourceConstantAlpha = 255;
POINT ptWinPos = {rc.left, rc.top};
SIZE sizeWindow = {nWidth, nHeight};
POINT ptSrc = {0,0};
DWORD dwExStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE);
if((dwExStyle&0x80000) != 0x80000) SetWindowLong(m_hWnd, GWL_EXSTYLE, dwExStyle^0x80000);
BOOL bRet = UpdateLayeredWindow(m_hWnd, pDC->m_hDC, &ptWinPos, &sizeWindow, memDC.m_hDC, &ptSrc, 0, &blend, 2);
graph.ReleaseHDC(memDC.m_hDC);
memDC.SelectObject(pOldBmp);
memDC.DeleteDC();
bmp.DeleteObject();
ReleaseDC(pDC);