-1

我尝试整天使用 UpdateLayeredWindow,但它无法工作:(,我将代码放入 OnCreate 并使用 CImage 加载一个 png 文件(由 photoshop 创建)。

int CMainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    SetWindowLong(this->m_hWnd, GWL_STYLE, 0);
    SetWindowLong(this->m_hWnd, GWL_EXSTYLE, 0);
    SetWindowLong(this->m_hWnd, GWL_EXSTYLE, GetWindowLong(this->m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
    this->SetMenu(NULL);
    ::SetWindowPos(this->m_hWnd, HWND_TOP, 50, 50, 652, 492, SWP_SHOWWINDOW);

    CBitmap imageBitmap, *oldBitmap;
    CDC *dcWindow, dcMem;
    CRect wRect;
    CPoint wPos;
    CSize wSize;
    HBITMAP hbmp;
    BLENDFUNCTION bFunc;

    m_Image.Load(_T("Img/BG_Blue.png"));
    GetWindowRect(&wRect);
    dcWindow = GetWindowDC();
    imageBitmap.CreateCompatibleBitmap(dcWindow, wRect.Width(), wRect.Height());
    dcMem.CreateCompatibleDC(dcWindow);
    oldBitmap = dcMem.SelectObject(&imageBitmap);
    m_Image.Draw(dcMem.m_hDC, 0, 0, wRect.Width(), wRect.Height(), 0, 0, wRect.Width(), wRect.Height());
    wPos.x = 0; wPos.y = 0;
    wSize.cx = wRect.left; wSize.cy = wRect.bottom;
    bFunc.SourceConstantAlpha = 125;
    bFunc.BlendFlags = 0;
    bFunc.BlendOp = AC_SRC_OVER;
    bFunc.AlphaFormat = AC_SRC_ALPHA;
    UpdateLayeredWindow(dcWindow, &wPos, &wSize, &dcMem, &wPos, 0, &bFunc, ULW_ALPHA);
    //BitBlt(dcWindow->m_hDC, 0, 0, wRect.Width(), wRect.Height(), dcMem.m_hDC, 0, 0, SRCCOPY);
    DWORD error = GetLastError();
    dcMem.SelectObject(oldBitmap);
    return 0;
}

该函数返回 1 ,但屏幕上什么也没有出现,只有启动菜单上的一个图标表示程序正在运行。我想知道png文件是否有问题......有人可以帮忙吗?

4

1 回答 1

0

dcWindow应该是屏幕的设备上下文而不是窗口。所以像这样初始化它:dcWindow->Attach(::GetDC(NULL))而不是dcWindow = GetWindowDC();

于 2012-09-22T13:43:59.760 回答