Share via


Funzione SetBkMode (wingdi.h)

La funzione SetBkMode imposta la modalità di combinazione in background del contesto di dispositivo specificato. La modalità di combinazione di sfondo viene usata con testo, pennelli tratteggi e stili di penna che non sono linee solide.

Sintassi

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

Parametri

[in] hdc

Handle per il contesto del dispositivo.

[in] mode

Modalità in background. Questo parametro può avere uno dei valori seguenti.

Valore Significato
OPACO
Lo sfondo viene riempito con il colore di sfondo corrente prima che venga disegnato il testo, il pennello tratteggiato o la penna.
TRASPARENTE
Lo sfondo rimane invariato.

Valore restituito

Se la funzione ha esito positivo, il valore restituito specifica la modalità in background precedente.

Se la funzione ha esito negativo, il valore restituito è zero.

Commenti

La funzione SetBkMode influisce sugli stili di linea per le linee disegnate usando una penna creata dalla funzione CreatePen . SetBkMode non influisce sulle linee disegnate utilizzando una penna creata dalla funzione ExtCreatePen .

Esempio

Per informazioni su come rendere trasparente o opaco lo sfondo di un pennello tratteggio, fare riferimento all'esempio illustrato nell'argomento CreateHatchBrush .

L'esempio successivo disegna una stringa 36 volte, ruotandola ogni volta a 10 gradi in senso antiorario. Imposta anche la modalità di sfondo su trasparente per rendere visibile il testo.

#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;
}

Requisiti

   
Client minimo supportato Windows 2000 Professional [solo app desktop]
Server minimo supportato Windows 2000 Server [solo app desktop]
Piattaforma di destinazione Windows
Intestazione wingdi.h (include Windows.h)
Libreria Gdi32.lib
DLL Gdi32.dll

Vedi anche

CreatePen

ExtCreatePen

GetBkMode

Funzioni di disegno e disegno

Panoramica di disegno e disegno