Share via


Función SetBkMode (wingdi.h)

La función SetBkMode establece el modo de combinación de fondo del contexto de dispositivo especificado. El modo de combinación de fondo se usa con texto, pinceles sombreados y estilos de lápiz que no son líneas sólidas.

Sintaxis

int SetBkMode(
  [in] HDC hdc,
  [in] int mode
);

Parámetros

[in] hdc

Identificador del contexto del dispositivo.

[in] mode

Modo de fondo. Este parámetro puede ser uno de los valores siguientes.

Valor Significado
OPACO
: el fondo se rellena con el color de fondo actual antes de que se dibuje el texto, el pincel sombreado o el lápiz.
TRANSPARENTE
El fondo permanece intacto.

Valor devuelto

Si la función se ejecuta correctamente, el valor devuelto especifica el modo de fondo anterior.

Si la función no se realiza correctamente, el valor devuelto es cero.

Comentarios

La función SetBkMode afecta a los estilos de línea para las líneas dibujadas mediante un lápiz creado por la función CreatePen . SetBkMode no afecta a las líneas dibujadas mediante un lápiz creado por la función ExtCreatePen .

Ejemplos

Para ver cómo hacer que el fondo de un pincel de sombreado sea transparente o opaco, consulte el ejemplo que se muestra en el tema CreateHatchBrush .

En el ejemplo siguiente se dibuja una cadena 36 veces, girando 10 grados en sentido contrario a las agujas del reloj cada vez. También establece el modo de fondo en transparente para que el texto sea visible.

#include "strsafe.h"
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    
    case WM_PAINT:
        {
        hdc = BeginPaint(hWnd, &ps);
        RECT rc; 
        int angle; 
        HGDIOBJ hfnt, hfntPrev; 
        WCHAR lpszRotate[22] = TEXT("String to be rotated.");
        HRESULT hr; 
        size_t pcch = 22;
 
// Allocate memory for a LOGFONT structure. 
 
PLOGFONT plf = (PLOGFONT) LocalAlloc(LPTR, sizeof(LOGFONT)); 
 
 
// Specify a font typeface name and weight. 
 
hr = StringCchCopy(plf->lfFaceName, 6, TEXT("Arial"));
if (FAILED(hr))
{
// TODO: write error handler
}

plf->lfWeight = FW_NORMAL; 
 
// Retrieve the client-rectangle dimensions. 
 
GetClientRect(hWnd, &rc); 
 
// Set the background mode to transparent for the 
// text-output operation. 
 
SetBkMode(hdc, TRANSPARENT); 
 
// Draw the string 36 times, rotating 10 degrees 
// counter-clockwise each time. 
 
for (angle = 0; angle < 3600; angle += 100) 
{ 
    plf->lfEscapement = angle; 
    hfnt = CreateFontIndirect(plf); 
    hfntPrev = SelectObject(hdc, hfnt);
    
    //
    // The StringCchLength call is fitted to the lpszRotate string
    //
    hr = StringCchLength(lpszRotate, 22, &pcch);
    if (FAILED(hr))
    {
    // TODO: write error handler
    } 
    TextOut(hdc, rc.right / 2, rc.bottom / 2, 
        lpszRotate, pcch); 
    SelectObject(hdc, hfntPrev); 
    DeleteObject(hfnt); 
} 
 
// Reset the background mode to its default. 
 
SetBkMode(hdc, OPAQUE); 
 
// Free the memory allocated for the LOGFONT structure. 
 
LocalFree((LOCALHANDLE) plf); 
        EndPaint(hWnd, &ps);
        break;
        }
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

Requisitos

   
Cliente mínimo compatible Windows 2000 Professional [solo aplicaciones de escritorio]
Servidor mínimo compatible Windows 2000 Server [solo aplicaciones de escritorio]
Plataforma de destino Windows
Encabezado wingdi.h (incluye Windows.h)
Library Gdi32.lib
Archivo DLL Gdi32.dll

Consulte también

CreatePen

ExtCreatePen

GetBkMode

Funciones de dibujo y pintura

Información general sobre la pintura y el dibujo