gpt4 book ai didi

c++ - 如何在 Aero 玻璃窗上绘制不透明图像?

转载 作者:行者123 更新时间:2023-11-28 05:53:57 25 4
gpt4 key购买 nike

我已经使用 DWM API 通过调用 DwmExtendFrameIntoClientArea 创建了一个 Aero 玻璃窗。

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");
}
}
}

然后,我在窗口上绘制位图图像(我也尝试调用 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 玻璃窗上绘制不透明图像? result

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

最佳答案

解决方案一:

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);

}

结果: enter image description here

关于c++ - 如何在 Aero 玻璃窗上绘制不透明图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34624042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com