SetBkMode 함수(wingdi.h)

SetBkMode 함수는 지정된 디바이스 컨텍스트의 배경 혼합 모드를 설정합니다. 배경 혼합 모드는 실선이 아닌 텍스트, 부화 브러시 및 펜 스타일과 함께 사용됩니다.

구문

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

매개 변수

[in] hdc

디바이스 컨텍스트에 대한 핸들입니다.

[in] mode

백그라운드 모드입니다. 이 매개 변수는 다음 값 중 하나일 수 있습니다.

의미
불투명
배경은 텍스트, 부화 브러시 또는 펜을 그리기 전에 현재 배경색으로 채워집니다.
투명
배경은 그대로 유지됩니다.

반환 값

함수가 성공하면 반환 값은 이전 백그라운드 모드를 지정합니다.

함수가 실패하면 반환 값은 0입니다.

설명

SetBkMode 함수는 CreatePen 함수에서 만든 펜을 사용하여 그린 선의 선 스타일에 영향을 줍니다. SetBkModeExtCreatePen 함수에서 만든 펜을 사용하여 그린 선에 영향을 주지 않습니다.

예제

해치 브러시의 배경을 투명하거나 불투명하게 만드는 방법을 보려면 CreateHatchBrush 항목에 표시된 예제를 참조하세요.

다음 예제에서는 매번 시계 반대 방향으로 10도 회전하여 문자열을 36번 그립니다. 또한 배경 모드를 투명하게 설정하여 텍스트를 표시합니다.

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

요구 사항

   
지원되는 최소 클라이언트 Windows 2000 Professional[데스크톱 앱만]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 wingdi.h(Windows.h 포함)
라이브러리 Gdi32.lib
DLL Gdi32.dll

추가 정보

CreatePen

ExtCreatePen

GetBkMode

그리기 및 그리기 함수

그리기 및 그리기 개요