Microsoft Windows CE 3.0  

Retrieving the Device Context for a Surface

This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

If you want to modify the contents of a DirectDraw surface object by using GDI functions, you must retrieve a GDI-compatible device context handle. This could be useful if you wanted to display text in a DirectDraw surface by calling the DrawTextWin32 function, which accepts a handle to a device context as a parameter. It is possible to retrieve a GDI-compatible device context for a surface by calling the IDirectDrawSurface5::GetDCmethod for that surface. The following example shows how this might be done:

// For this example the lpDDS4 variable is a
valid pointer // to an IDirectDrawSurface5 interface. HDC hdc;
HRESULT HR; hr = lpDDS4->GetDC(&hdc); if(FAILED(hr)) return
hr; // Call DrawText, or some other GDI // function here.

Note that the code calls the IDirectDrawSurface5::ReleaseDCmethod when the surface's device context is no longer needed. This step is required, because the IDirectDrawSurface5::GetDCmethod uses an internal version of the IDirectDrawSurface5::Lockmethod to lock the surface. The surface remains locked until the IDirectDrawSurface5::ReleaseDCmethod is called.

 Last updated on Tuesday, May 18, 2004

© 2004 Microsoft Corporation. All rights reserved.