Original:how OLE controls are rendered in Direct3D
Graphical drawing on Windows is based on GDI, and Direct3D is not, so there are a lot of problems in displaying some controls in Windows in a 3D window
So what's the way to make GDI's content appear in 3D? Anyway, it's all images, there's always a way to achieve it!
In the previous period of time in the research browser embedded in the game, the basic idea is to open a browsing window in the background, and then copy the contents of it to a texture, and then the texture in the D3D to draw out, as for the event processing will be another fuss.
So, other windows of GDI drawing things can be done like this!
Originally I was getdc, then getpixel pixel copy, slow I want to die ....
Later discovered the BitBlt this fast copy method, has the practical value:
1. Get the control's DC:GETDC (HWND)
2. Obtaining the DC:IDIRECT3DSURFACE9::GETDC of texture
3. Copy the past with BitBlt
BOOL BitBlt (
HDC hdcdest,//handle to destination DC
int nxdest,//X-coord of destination Upper-left corner
int nydest,//Y-coord of destination Upper-left corner
int nwidth,//width of destination Rectangle
int nheight,//height of destination Rectangle
HDC hdcsrc,//handle to source DC
int NXSRC,//x-coordinate of source Upper-left Corner
int NYSRC,//y-coordinate of source Upper-left Corner
DWORD dwrop//Raster operation code
);
If it's an OLE control, it's even easier:
Winoleapi Oledraw (
IUnknown * PUnk,//pointer to the View object to be drawn
DWORD Dwaspect,//how the object is to be represented
HDC Hdcdraw,//device context on which to draw
Lpcrect lprcbounds//pointer to the rectangle in which the object
is drawn
);
For example, I have a IWebBrowser2 pointer that I want to copy to the texture, so I can do this:
idirect3dsurface9* psurface = NULL;
This->mtexture->getsurfacelevel (0, &psurface);
if (NULL! = psurface)
{
HDC hdctexture;
HRESULT hr = PSURFACE->GETDC (&hdctexture);
if (FAILED (HR)) return;
:: Setmapmode (Hdctexture, mm_text);
:: Oledraw (Pbrowser, Dvaspect_content, Hdctexture, &rect);
Psurface->releasedc (hdctexture);
Psurface->release ();
}
Show me a bit:
Not only the browser, but any OLE control, you can use your imagination:
How to render the "reprint" OLE Control in Direct3D