背景透明

bool DrawAlpha(Image* pBgImg, HWND hWnd) { if (!::IsWindow(hWnd)) return false; CWndDecorate wndDecor(hWnd); //wndDecor.SetAlpha((255 * 20) / 100); //wndDecor.ShowOnDesk(); RECT rcWnd; ::GetWindowRect(hWnd, &rcWnd); int nWid = rcWnd.right - rcWnd.left; int nHei = rcWnd.bottom - rcWnd.top; HDC hdcTemp = ::GetWindowDC(hWnd); HDC hdcMemory = ::CreateCompatibleDC(hdcTemp); HBITMAP hBitMap = CreateCompatibleBitmap(hdcTemp, nWid, nHei); SelectObject(hdcMemory, hBitMap); HDC hdcScreen = ::GetWindowDC(hWnd); POINT ptWinPos = {rcWnd.left, rcWnd.top}; Graphics graph(hdcMemory); Point points[] = {Point(0, 0),Point(nWid, 0),Point(0, nHei)}; graph.DrawImage(pBgImg, points,3); SIZE sizeWindow={nWid, nHei}; POINT ptSrc={0,0}; DWORD dwExStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE); if ((dwExStyle & 0x80000) != 0x80000) { ::SetWindowLong(hWnd, GWL_EXSTYLE, dwExStyle ^ 0x80000); } CString strTitle; m_alWnd.GetWindowText(strTitle); Gdiplus::Font font(L"宋体",12,FontStyleBold,UnitPixel); StringFormat strFormat; SolidBrush brush(Color(0xff,0,0,0)); graph.DrawString(strTitle, -1, &font, PointF(32,30),&strFormat, &brush); ::UpdateLayeredWindow(hWnd, hdcScreen, &ptWinPos, &sizeWindow, hdcMemory, &ptSrc, 0, &m_alBlend, ULW_ALPHA); graph.ReleaseHDC(hdcMemory); ::ReleaseDC(hWnd,hdcScreen); hdcScreen = NULL; ::ReleaseDC(hWnd,hdcTemp); hdcTemp = NULL; DeleteObject(hBitMap); DeleteDC(hdcMemory); hdcMemory = NULL; return true; } 

你可能感兴趣的:(null,graph,image)