DirectDraw and paint something with GDI
Hi guys, I have a question and I think it's not very feasible, I recently started playing with DirectDraw (D2D1) (I was amazed) the question is, can I between cRenderTarget.BeginDraw and cRenderTarget.EndDraw draw something with GDI and GDI+, I know that It doesn't make much sense, I'm making a user control and I would like that within a Paint event the user (programmer) could use bitblt to be able to draw a control over my control.
Re: DirectDraw and paint something with GDI
no, u can not draw like that.
u need to specify the hwnd or bitmap where it will be rendered.
a d2d1.bitmap u can copy it into something else I think. never done it but its possible.
so, u can use d2d1 to draw into a d2d1.bitmap and copy that into something else.
but its wasteful. better work with gdi32 if u want to use hdc
Re: DirectDraw and paint something with GDI
Grace, I'm effectively going to skip this, and I'm going to choose to take working 100% with directdraw.
Later I will have other questions with Directdraw
Re: DirectDraw and paint something with GDI
I did something awhile ago, I wanted to use d2d1&bitblt (to capture the screen in real-time and show it somewhere else)
Code:
Sub TheLoop()
Dim cConverter As IWICFormatConverter
Dim wicBitmap As IWICBitmap
With Frm
.running = 1
Set wicBitmap = cWICFactory.CreateBitmapFromHBITMAP(.mem.hBmp, ByVal 0&, WICBitmapUsePremultipliedAlpha)
Set cConverter = cWICFactory.CreateFormatConverter()
cConverter.Initialize wicBitmap, WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, Nothing, 0, WICBitmapPaletteTypeMedianCut
hTarget.BeginDraw
hTarget.Clear bcolor
Set hBitmap = hTarget.CreateBitmapFromWicBitmap(ByVal cConverter, ByVal 0&)
hTarget.DrawBitmap hBitmap, oRect, 1, .scaling, iRect
hTarget.EndDraw ByVal 0&, ByVal 0&
Set wicBitmap = Nothing
Set cConverter = Nothing
Set hBitmap = Nothing
BitBlt .mem.hDest, 0, 0, .width, .height, .hdc, 0, 0, vbSrcCopy
.running = 0
End With
End Sub
in the code above u see I have "frm" with a couple of things, heres what they do:
Code:
Private Sub InitDirect2d()
Dim cIID(1) As Currency
Dim HwndRenderTargetProperties As D2D1_HWND_RENDER_TARGET_PROPERTIES
Dim RenderTargetProperties As D2D1_RENDER_TARGET_PROPERTIES
Terminate2d
With Frm
.mem.hdc = GetDC(0&)
.mem.hDest = CreateCompatibleDC(.mem.hdc)
.mem.hBmp = CreateCompatibleBitmap(.mem.hdc, .width, .height)
SelectObject .mem.hDest, .mem.hBmp
End With
GetMem8 547589997359777.4628@, WICPixelFormat32bppPBGRA
GetMem8 120965351487186.6801@, ByVal VarPtr(WICPixelFormat32bppPBGRA) + 8
cIID(0) = 506948672004902.9703@: cIID(1) = 53149071617564.8146@
With HwndRenderTargetProperties
.hWnd = main.hWnd
.pixelSize.width = Frm.width
.pixelSize.height = Frm.height
.presentOptions = D2D1_PRESENT_OPTIONS_NONE
End With
With RenderTargetProperties
.pixelFormat.Format = DXGI_FORMAT_UNKNOWN
.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN
.Type = D2D1_RENDER_TARGET_TYPE_DEFAULT
.usage = D2D1_RENDER_TARGET_USAGE_NONE
.minLevel = D2D1_FEATURE_LEVEL_DEFAULT
End With
Set cFactory = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, cIID(0), ByVal 0&)
Set hTarget = cFactory.CreateHwndRenderTarget(RenderTargetProperties, HwndRenderTargetProperties)
Set cWICFactory = New WICImagingFactory
hTarget.SetDpi 96, 96
oRect.Right = Frm.width
oRect.Bottom = Frm.height
iRect = oRect
End Sub
so as u see, u need to do a lot to make it work.
Re: DirectDraw and paint something with GDI
thanks @baka for your time, and yes, doing it that way takes more work