Platform SDK: DirectX |
You can retrieve a pointer to a surface's IDirectDrawSurface7 interface from the device context for the surface by calling the IDirectDraw7::GetSurfaceFromDC method. This feature might be very useful for component applications or ActiveX® controls, that are commonly given a device context to draw into at run time, but could benefit by exploiting the features exposed by the IDirectDrawSurface7 interface.
A device context might identify memory that isn't associated with a DirectDraw object, or the device context might identify a surface for another DirectDraw object entirely. The latter case is most likely to occur on a system with multiple monitors. If the device context identifies a surface that wasn't created by that DirectDraw object, the method fails, returning DDERR_NOTFOUND.
The following sample code shows what a very simple scenario might look like.
// For this example, the hdc variable is a valid // handle to a video memory device context, and the // lpDD variable is a valid IDirectDraw7 interface pointer. LPDIRECTDRAWSURFACE7 lpDDS; HRESULT hr; hr = lpDD->GetSurfaceFromDC(hdc, &lpDDS); if(SUCCEEDED(hr)) { // Use the surface interface. } else if(DDERR_NOTFOUND == hr) { OutputDebugString("HDC not from this DirectDraw surface\n"); }
You can retrieve a surface's DirectDrawSurface7 object from the device context for the surface by calling the DirectDraw7.GetSurfaceFromDC method. This feature might be very useful for component applications or Microsoft® ActiveX® controls that are commonly given a device context to draw into at run time, but could benefit by exploiting the features provided by the object.
A device context might identify memory that isn't associated with a DirectDraw object, or the device context might identify a surface for another DirectDraw object entirely. If the device context identifies a surface that wasn't created by that DirectDraw object, the method fails, returning DDERR_NOTFOUND.
The following sample code shows what a very simple scenario might look like.
' For this example, the hDC variable is a valid ' handle to the video memory device context, and the ' DD variable is a valid DirectDraw7 object. Dim dds As DirectDrawSurface7 Set dds = dd.GetSurfaceFromDC(hDC) If Err.Number = DDERR_NOTFOUND Then MsgBox "hDC not from this DirectDraw surface" End If