如何在 Aero 玻璃上绘制不透明图像 window?

How to draw a opaque image on the Aero glass window?

我已经使用 DWM API 通过调用 DwmExtendFrameIntoClientArea 创建了一个 Aero glass window。

void CMainFrame::OnActivate(UINT nState,CWnd* pWndOther,BOOL bMinimized )
{
    CFrameWnd::OnActivate(nState,pWndOther,bMinimized);
    BOOL fDwmEnabled = FALSE;
    if (SUCCEEDED(DwmIsCompositionEnabled(&fDwmEnabled)))
    {
        if(nState == WA_ACTIVE )
        {
            MARGINS margins ={-1};
            HRESULT hr = DwmExtendFrameIntoClientArea(m_hWnd, &margins);
            if (!SUCCEEDED(hr))
               TRACE0("Failed to DwmExtendFrameIntoClientArea\n");
        }
    }
}

然后,我在 window 上绘制位图图像(我也尝试调用 DrawThemeIcon 和 CImageList::Draw 来绘制图像)。

void CMainFrame::DisplayBitmap( CBitmap *p, CDC *pDC)
{
    CDC dcMemory;
    BITMAP bm;
    dcMemory.CreateCompatibleDC(pDC);
    dcMemory.SelectObject(p);
    p->GetBitmap(&bm);
    pDC->BitBlt(100,100,bm.bmWidth,bm.bmHeight,&dcMemory,0,0,SRCCOPY);
}

void CMainFrame::OnNcPaint(){
    CFrameWnd::OnNcPaint();
    CDC* dc = GetWindowDC();
    CRect rct;
    GetWindowRect(&rct);
    dc->FillSolidRect(0, 0, rct.right - rct.left, rct.bottom - rct.top, RGB(0, 0, 0));
    DisplayBitmap(&bmpBtn,dc);
    ReleaseDC(dc);
}

我发现图像很丑而且半透明。如何在 Aero 玻璃上绘制不透明图像 window?

更新: 我仍然需要有人可以在不使用 GDI+ 库的情况下为我提供另一种解决方案。谢谢!

解决方案 1:

CMainFrame::CMainFrame()
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR           gdiplusToken;
    //Initialize GDI+.
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    m_pImage = m_pImage->FromFile (_T("lena.bmp"));
}

void CMainFrame::OnNcPaint(){
    CFrameWnd::OnNcPaint();
    CDC* dc = GetWindowDC();
    CRect rct;
    GetWindowRect(&rct);
    dc->FillSolidRect(0, 0, rct.right - rct.left, rct.bottom - rct.top, RGB(0, 0, 0));
    CPaintDC gdc(this);
    Graphics g(gdc);
    //I don't why the image will disappear sometimes when I move the window.
    g.DrawImage ( m_pImage, 0, 0 );
    ReleaseDC(dc);

}

结果: