最终的目标是在使用透明度的窗口中有一个启动画面,但这不是我现在卡住的内容。使用GDI的Windows启动画面+
为了创建一个透明窗口,我首先尝试使用GDI +将闪屏和文本组合到屏幕外的缓冲区中。
目前,我只是想组合缓冲区并显示它以响应'WM_PAINT'消息。目前这还没有解决。我看到的只是一个黑色的窗口。
我想我误解的东西有关于设置渲染GDI +目标,然后使它们(我试图用简单的GDI位图传送到渲染屏幕)
总之,这里的代码,使远:
//my window initialisation code
void MyWindow::create_hwnd(HINSTANCE instance, const SIZE &dim)
{
DWORD ex_style = WS_EX_LAYERED ; //eventually I'll be making use of this layerd flag
m_hwnd = CreateWindowEx(
ex_style,
szFloatingWindowClass ,
L"",
WS_POPUP ,
0,
0,
dim.cx,
dim.cy,
null,
null,
instance,
null);
m_display_dc = GetDC(NULL);
//This was sanity check test code - just loading a standard HBITMAP and displaying it in WM_PAINT. It worked fine
//HANDLE handle= LoadImage(NULL , L"c:\\test_image2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
m_gdip_offscreen_bm = new Gdiplus::Bitmap(dim.cx, dim.cy);
m_gdi_dc = Gdiplus::Graphics::FromImage(m_gdip_offscreen_bm);//new Gdiplus::Graphics(m_splash_dc);//window_dc ;m_splash_dc
//this draws the conents of my splash screen - this works if I create a GDI+ context for the window, rather than for an offscreen bitmap.
//For all I know, it might actually be working but when I try to display the contents on screen, it shows a black image
draw_all();
//this is just to show that drawing something simple on the offscreen bit map seems to have no effect
Gdiplus::Pen pen(Gdiplus::Color(255, 0, 0, 255));
m_gdi_dc->DrawLine(&pen, 0,0,100,100);
DWORD last_error = GetLastError(); //returns '0' at this stage
}
及这里的处理WM_PAINT消息snipit:
---8<-----------------------
//Paint message snippit
case WM_PAINT:
{
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(vg->m_hwnd, &ps); //get the HWNDs DC
HDC hdcMem = vg->m_gdi_dc->GetHDC(); //get the HDC from our offscreen GDI+ object
unsigned int width = vg->m_gdip_offscreen_bm->GetWidth(); //width and height seem fine at this point
unsigned int height = vg->m_gdip_offscreen_bm->GetHeight();
BitBlt(hdc, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY); //this blits a black rectangle
DWORD last_error = GetLastError(); //this was '0'
vg->m_gdi_dc->ReleaseHDC(hdcMem);
EndPaint(vg->m_hwnd, &ps); //end paint
return 1;
}
---8<-----------------------
我对长期职位的歉意。有人知道我不怎么了解你如何使用GDI +(或GDI)写入屏幕外缓冲区,然后将其显示在屏幕上?
谢谢您的阅读。
我发现如果我为屏幕创建另一个GDI +上下文并使用它绘制合成的上下文,它可以正常工作。但是,我试图使用GDI-方法的原因是为了能够使用' UpdateLayeredWindow”。我的问题,如何使用GDI blit GDI +图像仍然站立。 – Luther 2011-03-07 16:33:42
如果窗口具有以这种方式添加的WS_EX_LAYERED样式,则不会发送此代码,因为不会发送WM_PAINT消息。这会导致窗口只触发UpdateLayeredWindow更新的窗口离屏位图副本。 – 2011-03-08 08:01:16
感谢您的提示克里斯。我暂时关闭分层标志,但仍然无法绘制alpha混合图像。我目前正在尝试使用'AlphaBlend',它似乎是用于渲染alpha混合图像的替代fpr BitBlt。目前为止没有骰子,它只是将GetLastError设置为'ERROR_INVALID_PARAMETER',但没有详细说明。我永远不会与Win32和GDI成为朋友;他们只是玩不好!阿尔法混合应该是微不足道的。 – Luther 2011-03-08 10:37:16