Freigeben über


Retrieving the Device Context for a Surface (Windows CE 5.0)

Send Feedback

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 DrawText Win32 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::GetDC method 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.
 
    lpDDS4->ReleaseDC(hdc);

Note that the code calls the IDirectDrawSurface5::ReleaseDC method when the surface's device context is no longer needed.

This step is required, because the IDirectDrawSurface5::GetDC method uses an internal version of the IDirectDrawSurface5::Lock method to lock the surface. The surface remains locked until the IDirectDrawSurface5::ReleaseDC method is called.

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.