Конечная цель этого - создать заставку в окнах, в которых используется прозрачность, но это не то, на чем я сейчас застрял.
Чтобы создать прозрачное окно, я сначала пытаюсьсоставить заставку и текст в буфере за пределами экрана, используя 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:
---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 в этом отношении), а затем отображаете это на экране?
Спасибо за чтение.